#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char ** argv) try { using namespace DB; size_t n = argc == 2 ? parse(argv[1]) : 10ULL; std::string input = "SELECT number, number / 3, number * number"; ParserSelectQuery parser; ASTPtr ast = parseQuery(parser, input.data(), input.data() + input.size(), "", 0); Context context = Context::createGlobal(); NamesAndTypesList source_columns = {{"number", std::make_shared()}}; auto syntax_result = SyntaxAnalyzer(context, {}).analyze(ast, source_columns); ExpressionAnalyzer analyzer(ast, syntax_result, context); ExpressionActionsChain chain(context); analyzer.appendSelect(chain, false); analyzer.appendProjectResult(chain); chain.finalize(); ExpressionActionsPtr expression = chain.getLastActions(); StoragePtr table = StorageSystemNumbers::create("numbers", false); Names column_names; column_names.push_back("number"); QueryProcessingStage::Enum stage = table->getQueryProcessingStage(context); BlockInputStreamPtr in; in = table->read(column_names, {}, context, stage, 8192, 1)[0]; in = std::make_shared(in, expression); in = std::make_shared(in, 10, std::max(static_cast(0), static_cast(n) - 10)); WriteBufferFromOStream out1(std::cout); BlockOutputStreamPtr out = FormatFactory::instance().getOutput("TabSeparated", out1, expression->getSampleBlock(), context); { Stopwatch stopwatch; stopwatch.start(); copyData(*in, *out); stopwatch.stop(); std::cout << std::fixed << std::setprecision(2) << "Elapsed " << stopwatch.elapsedSeconds() << " sec." << ", " << n / stopwatch.elapsedSeconds() << " rows/sec." << std::endl; } return 0; } catch (const DB::Exception & e) { std::cerr << e.what() << ", " << e.displayText() << std::endl; throw; }