2010-05-24 17:55:57 +00:00
|
|
|
#include <map>
|
|
|
|
#include <list>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <boost/assign/list_inserter.hpp>
|
|
|
|
|
|
|
|
#include <Poco/SharedPtr.h>
|
|
|
|
|
2010-06-04 18:25:25 +00:00
|
|
|
#include <DB/IO/ReadBufferFromIStream.h>
|
|
|
|
#include <DB/IO/WriteBufferFromOStream.h>
|
|
|
|
|
2010-05-24 17:55:57 +00:00
|
|
|
#include <DB/DataTypes/DataTypesNumberFixed.h>
|
|
|
|
#include <DB/DataTypes/DataTypeString.h>
|
2011-08-07 02:08:22 +00:00
|
|
|
#include <DB/DataTypes/DataTypeFixedString.h>
|
|
|
|
#include <DB/DataTypes/DataTypeDateTime.h>
|
2010-05-24 17:55:57 +00:00
|
|
|
|
|
|
|
#include <DB/DataStreams/TabSeparatedRowInputStream.h>
|
|
|
|
#include <DB/DataStreams/TabSeparatedRowOutputStream.h>
|
|
|
|
#include <DB/DataStreams/copyData.h>
|
|
|
|
|
|
|
|
#include <DB/Storages/StorageLog.h>
|
|
|
|
|
|
|
|
|
|
|
|
using Poco::SharedPtr;
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2011-11-01 17:12:11 +00:00
|
|
|
DB::NamesAndTypesListPtr names_and_types_list = new DB::NamesAndTypesList;
|
2010-05-24 17:55:57 +00:00
|
|
|
|
2011-11-01 17:12:11 +00:00
|
|
|
boost::assign::push_back(*names_and_types_list)
|
2010-05-24 17:55:57 +00:00
|
|
|
("WatchID", new DB::DataTypeUInt64)
|
|
|
|
("JavaEnable", new DB::DataTypeUInt8)
|
|
|
|
("Title", new DB::DataTypeString)
|
|
|
|
("GoodEvent", new DB::DataTypeUInt32)
|
2011-08-07 02:08:22 +00:00
|
|
|
("EventTime", new DB::DataTypeDateTime)
|
2010-05-24 17:55:57 +00:00
|
|
|
("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)
|
2011-08-07 02:08:22 +00:00
|
|
|
("UserAgentMinor", new DB::DataTypeFixedString(2))
|
2010-05-24 17:55:57 +00:00
|
|
|
("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)
|
2011-08-07 02:08:22 +00:00
|
|
|
("ClientEventTime", new DB::DataTypeDateTime)
|
2010-05-24 17:55:57 +00:00
|
|
|
("SilverlightVersion1", new DB::DataTypeUInt8)
|
|
|
|
("SilverlightVersion2", new DB::DataTypeUInt8)
|
|
|
|
("SilverlightVersion3", new DB::DataTypeUInt32)
|
|
|
|
("SilverlightVersion4", new DB::DataTypeUInt16)
|
|
|
|
("PageCharset", new DB::DataTypeString)
|
2011-08-07 02:08:22 +00:00
|
|
|
("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)
|
2010-05-24 17:55:57 +00:00
|
|
|
;
|
|
|
|
|
2010-05-24 18:58:14 +00:00
|
|
|
SharedPtr<DB::DataTypes> data_types = new DB::DataTypes;
|
2011-08-09 15:57:33 +00:00
|
|
|
DB::Names column_names;
|
2010-05-24 17:55:57 +00:00
|
|
|
|
2011-11-01 17:12:11 +00:00
|
|
|
for (DB::NamesAndTypesList::const_iterator it = names_and_types_list->begin(); it != names_and_types_list->end(); ++it)
|
2010-05-24 17:55:57 +00:00
|
|
|
{
|
|
|
|
data_types->push_back(it->second);
|
|
|
|
column_names.push_back(it->first);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// создаём таблицу хит лога
|
|
|
|
|
2011-11-01 17:12:11 +00:00
|
|
|
DB::StorageLog table("./", "HitLog", names_and_types_list, ".bin");
|
2010-05-24 17:55:57 +00:00
|
|
|
|
|
|
|
/// создаём описание, как читать данные из tab separated дампа
|
|
|
|
|
|
|
|
DB::Block sample;
|
2011-11-01 17:12:11 +00:00
|
|
|
for (DB::NamesAndTypesList::const_iterator it = names_and_types_list->begin(); it != names_and_types_list->end(); ++it)
|
2010-05-24 17:55:57 +00:00
|
|
|
{
|
|
|
|
DB::ColumnWithNameAndType elem;
|
|
|
|
elem.name = it->first;
|
|
|
|
elem.type = it->second;
|
|
|
|
elem.column = elem.type->createColumn();
|
|
|
|
sample.insert(elem);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// читаем данные из tsv файла и одновременно пишем в таблицу
|
2010-05-24 18:58:14 +00:00
|
|
|
if (argc == 2 && 0 == strcmp(argv[1], "write"))
|
2010-05-24 17:55:57 +00:00
|
|
|
{
|
2010-06-04 18:25:25 +00:00
|
|
|
DB::ReadBufferFromIStream in_buf(std::cin);
|
|
|
|
|
|
|
|
DB::TabSeparatedRowInputStream in(in_buf, data_types);
|
2010-05-24 17:55:57 +00:00
|
|
|
SharedPtr<DB::IBlockOutputStream> out = table.write(0);
|
|
|
|
DB::copyData(in, *out, sample);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// читаем из неё
|
2010-05-24 18:58:14 +00:00
|
|
|
if (argc == 2 && 0 == strcmp(argv[1], "read"))
|
2010-05-24 17:55:57 +00:00
|
|
|
{
|
2010-06-07 17:50:50 +00:00
|
|
|
/*
|
2011-08-09 15:57:33 +00:00
|
|
|
DB::Names column_names;
|
2010-05-28 19:13:55 +00:00
|
|
|
boost::assign::push_back(column_names)
|
2010-06-07 17:50:50 +00:00
|
|
|
("UniqID");
|
2010-05-28 19:13:55 +00:00
|
|
|
|
|
|
|
SharedPtr<DB::DataTypes> data_types = new DB::DataTypes;
|
|
|
|
boost::assign::push_back(*data_types)
|
2010-06-07 17:50:50 +00:00
|
|
|
(new DB::DataTypeUInt64);
|
2010-05-28 19:13:55 +00:00
|
|
|
*/
|
2010-06-04 18:25:25 +00:00
|
|
|
DB::WriteBufferFromOStream out_buf(std::cout);
|
|
|
|
|
2010-05-24 17:55:57 +00:00
|
|
|
SharedPtr<DB::IBlockInputStream> in = table.read(column_names, 0);
|
2010-06-04 18:25:25 +00:00
|
|
|
DB::TabSeparatedRowOutputStream out(out_buf, data_types);
|
2010-05-24 17:55:57 +00:00
|
|
|
DB::copyData(*in, out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const DB::Exception & e)
|
|
|
|
{
|
|
|
|
std::cerr << e.what() << ", " << e.message() << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|