| 62 | } |
| 63 | |
| 64 | int mainEntryClickHouseCompressor(int argc, char ** argv) |
| 65 | { |
| 66 | using namespace DB; |
| 67 | namespace po = boost::program_options; |
| 68 | |
| 69 | po::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth()); |
| 70 | desc.add_options() |
| 71 | ("help,h", "produce help message") |
| 72 | ("input", po::value<std::string>()->value_name("INPUT"), "input file") |
| 73 | ("output", po::value<std::string>()->value_name("OUTPUT"), "output file") |
| 74 | ("decompress,d", "decompress") |
| 75 | ("offset-in-compressed-file", po::value<size_t>()->default_value(0ULL), "offset to the compressed block (i.e. physical file offset)") |
| 76 | ("offset-in-decompressed-block", po::value<size_t>()->default_value(0ULL), "offset to the decompressed block (i.e. virtual offset)") |
| 77 | ("block-size,b", po::value<unsigned>()->default_value(DBMS_DEFAULT_BUFFER_SIZE), "compress in blocks of specified size") |
| 78 | ("hc", "use LZ4HC instead of LZ4") |
| 79 | ("zstd", "use ZSTD instead of LZ4") |
| 80 | ("codec", po::value<std::vector<std::string>>()->multitoken(), "use codecs combination instead of LZ4") |
| 81 | ("level", po::value<int>(), "compression level for codecs specified via flags") |
| 82 | ("none", "use no compression instead of LZ4") |
| 83 | ("stat", "print block statistics of compressed data") |
| 84 | ; |
| 85 | |
| 86 | po::positional_options_description positional_desc; |
| 87 | positional_desc.add("input", 1); |
| 88 | positional_desc.add("output", 1); |
| 89 | |
| 90 | po::variables_map options; |
| 91 | po::store(po::command_line_parser(argc, argv).options(desc).positional(positional_desc).run(), options); |
| 92 | |
| 93 | if (options.count("help")) |
| 94 | { |
| 95 | std::cout << "Usage: " << argv[0] << " [options] < INPUT > OUTPUT" << std::endl; |
| 96 | std::cout << "Usage: " << argv[0] << " [options] INPUT OUTPUT" << std::endl; |
| 97 | std::cout << desc << std::endl; |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | try |
| 102 | { |
| 103 | bool decompress = options.count("decompress"); |
| 104 | bool use_lz4hc = options.count("hc"); |
| 105 | bool use_zstd = options.count("zstd"); |
| 106 | bool stat_mode = options.count("stat"); |
| 107 | bool use_none = options.count("none"); |
| 108 | unsigned block_size = options["block-size"].as<unsigned>(); |
| 109 | std::vector<std::string> codecs; |
| 110 | if (options.count("codec")) |
| 111 | codecs = options["codec"].as<std::vector<std::string>>(); |
| 112 | |
| 113 | if ((use_lz4hc || use_zstd || use_none) && !codecs.empty()) |
| 114 | throw Exception("Wrong options, codec flags like --zstd and --codec options are mutually exclusive", ErrorCodes::BAD_ARGUMENTS); |
| 115 | |
| 116 | if (!codecs.empty() && options.count("level")) |
| 117 | throw Exception("Wrong options, --level is not compatible with --codec list", ErrorCodes::BAD_ARGUMENTS); |
| 118 | |
| 119 | std::string method_family = "LZ4"; |
| 120 | |
| 121 | if (use_lz4hc) |
no test coverage detected