2011-08-18 20:33:20 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
#include <DB/Parsers/ParserCreateQuery.h>
|
|
|
|
#include <DB/Parsers/formatAST.h>
|
2015-04-11 03:30:54 +00:00
|
|
|
#include <DB/Parsers/parseQuery.h>
|
2011-08-18 20:33:20 +00:00
|
|
|
|
2016-04-10 21:50:36 +00:00
|
|
|
#include <DB/Databases/DatabaseOrdinary.h>
|
|
|
|
|
2011-08-18 20:33:20 +00:00
|
|
|
#include <DB/Interpreters/InterpreterCreateQuery.h>
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
2014-06-12 00:48:56 +00:00
|
|
|
using namespace DB;
|
2014-06-30 23:46:22 +00:00
|
|
|
|
2011-08-18 20:33:20 +00:00
|
|
|
try
|
|
|
|
{
|
2011-08-19 18:31:14 +00:00
|
|
|
std::string input = "CREATE TABLE IF NOT EXISTS hits (\n"
|
2011-08-18 20:33:20 +00:00
|
|
|
"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";
|
|
|
|
|
2015-04-11 03:30:54 +00:00
|
|
|
ParserCreateQuery parser;
|
|
|
|
ASTPtr ast = parseQuery(parser, input.data(), input.data() + input.size(), "");
|
2011-08-18 20:33:20 +00:00
|
|
|
|
2014-06-12 00:48:56 +00:00
|
|
|
Context context;
|
2011-08-18 20:33:20 +00:00
|
|
|
|
2012-08-02 17:33:31 +00:00
|
|
|
context.setPath("./");
|
2016-06-10 20:46:58 +00:00
|
|
|
auto database = std::make_shared<DatabaseOrdinary>("test", "./metadata/test/");
|
|
|
|
context.addDatabase("test", database);
|
2016-08-09 21:48:05 +00:00
|
|
|
database->loadTables(context, nullptr, false);
|
2012-08-02 17:33:31 +00:00
|
|
|
context.setCurrentDatabase("test");
|
2011-08-18 20:33:20 +00:00
|
|
|
|
2014-06-12 00:48:56 +00:00
|
|
|
InterpreterCreateQuery interpreter(ast, context);
|
2011-11-01 15:16:04 +00:00
|
|
|
interpreter.execute();
|
2011-08-18 20:33:20 +00:00
|
|
|
}
|
2014-06-12 00:48:56 +00:00
|
|
|
catch (const Exception & e)
|
2011-08-18 20:33:20 +00:00
|
|
|
{
|
2012-11-08 18:30:49 +00:00
|
|
|
std::cerr << e.displayText() << std::endl;
|
2011-08-18 20:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|