ClickHouse/dbms/DataStreams/tests/union_stream2.cpp

66 lines
1.9 KiB
C++
Raw Normal View History

#include <iostream>
#include <iomanip>
#include <IO/WriteBufferFromFileDescriptor.h>
#include <Storages/System/StorageSystemNumbers.h>
#include <DataStreams/LimitBlockInputStream.h>
#include <DataStreams/UnionBlockInputStream.h>
#include <DataStreams/AsynchronousBlockInputStream.h>
#include <DataStreams/IBlockOutputStream.h>
#include <DataStreams/copyData.h>
#include <DataTypes/DataTypesNumber.h>
#include <Interpreters/Context.h>
#include <Interpreters/loadMetadata.h>
#include <Processors/Executors/TreeExecutorBlockInputStream.h>
using namespace DB;
2017-12-01 21:51:50 +00:00
int main(int, char **)
try
{
Context context = Context::createGlobal();
2019-07-08 02:14:32 +00:00
context.makeGlobalContext();
Settings settings = context.getSettings();
context.setPath("./");
loadMetadata(context);
Names column_names;
column_names.push_back("WatchID");
2020-02-17 19:28:25 +00:00
StoragePtr table = DatabaseCatalog::instance().getTable({"default", "hits6"});
2018-04-23 19:05:46 +00:00
QueryProcessingStage::Enum stage = table->getQueryProcessingStage(context);
auto pipes = table->read(column_names, {}, context, stage, settings.max_block_size, settings.max_threads);
BlockInputStreams streams(pipes.size());
for (size_t i = 0, size = streams.size(); i < size; ++i)
streams[i] = std::make_shared<AsynchronousBlockInputStream>(std::make_shared<TreeExecutorBlockInputStream>(std::move(pipes[i])));
2018-11-28 14:33:40 +00:00
BlockInputStreamPtr stream = std::make_shared<UnionBlockInputStream>(streams, nullptr, settings.max_threads);
stream = std::make_shared<LimitBlockInputStream>(stream, 10, 0);
WriteBufferFromFileDescriptor wb(STDERR_FILENO);
Block sample = table->getSampleBlock();
BlockOutputStreamPtr out = context.getOutputFormat("TabSeparated", wb, sample);
copyData(*stream, *out);
return 0;
}
catch (const Exception & e)
{
std::cerr << e.what() << ", " << e.displayText() << std::endl
<< std::endl
<< "Stack trace:" << std::endl
<< e.getStackTraceString();
return 1;
}