| 1 | #include <iostream> |
| 2 | #include <iomanip> |
| 3 | |
| 4 | #include <Parsers/ParserCreateQuery.h> |
| 5 | #include <Parsers/formatAST.h> |
| 6 | #include <Parsers/parseQuery.h> |
| 7 | |
| 8 | #include <Databases/DatabaseOrdinary.h> |
| 9 | |
| 10 | #include <Interpreters/Context.h> |
| 11 | #include <Interpreters/InterpreterCreateQuery.h> |
| 12 | |
| 13 | |
| 14 | using namespace DB; |
| 15 | |
| 16 | int main(int, char **) |
| 17 | try |
| 18 | { |
| 19 | std::string input = "CREATE TABLE IF NOT EXISTS hits (\n" |
| 20 | "WatchID UInt64,\n" |
| 21 | "JavaEnable UInt8,\n" |
| 22 | "Title String,\n" |
| 23 | "EventTime DateTime,\n" |
| 24 | "CounterID UInt32,\n" |
| 25 | "ClientIP UInt32,\n" |
| 26 | "RegionID UInt32,\n" |
| 27 | "UniqID UInt64,\n" |
| 28 | "CounterClass UInt8,\n" |
| 29 | "OS UInt8,\n" |
| 30 | "UserAgent UInt8,\n" |
| 31 | "URL String,\n" |
| 32 | "Referer String,\n" |
| 33 | "ResolutionWidth UInt16,\n" |
| 34 | "ResolutionHeight UInt16,\n" |
| 35 | "ResolutionDepth UInt8,\n" |
| 36 | "FlashMajor UInt8,\n" |
| 37 | "FlashMinor UInt8,\n" |
| 38 | "FlashMinor2 String,\n" |
| 39 | "NetMajor UInt8,\n" |
| 40 | "NetMinor UInt8,\n" |
| 41 | "UserAgentMajor UInt16,\n" |
| 42 | "UserAgentMinor FixedString(2),\n" |
| 43 | "CookieEnable UInt8,\n" |
| 44 | "JavascriptEnable UInt8,\n" |
| 45 | "IsMobile UInt8,\n" |
| 46 | "MobilePhone UInt8,\n" |
| 47 | "MobilePhoneModel String,\n" |
| 48 | "Params String,\n" |
| 49 | "IPNetworkID UInt32,\n" |
| 50 | "TraficSourceID Int8,\n" |
| 51 | "SearchEngineID UInt16,\n" |
| 52 | "SearchPhrase String,\n" |
| 53 | "AdvEngineID UInt8,\n" |
| 54 | "IsArtifical UInt8,\n" |
| 55 | "WindowClientWidth UInt16,\n" |
| 56 | "WindowClientHeight UInt16,\n" |
| 57 | "ClientTimeZone Int16,\n" |
| 58 | "ClientEventTime DateTime,\n" |
| 59 | "SilverlightVersion1 UInt8,\n" |
| 60 | "SilverlightVersion2 UInt8,\n" |
| 61 | "SilverlightVersion3 UInt32,\n" |
| 62 | "SilverlightVersion4 UInt16,\n" |
| 63 | "PageCharset String,\n" |
| 64 | "CodeVersion UInt32,\n" |
| 65 | "IsLink UInt8,\n" |
| 66 | "IsDownload UInt8,\n" |
| 67 | "IsNotBounce UInt8,\n" |
| 68 | "FUniqID UInt64,\n" |
| 69 | "OriginalURL String,\n" |
| 70 | "HID UInt32,\n" |
| 71 | "IsOldCounter UInt8,\n" |
| 72 | "IsEvent UInt8,\n" |
| 73 | "IsParameter UInt8,\n" |
| 74 | "DontCountHits UInt8,\n" |
| 75 | "WithHash UInt8\n" |
| 76 | ") ENGINE = Log" ; |
| 77 | |
| 78 | ParserCreateQuery parser; |
| 79 | ASTPtr ast = parseQuery(parser, input.data(), input.data() + input.size(), "" , 0); |
| 80 | |
| 81 | Context context = Context::createGlobal(); |
| 82 | context.makeGlobalContext(); |
| 83 | |
| 84 | context.setPath("./" ); |
| 85 | auto database = std::make_shared<DatabaseOrdinary>("test" , "./metadata/test/" , context); |
| 86 | context.addDatabase("test" , database); |
| 87 | database->loadStoredObjects(context, false); |
| 88 | context.setCurrentDatabase("test" ); |
| 89 | |
| 90 | InterpreterCreateQuery interpreter(ast, context); |
| 91 | interpreter.execute(); |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | catch (const Exception & e) |
| 96 | { |
| 97 | std::cerr << e.what() << ", " << e.displayText() << std::endl |
| 98 | << std::endl |
| 99 | << "Stack trace:" << std::endl |
| 100 | << e.getStackTrace().toString(); |
| 101 | return 1; |
| 102 | } |
| 103 | |