|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +#include "dwio/nimble/velox/NimbleConfig.h" |
| 17 | + |
| 18 | +#include "dwio/nimble/encodings/EncodingSelectionPolicy.h" |
| 19 | + |
| 20 | +#include <folly/json/dynamic.h> |
| 21 | +#include <folly/json/json.h> |
| 22 | + |
| 23 | +DEFINE_string( |
| 24 | + nimble_selection_read_factors, |
| 25 | + "Constant=1.0;Trivial=0.5;FixedBitWidth=0.9;MainlyConstant=1.0;SparseBool=1.0;Dictionary=1.0;RLE=1.0;Varint=1.0", |
| 26 | + "Encoding selection read factors, in the format: " |
| 27 | + "<EncodingName>=<FactorFloatValue>;<EncodingName>=<FactorFloatValue>;..."); |
| 28 | + |
| 29 | +DEFINE_double( |
| 30 | + nimble_selection_compression_accept_ratio, |
| 31 | + 0.97, |
| 32 | + "Encoding selection compression accept ratio."); |
| 33 | + |
| 34 | +DEFINE_bool( |
| 35 | + nimble_zstrong_enable_variable_bit_width_compressor, |
| 36 | + false, |
| 37 | + "Enable zstrong variable bit width compressor at write time. Transparent at read time."); |
| 38 | + |
| 39 | +DEFINE_string( |
| 40 | + nimble_writer_input_buffer_default_growth_config, |
| 41 | + "{\"32\":4.0,\"512\":1.414,\"4096\":1.189}", |
| 42 | + "Default growth config for writer input buffers, each entry in the format of {range_start,growth_factor}"); |
| 43 | + |
| 44 | +namespace facebook::nimble { |
| 45 | +namespace { |
| 46 | +template <typename T> |
| 47 | +std::vector<T> parseVector(const std::string& str) { |
| 48 | + std::vector<T> result; |
| 49 | + if (!str.empty()) { |
| 50 | + std::vector<folly::StringPiece> pieces; |
| 51 | + folly::split(',', str, pieces, true); |
| 52 | + for (auto& p : pieces) { |
| 53 | + const auto& trimmedCol = folly::trimWhitespace(p); |
| 54 | + if (!trimmedCol.empty()) { |
| 55 | + result.push_back(folly::to<T>(trimmedCol)); |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + return result; |
| 60 | +} |
| 61 | + |
| 62 | +std::map<uint64_t, float> parseGrowthConfigMap(const std::string& str) { |
| 63 | + std::map<uint64_t, float> ret; |
| 64 | + NIMBLE_CHECK(!str.empty(), "Can't supply an empty growth config."); |
| 65 | + folly::dynamic json = folly::parseJson(str); |
| 66 | + for (const auto& pair : json.items()) { |
| 67 | + auto [_, inserted] = ret.emplace( |
| 68 | + folly::to<uint64_t>(pair.first.asString()), pair.second.asDouble()); |
| 69 | + NIMBLE_CHECK( |
| 70 | + inserted, fmt::format("Duplicate key: {}.", pair.first.asString())); |
| 71 | + } |
| 72 | + return ret; |
| 73 | +} |
| 74 | +} // namespace |
| 75 | + |
| 76 | +/* static */ Config::Entry<bool> Config::FLATTEN_MAP("orc.flatten.map", false); |
| 77 | + |
| 78 | +/* static */ Config::Entry<const std::vector<uint32_t>> Config::MAP_FLAT_COLS( |
| 79 | + "orc.map.flat.cols", |
| 80 | + {}, |
| 81 | + [](const std::vector<uint32_t>& val) { return folly::join(",", val); }, |
| 82 | + [](const std::string& /* key */, const std::string& val) { |
| 83 | + return parseVector<uint32_t>(val); |
| 84 | + }); |
| 85 | + |
| 86 | +/* static */ Config::Entry<const std::vector<uint32_t>> |
| 87 | + Config::DEDUPLICATED_COLS( |
| 88 | + "alpha.map.deduplicated.cols", |
| 89 | + {}, |
| 90 | + [](const std::vector<uint32_t>& val) { return folly::join(",", val); }, |
| 91 | + [](const std::string& /* key */, const std::string& val) { |
| 92 | + return parseVector<uint32_t>(val); |
| 93 | + }); |
| 94 | + |
| 95 | +/* static */ Config::Entry<const std::vector<uint32_t>> |
| 96 | + Config::BATCH_REUSE_COLS( |
| 97 | + "alpha.dictionaryarray.cols", |
| 98 | + {}, |
| 99 | + [](const std::vector<uint32_t>& val) { return folly::join(",", val); }, |
| 100 | + [](const std::string& /* key */, const std::string& val) { |
| 101 | + return parseVector<uint32_t>(val); |
| 102 | + }); |
| 103 | + |
| 104 | +/* static */ Config::Entry<uint64_t> Config::RAW_STRIPE_SIZE( |
| 105 | + "alpha.raw.stripe.size", |
| 106 | + 512L * 1024L * 1024L); |
| 107 | + |
| 108 | +/* static */ Config::Entry<const std::vector<std::pair<EncodingType, float>>> |
| 109 | + Config::MANUAL_ENCODING_SELECTION_READ_FACTORS( |
| 110 | + "alpha.encodingselection.read.factors", |
| 111 | + ManualEncodingSelectionPolicyFactory::parseReadFactors( |
| 112 | + FLAGS_nimble_selection_read_factors), |
| 113 | + [](const std::vector<std::pair<EncodingType, float>>& val) { |
| 114 | + std::vector<std::string> encodingFactorStrings; |
| 115 | + std::transform( |
| 116 | + val.cbegin(), |
| 117 | + val.cend(), |
| 118 | + std::back_inserter(encodingFactorStrings), |
| 119 | + [](const auto& readFactor) { |
| 120 | + return fmt::format( |
| 121 | + "{}={}", toString(readFactor.first), readFactor.second); |
| 122 | + }); |
| 123 | + return folly::join(";", encodingFactorStrings); |
| 124 | + }, |
| 125 | + [](const std::string& /* key */, const std::string& val) { |
| 126 | + return ManualEncodingSelectionPolicyFactory::parseReadFactors(val); |
| 127 | + }); |
| 128 | + |
| 129 | +/* static */ Config::Entry<float> |
| 130 | + Config::ENCODING_SELECTION_COMPRESSION_ACCEPT_RATIO( |
| 131 | + "alpha.encodingselection.compression.accept.ratio", |
| 132 | + FLAGS_nimble_selection_compression_accept_ratio); |
| 133 | + |
| 134 | +/* static */ Config::Entry<uint32_t> Config::ZSTRONG_COMPRESSION_LEVEL( |
| 135 | + "alpha.zstrong.compression.level", |
| 136 | + 4); |
| 137 | + |
| 138 | +/* static */ Config::Entry<uint32_t> Config::ZSTRONG_DECOMPRESSION_LEVEL( |
| 139 | + "alpha.zstrong.decompression.level", |
| 140 | + 2); |
| 141 | + |
| 142 | +/* static */ Config::Entry<bool> |
| 143 | + Config::ENABLE_ZSTRONG_VARIABLE_BITWIDTH_COMPRESSOR( |
| 144 | + "alpha.zstrong.enable.variable.bit.width.compressor", |
| 145 | + FLAGS_nimble_zstrong_enable_variable_bit_width_compressor); |
| 146 | + |
| 147 | +/* static */ Config::Entry<const std::map<uint64_t, float>> |
| 148 | + Config::INPUT_BUFFER_DEFAULT_GROWTH_CONFIGS( |
| 149 | + "alpha.writer.input.buffer.default.growth.configs", |
| 150 | + parseGrowthConfigMap( |
| 151 | + FLAGS_nimble_writer_input_buffer_default_growth_config), |
| 152 | + [](const std::map<uint64_t, float>& val) { |
| 153 | + folly::dynamic obj = folly::dynamic::object; |
| 154 | + for (const auto& [rangeStart, growthFactor] : val) { |
| 155 | + obj[folly::to<std::string>(rangeStart)] = growthFactor; |
| 156 | + } |
| 157 | + return folly::toJson(obj); |
| 158 | + }, |
| 159 | + [](const std::string& /* key */, const std::string& val) { |
| 160 | + return parseGrowthConfigMap(val); |
| 161 | + }); |
| 162 | +} // namespace facebook::nimble |
0 commit comments