2011-08-18 20:33:20 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ParserCreateQuery.h>
|
|
|
|
#include <Parsers/formatAST.h>
|
|
|
|
#include <Parsers/parseQuery.h>
|
2011-08-18 20:33:20 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Databases/DatabaseOrdinary.h>
|
2016-04-10 21:50:36 +00:00
|
|
|
|
2017-05-23 18:58:38 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/InterpreterCreateQuery.h>
|
2011-08-18 20:33:20 +00:00
|
|
|
|
|
|
|
|
2017-05-23 18:58:38 +00:00
|
|
|
using namespace DB;
|
|
|
|
|
2017-12-02 02:47:12 +00:00
|
|
|
int main(int, char **)
|
2017-05-23 18:58:38 +00:00
|
|
|
try
|
2011-08-18 20:33:20 +00:00
|
|
|
{
|
2017-05-23 18:58:38 +00:00
|
|
|
std::string input = "CREATE TABLE IF NOT EXISTS hits (\n"
|
|
|
|
"WatchID UInt64,\n"
|
|
|
|
"JavaEnable UInt8,\n"
|
|
|
|
"Title String,\n"
|
|
|
|
"EventTime DateTime,\n"
|
|
|
|
"CounterID UInt32,\n"
|
|
|
|
"ClientIP UInt32,\n"
|
|
|
|
"RegionID UInt32,\n"
|
|
|
|
"UniqID UInt64,\n"
|
|
|
|
"CounterClass UInt8,\n"
|
|
|
|
"OS UInt8,\n"
|
|
|
|
"UserAgent UInt8,\n"
|
|
|
|
"URL String,\n"
|
|
|
|
"Referer String,\n"
|
|
|
|
"ResolutionWidth UInt16,\n"
|
|
|
|
"ResolutionHeight UInt16,\n"
|
|
|
|
"ResolutionDepth UInt8,\n"
|
|
|
|
"FlashMajor UInt8,\n"
|
|
|
|
"FlashMinor UInt8,\n"
|
|
|
|
"FlashMinor2 String,\n"
|
|
|
|
"NetMajor UInt8,\n"
|
|
|
|
"NetMinor UInt8,\n"
|
|
|
|
"UserAgentMajor UInt16,\n"
|
|
|
|
"UserAgentMinor FixedString(2),\n"
|
|
|
|
"CookieEnable UInt8,\n"
|
|
|
|
"JavascriptEnable UInt8,\n"
|
|
|
|
"IsMobile UInt8,\n"
|
|
|
|
"MobilePhone UInt8,\n"
|
|
|
|
"MobilePhoneModel String,\n"
|
|
|
|
"Params String,\n"
|
|
|
|
"IPNetworkID UInt32,\n"
|
|
|
|
"TraficSourceID Int8,\n"
|
|
|
|
"SearchEngineID UInt16,\n"
|
|
|
|
"SearchPhrase String,\n"
|
|
|
|
"AdvEngineID UInt8,\n"
|
|
|
|
"IsArtifical UInt8,\n"
|
|
|
|
"WindowClientWidth UInt16,\n"
|
|
|
|
"WindowClientHeight UInt16,\n"
|
|
|
|
"ClientTimeZone Int16,\n"
|
|
|
|
"ClientEventTime DateTime,\n"
|
|
|
|
"SilverlightVersion1 UInt8,\n"
|
|
|
|
"SilverlightVersion2 UInt8,\n"
|
|
|
|
"SilverlightVersion3 UInt32,\n"
|
|
|
|
"SilverlightVersion4 UInt16,\n"
|
|
|
|
"PageCharset String,\n"
|
|
|
|
"CodeVersion UInt32,\n"
|
|
|
|
"IsLink UInt8,\n"
|
|
|
|
"IsDownload UInt8,\n"
|
|
|
|
"IsNotBounce UInt8,\n"
|
|
|
|
"FUniqID UInt64,\n"
|
|
|
|
"OriginalURL String,\n"
|
|
|
|
"HID UInt32,\n"
|
|
|
|
"IsOldCounter UInt8,\n"
|
|
|
|
"IsEvent UInt8,\n"
|
|
|
|
"IsParameter UInt8,\n"
|
|
|
|
"DontCountHits UInt8,\n"
|
|
|
|
"WithHash UInt8\n"
|
|
|
|
") ENGINE = Log";
|
2011-08-18 20:33:20 +00:00
|
|
|
|
2017-05-23 18:58:38 +00:00
|
|
|
ParserCreateQuery parser;
|
2018-04-16 15:11:13 +00:00
|
|
|
ASTPtr ast = parseQuery(parser, input.data(), input.data() + input.size(), "", 0);
|
2011-08-18 20:33:20 +00:00
|
|
|
|
2017-06-19 20:31:23 +00:00
|
|
|
Context context = Context::createGlobal();
|
2019-07-08 02:14:32 +00:00
|
|
|
context.makeGlobalContext();
|
2011-08-18 20:33:20 +00:00
|
|
|
|
2017-05-23 18:58:38 +00:00
|
|
|
context.setPath("./");
|
2018-02-02 17:29:45 +00:00
|
|
|
auto database = std::make_shared<DatabaseOrdinary>("test", "./metadata/test/", context);
|
2020-02-10 13:10:17 +00:00
|
|
|
DatabaseCatalog::instance().attachDatabase("test", database);
|
2019-10-10 20:47:47 +00:00
|
|
|
database->loadStoredObjects(context, false);
|
2017-05-23 18:58:38 +00:00
|
|
|
context.setCurrentDatabase("test");
|
2011-08-18 20:33:20 +00:00
|
|
|
|
2017-05-23 18:58:38 +00:00
|
|
|
InterpreterCreateQuery interpreter(ast, context);
|
|
|
|
interpreter.execute();
|
2011-08-18 20:33:20 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return 0;
|
2011-08-18 20:33:20 +00:00
|
|
|
}
|
2017-05-23 18:58:38 +00:00
|
|
|
catch (const Exception & e)
|
|
|
|
{
|
|
|
|
std::cerr << e.what() << ", " << e.displayText() << std::endl
|
|
|
|
<< std::endl
|
|
|
|
<< "Stack trace:" << std::endl
|
2020-01-02 06:56:53 +00:00
|
|
|
<< e.getStackTraceString();
|
2017-05-23 18:58:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|