2011-08-28 05:13:24 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
#include <boost/assign/list_inserter.hpp>
|
|
|
|
|
|
|
|
#include <Poco/SharedPtr.h>
|
|
|
|
#include <Poco/Stopwatch.h>
|
|
|
|
#include <Poco/NumberParser.h>
|
|
|
|
|
2011-10-31 06:37:12 +00:00
|
|
|
#include <DB/IO/ReadBufferFromIStream.h>
|
2011-08-28 05:13:24 +00:00
|
|
|
#include <DB/IO/WriteBufferFromOStream.h>
|
|
|
|
|
|
|
|
#include <DB/Storages/StorageLog.h>
|
2011-08-28 08:02:11 +00:00
|
|
|
#include <DB/Storages/StorageSystemNumbers.h>
|
|
|
|
#include <DB/Storages/StorageSystemOne.h>
|
2011-08-28 05:13:24 +00:00
|
|
|
|
|
|
|
#include <DB/DataStreams/TabSeparatedRowOutputStream.h>
|
|
|
|
#include <DB/DataStreams/copyData.h>
|
|
|
|
|
|
|
|
#include <DB/DataTypes/DataTypesNumberFixed.h>
|
2011-10-31 06:37:12 +00:00
|
|
|
#include <DB/DataTypes/DataTypeFactory.h>
|
2011-08-28 05:13:24 +00:00
|
|
|
|
2011-08-28 08:02:11 +00:00
|
|
|
#include <DB/Functions/FunctionsArithmetic.h>
|
2011-08-28 05:13:24 +00:00
|
|
|
#include <DB/Functions/FunctionsComparison.h>
|
2011-08-28 08:02:11 +00:00
|
|
|
#include <DB/Functions/FunctionsLogical.h>
|
2011-10-03 04:06:34 +00:00
|
|
|
#include <DB/Functions/FunctionsString.h>
|
2011-10-15 23:40:56 +00:00
|
|
|
#include <DB/Functions/FunctionsConversion.h>
|
2011-10-16 04:17:41 +00:00
|
|
|
#include <DB/Functions/FunctionsDateTime.h>
|
2011-10-16 07:11:36 +00:00
|
|
|
#include <DB/Functions/FunctionsStringSearch.h>
|
2011-08-28 05:13:24 +00:00
|
|
|
|
2011-10-31 06:37:12 +00:00
|
|
|
#include <DB/Interpreters/loadMetadata.h>
|
|
|
|
#include <DB/Interpreters/executeQuery.h>
|
2011-08-28 05:13:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
using Poco::SharedPtr;
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2011-10-15 23:40:56 +00:00
|
|
|
/// Заранее инициализируем DateLUT, чтобы первая инициализация потом не влияла на измеряемую скорость выполнения.
|
|
|
|
Yandex::DateLUTSingleton::instance();
|
|
|
|
|
2011-08-28 05:13:24 +00:00
|
|
|
typedef std::pair<std::string, SharedPtr<DB::IDataType> > NameAndTypePair;
|
|
|
|
typedef std::list<NameAndTypePair> NamesAndTypesList;
|
|
|
|
|
|
|
|
NamesAndTypesList names_and_types_list;
|
|
|
|
|
|
|
|
boost::assign::push_back(names_and_types_list)
|
|
|
|
("WatchID", new DB::DataTypeUInt64)
|
|
|
|
("JavaEnable", new DB::DataTypeUInt8)
|
|
|
|
("Title", new DB::DataTypeString)
|
|
|
|
("GoodEvent", new DB::DataTypeUInt32)
|
|
|
|
("EventTime", new DB::DataTypeDateTime)
|
|
|
|
("CounterID", new DB::DataTypeUInt32)
|
|
|
|
("ClientIP", new DB::DataTypeUInt32)
|
|
|
|
("RegionID", new DB::DataTypeUInt32)
|
|
|
|
("UniqID", new DB::DataTypeUInt64)
|
|
|
|
("CounterClass", new DB::DataTypeUInt8)
|
|
|
|
("OS", new DB::DataTypeUInt8)
|
|
|
|
("UserAgent", new DB::DataTypeUInt8)
|
|
|
|
("URL", new DB::DataTypeString)
|
|
|
|
("Referer", new DB::DataTypeString)
|
|
|
|
("Refresh", new DB::DataTypeUInt8)
|
|
|
|
("ResolutionWidth", new DB::DataTypeUInt16)
|
|
|
|
("ResolutionHeight", new DB::DataTypeUInt16)
|
|
|
|
("ResolutionDepth", new DB::DataTypeUInt8)
|
|
|
|
("FlashMajor", new DB::DataTypeUInt8)
|
|
|
|
("FlashMinor", new DB::DataTypeUInt8)
|
|
|
|
("FlashMinor2", new DB::DataTypeString)
|
|
|
|
("NetMajor", new DB::DataTypeUInt8)
|
|
|
|
("NetMinor", new DB::DataTypeUInt8)
|
|
|
|
("UserAgentMajor", new DB::DataTypeUInt16)
|
|
|
|
("UserAgentMinor", new DB::DataTypeFixedString(2))
|
|
|
|
("CookieEnable", new DB::DataTypeUInt8)
|
|
|
|
("JavascriptEnable", new DB::DataTypeUInt8)
|
|
|
|
("IsMobile", new DB::DataTypeUInt8)
|
|
|
|
("MobilePhone", new DB::DataTypeUInt8)
|
|
|
|
("MobilePhoneModel", new DB::DataTypeString)
|
|
|
|
("Params", new DB::DataTypeString)
|
|
|
|
("IPNetworkID", new DB::DataTypeUInt32)
|
|
|
|
("TraficSourceID", new DB::DataTypeInt8)
|
|
|
|
("SearchEngineID", new DB::DataTypeUInt16)
|
|
|
|
("SearchPhrase", new DB::DataTypeString)
|
|
|
|
("AdvEngineID", new DB::DataTypeUInt8)
|
|
|
|
("IsArtifical", new DB::DataTypeUInt8)
|
|
|
|
("WindowClientWidth", new DB::DataTypeUInt16)
|
|
|
|
("WindowClientHeight", new DB::DataTypeUInt16)
|
|
|
|
("ClientTimeZone", new DB::DataTypeInt16)
|
|
|
|
("ClientEventTime", new DB::DataTypeDateTime)
|
|
|
|
("SilverlightVersion1", new DB::DataTypeUInt8)
|
|
|
|
("SilverlightVersion2", new DB::DataTypeUInt8)
|
|
|
|
("SilverlightVersion3", new DB::DataTypeUInt32)
|
|
|
|
("SilverlightVersion4", new DB::DataTypeUInt16)
|
|
|
|
("PageCharset", new DB::DataTypeString)
|
|
|
|
("CodeVersion", new DB::DataTypeUInt32)
|
|
|
|
("IsLink", new DB::DataTypeUInt8)
|
|
|
|
("IsDownload", new DB::DataTypeUInt8)
|
|
|
|
("IsNotBounce", new DB::DataTypeUInt8)
|
|
|
|
("FUniqID", new DB::DataTypeUInt64)
|
|
|
|
("OriginalURL", new DB::DataTypeString)
|
|
|
|
("HID", new DB::DataTypeUInt32)
|
|
|
|
("IsOldCounter", new DB::DataTypeUInt8)
|
|
|
|
("IsEvent", new DB::DataTypeUInt8)
|
|
|
|
("IsParameter", new DB::DataTypeUInt8)
|
|
|
|
("DontCountHits", new DB::DataTypeUInt8)
|
|
|
|
("WithHash", new DB::DataTypeUInt8)
|
|
|
|
;
|
|
|
|
|
|
|
|
SharedPtr<DB::NamesAndTypes> names_and_types_map = new DB::NamesAndTypes;
|
|
|
|
|
|
|
|
for (NamesAndTypesList::const_iterator it = names_and_types_list.begin(); it != names_and_types_list.end(); ++it)
|
|
|
|
{
|
|
|
|
names_and_types_map->insert(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
DB::Context context;
|
|
|
|
|
2011-10-17 02:43:02 +00:00
|
|
|
boost::assign::insert(*context.functions)
|
|
|
|
("plus", new DB::FunctionPlus)
|
|
|
|
("minus", new DB::FunctionMinus)
|
|
|
|
("multiply", new DB::FunctionMultiply)
|
|
|
|
("divide", new DB::FunctionDivideFloating)
|
|
|
|
("intDiv", new DB::FunctionDivideIntegral)
|
|
|
|
("modulo", new DB::FunctionModulo)
|
|
|
|
("negate", new DB::FunctionNegate)
|
|
|
|
|
|
|
|
("equals", new DB::FunctionEquals)
|
|
|
|
("notEquals", new DB::FunctionNotEquals)
|
|
|
|
("less", new DB::FunctionLess)
|
|
|
|
("greater", new DB::FunctionGreater)
|
|
|
|
("lessOrEquals", new DB::FunctionLessOrEquals)
|
|
|
|
("greaterOrEquals", new DB::FunctionGreaterOrEquals)
|
|
|
|
|
|
|
|
("and", new DB::FunctionAnd)
|
|
|
|
("or", new DB::FunctionOr)
|
|
|
|
("xor", new DB::FunctionXor)
|
|
|
|
("not", new DB::FunctionNot)
|
|
|
|
|
|
|
|
("length", new DB::FunctionLength)
|
|
|
|
("lengthUTF8", new DB::FunctionLengthUTF8)
|
|
|
|
("lower", new DB::FunctionLower)
|
|
|
|
("upper", new DB::FunctionUpper)
|
|
|
|
("lowerUTF8", new DB::FunctionLowerUTF8)
|
|
|
|
("upperUTF8", new DB::FunctionUpperUTF8)
|
|
|
|
("reverse", new DB::FunctionReverse)
|
|
|
|
("reverseUTF8", new DB::FunctionReverseUTF8)
|
|
|
|
("concat", new DB::FunctionConcat)
|
|
|
|
("substring", new DB::FunctionSubstring)
|
|
|
|
("substringUTF8", new DB::FunctionSubstringUTF8)
|
|
|
|
|
|
|
|
("toUInt8", new DB::FunctionToUInt8)
|
|
|
|
("toUInt16", new DB::FunctionToUInt16)
|
|
|
|
("toUInt32", new DB::FunctionToUInt32)
|
|
|
|
("toUInt64", new DB::FunctionToUInt64)
|
|
|
|
("toInt8", new DB::FunctionToInt8)
|
|
|
|
("toInt16", new DB::FunctionToInt16)
|
|
|
|
("toInt32", new DB::FunctionToInt32)
|
|
|
|
("toInt64", new DB::FunctionToInt64)
|
|
|
|
("toFloat32", new DB::FunctionToFloat32)
|
|
|
|
("toFloat64", new DB::FunctionToFloat64)
|
|
|
|
("toVarUInt", new DB::FunctionToVarUInt)
|
|
|
|
("toVarInt", new DB::FunctionToVarInt)
|
|
|
|
("toDate", new DB::FunctionToDate)
|
|
|
|
("toDateTime", new DB::FunctionToDateTime)
|
|
|
|
("toString", new DB::FunctionToString)
|
|
|
|
|
|
|
|
("toYear", new DB::FunctionToYear)
|
|
|
|
("toMonth", new DB::FunctionToMonth)
|
|
|
|
("toDayOfMonth", new DB::FunctionToDayOfMonth)
|
|
|
|
("toDayOfWeek", new DB::FunctionToDayOfWeek)
|
|
|
|
("toHour", new DB::FunctionToHour)
|
|
|
|
("toMinute", new DB::FunctionToMinute)
|
|
|
|
("toSecond", new DB::FunctionToSecond)
|
|
|
|
("toMonday", new DB::FunctionToMonday)
|
|
|
|
("toStartOfMonth", new DB::FunctionToStartOfMonth)
|
|
|
|
("toTime", new DB::FunctionToTime)
|
|
|
|
|
|
|
|
("position", new DB::FunctionPosition)
|
2011-10-17 08:28:39 +00:00
|
|
|
("positionUTF8", new DB::FunctionPositionUTF8)
|
|
|
|
("match", new DB::FunctionMatch)
|
|
|
|
("like", new DB::FunctionLike)
|
|
|
|
("notLike", new DB::FunctionNotLike)
|
2011-10-17 02:43:02 +00:00
|
|
|
;
|
2011-10-16 07:11:36 +00:00
|
|
|
|
2011-10-31 06:37:12 +00:00
|
|
|
context.path = "./";
|
|
|
|
|
2011-09-25 03:37:09 +00:00
|
|
|
context.aggregate_function_factory = new DB::AggregateFunctionFactory;
|
2011-10-31 06:37:12 +00:00
|
|
|
context.data_type_factory = new DB::DataTypeFactory;
|
|
|
|
|
|
|
|
DB::loadMetadata(context);
|
2011-09-25 03:37:09 +00:00
|
|
|
|
2011-10-31 06:37:12 +00:00
|
|
|
(*context.databases)["default"]["hits"] = new DB::StorageLog("./data/default/", "hits", names_and_types_map, ".bin");
|
|
|
|
(*context.databases)["default"]["hits2"] = new DB::StorageLog("./data/default/", "hits2", names_and_types_map, ".bin");
|
|
|
|
(*context.databases)["default"]["hits3"] = new DB::StorageLog("./data/default/", "hits3", names_and_types_map, ".bin");
|
2011-08-28 08:02:11 +00:00
|
|
|
(*context.databases)["system"]["one"] = new DB::StorageSystemOne("one");
|
|
|
|
(*context.databases)["system"]["numbers"] = new DB::StorageSystemNumbers("numbers");
|
2011-08-28 05:13:24 +00:00
|
|
|
context.current_database = "default";
|
|
|
|
|
2011-10-31 06:37:12 +00:00
|
|
|
DB::ReadBufferFromIStream in(std::cin);
|
|
|
|
DB::WriteBufferFromOStream out(std::cout);
|
|
|
|
DB::BlockInputStreamPtr query_plan;
|
2011-08-28 08:02:11 +00:00
|
|
|
|
2011-10-31 06:37:12 +00:00
|
|
|
DB::executeQuery(in, out, context, query_plan);
|
|
|
|
|
|
|
|
if (query_plan)
|
|
|
|
{
|
|
|
|
std::cerr << std::endl;
|
|
|
|
query_plan->dumpTree(std::cerr);
|
|
|
|
}
|
2011-08-28 05:13:24 +00:00
|
|
|
}
|
|
|
|
catch (const DB::Exception & e)
|
|
|
|
{
|
|
|
|
std::cerr << e.what() << ", " << e.message() << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|