2016-06-07 08:23:15 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
#include <Poco/ConsoleChannel.h>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteBufferFromFileDescriptor.h>
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataStreams/OneBlockInputStream.h>
|
|
|
|
#include <DataStreams/IBlockOutputStream.h>
|
|
|
|
#include <DataStreams/CollapsingSortedBlockInputStream.h>
|
|
|
|
#include <DataStreams/CollapsingFinalBlockInputStream.h>
|
|
|
|
#include <DataStreams/copyData.h>
|
|
|
|
#include <Interpreters/Context.h>
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
2016-06-07 08:23:15 +00:00
|
|
|
|
|
|
|
|
2017-12-01 21:40:58 +00:00
|
|
|
int main(int, char **)
|
2016-06-08 13:08:20 +00:00
|
|
|
try
|
2016-06-07 08:23:15 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
using namespace DB;
|
|
|
|
|
|
|
|
Poco::AutoPtr<Poco::ConsoleChannel> channel = new Poco::ConsoleChannel(std::cerr);
|
|
|
|
Logger::root().setChannel(channel);
|
|
|
|
Logger::root().setLevel("trace");
|
|
|
|
|
|
|
|
Block block1;
|
|
|
|
|
|
|
|
{
|
|
|
|
ColumnWithTypeAndName column1;
|
|
|
|
column1.name = "Sign";
|
|
|
|
column1.type = std::make_shared<DataTypeInt8>();
|
2020-02-28 19:14:13 +00:00
|
|
|
column1.column = ColumnInt8::create({static_cast<int8_t>(1), static_cast<int8_t>(-1)});
|
2017-04-01 07:20:54 +00:00
|
|
|
block1.insert(column1);
|
|
|
|
|
|
|
|
ColumnWithTypeAndName column2;
|
|
|
|
column2.name = "CounterID";
|
|
|
|
column2.type = std::make_shared<DataTypeUInt32>();
|
2020-02-28 19:14:13 +00:00
|
|
|
column2.column = ColumnUInt32::create({static_cast<uint32_t>(123), static_cast<uint32_t>(123)});
|
2017-04-01 07:20:54 +00:00
|
|
|
block1.insert(column2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Block block2;
|
|
|
|
|
|
|
|
{
|
|
|
|
ColumnWithTypeAndName column1;
|
|
|
|
column1.name = "Sign";
|
|
|
|
column1.type = std::make_shared<DataTypeInt8>();
|
2020-02-28 19:14:13 +00:00
|
|
|
column1.column = ColumnInt8::create({static_cast<int8_t>(1), static_cast<int8_t>(1)});
|
2017-04-01 07:20:54 +00:00
|
|
|
block2.insert(column1);
|
|
|
|
|
|
|
|
ColumnWithTypeAndName column2;
|
|
|
|
column2.name = "CounterID";
|
|
|
|
column2.type = std::make_shared<DataTypeUInt32>();
|
2020-02-28 19:14:13 +00:00
|
|
|
column2.column = ColumnUInt32::create({static_cast<uint32_t>(123), static_cast<uint32_t>(456)});
|
2017-04-01 07:20:54 +00:00
|
|
|
block2.insert(column2);
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockInputStreams inputs;
|
|
|
|
inputs.push_back(std::make_shared<OneBlockInputStream>(block1));
|
|
|
|
inputs.push_back(std::make_shared<OneBlockInputStream>(block2));
|
|
|
|
|
|
|
|
SortDescription descr;
|
|
|
|
SortColumnDescription col_descr("CounterID", 1, 1);
|
|
|
|
descr.push_back(col_descr);
|
|
|
|
|
|
|
|
//CollapsingSortedBlockInputStream collapsed(inputs, descr, "Sign", 1048576);
|
|
|
|
CollapsingFinalBlockInputStream collapsed(inputs, descr, "Sign");
|
|
|
|
|
2017-06-19 20:31:23 +00:00
|
|
|
Context context = Context::createGlobal();
|
2019-07-08 02:14:32 +00:00
|
|
|
context.makeGlobalContext();
|
2017-04-01 07:20:54 +00:00
|
|
|
WriteBufferFromFileDescriptor out_buf(STDERR_FILENO);
|
|
|
|
BlockOutputStreamPtr output = context.getOutputFormat("TabSeparated", out_buf, block1);
|
|
|
|
|
|
|
|
copyData(collapsed, *output);
|
|
|
|
|
|
|
|
return 0;
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
2020-02-25 15:22:35 +00:00
|
|
|
|
2016-06-08 13:08:20 +00:00
|
|
|
catch (const DB::Exception & e)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::cerr << e.what() << ", " << e.displayText() << std::endl;
|
|
|
|
throw;
|
2016-06-08 13:08:20 +00:00
|
|
|
}
|