2010-03-18 19:32:14 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteBufferFromOStream.h>
|
|
|
|
#include <Storages/StorageLog.h>
|
|
|
|
#include <DataStreams/TabSeparatedRowOutputStream.h>
|
|
|
|
#include <DataStreams/LimitBlockInputStream.h>
|
|
|
|
#include <DataStreams/BlockOutputStreamFromRowOutputStream.h>
|
|
|
|
#include <DataStreams/copyData.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <Columns/ColumnsNumber.h>
|
|
|
|
#include <Interpreters/Context.h>
|
2017-07-15 03:48:36 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2010-03-18 19:32:14 +00:00
|
|
|
|
|
|
|
|
2017-12-02 02:47:12 +00:00
|
|
|
int main(int, char **)
|
2016-05-28 08:11:52 +00:00
|
|
|
try
|
2010-03-18 19:32:14 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
using namespace DB;
|
2010-03-18 19:32:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const size_t rows = 10000000;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// create table with a pair of columns
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-12-25 21:57:29 +00:00
|
|
|
NamesAndTypesList names_and_types;
|
2017-12-25 21:10:46 +00:00
|
|
|
names_and_types.emplace_back("a", std::make_shared<DataTypeUInt64>());
|
|
|
|
names_and_types.emplace_back("b", std::make_shared<DataTypeUInt8>());
|
2010-03-18 19:32:14 +00:00
|
|
|
|
2017-06-06 19:06:44 +00:00
|
|
|
StoragePtr table = StorageLog::create("./", "test", names_and_types,
|
2017-12-25 21:57:29 +00:00
|
|
|
NamesAndTypesList{}, NamesAndTypesList{}, ColumnDefaults{}, DEFAULT_MAX_COMPRESS_BLOCK_SIZE);
|
2017-06-06 17:06:14 +00:00
|
|
|
table->startup();
|
2010-03-18 19:32:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// write into it
|
|
|
|
{
|
|
|
|
Block block;
|
2010-03-18 19:32:14 +00:00
|
|
|
|
2017-12-16 06:19:21 +00:00
|
|
|
{
|
|
|
|
ColumnWithTypeAndName column;
|
|
|
|
column.name = "a";
|
|
|
|
column.type = table->getDataTypeByName("a");
|
|
|
|
auto col = column.type->createColumn();
|
|
|
|
ColumnUInt64::Container & vec = typeid_cast<ColumnUInt64 &>(*col).getData();
|
|
|
|
|
|
|
|
vec.resize(rows);
|
|
|
|
for (size_t i = 0; i < rows; ++i)
|
|
|
|
vec[i] = i;
|
|
|
|
|
|
|
|
column.column = std::move(col);
|
|
|
|
block.insert(column);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ColumnWithTypeAndName column;
|
|
|
|
column.name = "b";
|
|
|
|
column.type = table->getDataTypeByName("b");
|
|
|
|
auto col = column.type->createColumn();
|
|
|
|
ColumnUInt8::Container & vec = typeid_cast<ColumnUInt8 &>(*col).getData();
|
|
|
|
|
|
|
|
vec.resize(rows);
|
|
|
|
for (size_t i = 0; i < rows; ++i)
|
|
|
|
vec[i] = i * 2;
|
|
|
|
|
|
|
|
column.column = std::move(col);
|
|
|
|
block.insert(column);
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockOutputStreamPtr out = table->write({}, {});
|
|
|
|
out->write(block);
|
|
|
|
}
|
2010-03-18 19:32:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// read from it
|
|
|
|
{
|
|
|
|
Names column_names;
|
|
|
|
column_names.push_back("a");
|
|
|
|
column_names.push_back("b");
|
2012-05-22 18:32:45 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
QueryProcessingStage::Enum stage;
|
2010-03-18 19:32:14 +00:00
|
|
|
|
2017-07-15 03:48:36 +00:00
|
|
|
BlockInputStreamPtr in = table->read(column_names, {}, Context::createGlobal(), stage, 8192, 1)[0];
|
2010-06-04 18:25:25 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Block sample;
|
|
|
|
{
|
|
|
|
ColumnWithTypeAndName col;
|
|
|
|
col.type = std::make_shared<DataTypeUInt64>();
|
|
|
|
sample.insert(std::move(col));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
ColumnWithTypeAndName col;
|
|
|
|
col.type = std::make_shared<DataTypeUInt8>();
|
|
|
|
sample.insert(std::move(col));
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
WriteBufferFromOStream out_buf(std::cout);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
LimitBlockInputStream in_limit(in, 10, 0);
|
|
|
|
RowOutputStreamPtr output_ = std::make_shared<TabSeparatedRowOutputStream>(out_buf, sample);
|
2018-02-19 00:45:32 +00:00
|
|
|
BlockOutputStreamFromRowOutputStream output(output_, sample);
|
2016-05-28 08:11:52 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
copyData(in_limit, output);
|
|
|
|
}
|
2010-03-18 19:32:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return 0;
|
2010-03-18 19:32:14 +00:00
|
|
|
}
|
2016-05-28 08:11:52 +00:00
|
|
|
catch (const DB::Exception & e)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::cerr << e.what() << ", " << e.displayText() << std::endl;
|
|
|
|
return 1;
|
2016-05-28 08:11:52 +00:00
|
|
|
}
|