From c1fa34a9afc619c0b2ae922fc544868c40d60798 Mon Sep 17 00:00:00 2001 From: nikitamikhaylov Date: Wed, 14 Oct 2020 16:03:13 +0300 Subject: [PATCH] done --- utils/db-generator/CMakeLists.txt | 2 +- utils/db-generator/query_db_generator.cpp | 40 +++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/utils/db-generator/CMakeLists.txt b/utils/db-generator/CMakeLists.txt index f1a86a7f8af..e4652643f79 100644 --- a/utils/db-generator/CMakeLists.txt +++ b/utils/db-generator/CMakeLists.txt @@ -1,2 +1,2 @@ add_executable (query_db_generator query_db_generator.cpp) -target_link_libraries(query_db_generator PRIVATE clickhouse_parsers) \ No newline at end of file +target_link_libraries(query_db_generator PRIVATE clickhouse_parsers boost::program_options) \ No newline at end of file diff --git a/utils/db-generator/query_db_generator.cpp b/utils/db-generator/query_db_generator.cpp index 88418e9b6c3..7bc7a300f82 100644 --- a/utils/db-generator/query_db_generator.cpp +++ b/utils/db-generator/query_db_generator.cpp @@ -1,7 +1,8 @@ #include -#include #include +#include #include +#include #include #include @@ -16,6 +17,10 @@ #include #include +#include +#include + +namespace po = boost::program_options; using ColumnType = uint32_t; using TableAndColumn = std::pair; @@ -1264,8 +1269,39 @@ TableList getTablesFromSelect(std::vector queries) return result; } -int main(int, char **) +int main(int argc, const char *argv[]) { + try + { + po::options_description desc("Allowed options"); + desc.add_options() + ("help,h", "Display greeting and allowed options.") + ("input,i", po::value(), "Input filename.") + ("output,o", po::value(), "Output filename."); + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + if (vm.count("help") || vm.count("h")) + { + std::cout << "Hello! It is datasets generator for ClickHouse's queries." << std::endl; + std::cout << "Put some query as an input and it will produce queries for table creating and filling." << std::endl; + std::cout << "After that your query could be executed on this tables." << std::endl; + std::cout << desc << std::endl; + return 1; + } + if (vm.count("input")) + freopen(vm["input"].as().c_str(), "r", stdin); + if (vm.count("output")) + freopen(vm["output"].as().c_str(), "w", stdout); + } + catch (...) + { + std::cerr << "Got error while parse command line arguments: " << DB::getCurrentExceptionMessage(true) << std::endl; + throw; + } + handlers["plus"] = arithmeticFunc; handlers["minus"] = arithmeticFunc; handlers["like"] = likeFunc;