1 | #include <iostream> |
2 | #include <iomanip> |
3 | |
4 | #include <IO/WriteBufferFromFileDescriptor.h> |
5 | |
6 | #include <Storages/System/StorageSystemNumbers.h> |
7 | |
8 | #include <DataStreams/LimitBlockInputStream.h> |
9 | #include <DataStreams/UnionBlockInputStream.h> |
10 | #include <DataStreams/AsynchronousBlockInputStream.h> |
11 | #include <DataStreams/IBlockOutputStream.h> |
12 | #include <DataStreams/copyData.h> |
13 | |
14 | #include <DataTypes/DataTypesNumber.h> |
15 | |
16 | #include <Interpreters/Context.h> |
17 | #include <Interpreters/loadMetadata.h> |
18 | |
19 | |
20 | using namespace DB; |
21 | |
22 | int main(int, char **) |
23 | try |
24 | { |
25 | Context context = Context::createGlobal(); |
26 | context.makeGlobalContext(); |
27 | Settings settings = context.getSettings(); |
28 | |
29 | context.setPath("./" ); |
30 | |
31 | loadMetadata(context); |
32 | |
33 | Names column_names; |
34 | column_names.push_back("WatchID" ); |
35 | |
36 | StoragePtr table = context.getTable("default" , "hits6" ); |
37 | |
38 | QueryProcessingStage::Enum stage = table->getQueryProcessingStage(context); |
39 | BlockInputStreams streams = table->read(column_names, {}, context, stage, settings.max_block_size, settings.max_threads); |
40 | |
41 | for (size_t i = 0, size = streams.size(); i < size; ++i) |
42 | streams[i] = std::make_shared<AsynchronousBlockInputStream>(streams[i]); |
43 | |
44 | BlockInputStreamPtr stream = std::make_shared<UnionBlockInputStream>(streams, nullptr, settings.max_threads); |
45 | stream = std::make_shared<LimitBlockInputStream>(stream, 10, 0); |
46 | |
47 | WriteBufferFromFileDescriptor wb(STDERR_FILENO); |
48 | Block sample = table->getSampleBlock(); |
49 | BlockOutputStreamPtr out = context.getOutputFormat("TabSeparated" , wb, sample); |
50 | |
51 | copyData(*stream, *out); |
52 | |
53 | return 0; |
54 | } |
55 | catch (const Exception & e) |
56 | { |
57 | std::cerr << e.what() << ", " << e.displayText() << std::endl |
58 | << std::endl |
59 | << "Stack trace:" << std::endl |
60 | << e.getStackTrace().toString(); |
61 | return 1; |
62 | } |
63 | |