| 151 | |
| 152 | |
| 153 | ColumnPtr ObfuscateQueryFunction::execute(const ColumnsWithTypeAndName & arguments, size_t input_rows_count) const |
| 154 | { |
| 155 | const ColumnPtr col_query = arguments[0].column; |
| 156 | |
| 157 | auto col_res = ColumnString::create(); |
| 158 | const std::optional<UInt64> const_seed_hash = (arguments.size() >= 2) ? extractConstSeedFromArg(arguments[1].column) : std::nullopt; |
| 159 | const KnownIdentifierFunc & known_identifier_func = getKnownIdentifierFunc(); |
| 160 | |
| 161 | /// Two main paths: column of strings, or a const column. |
| 162 | if (const ColumnString * col_query_string = checkAndGetColumn<ColumnString>(col_query.get())) |
| 163 | { |
| 164 | for (size_t i = 0; i < input_rows_count; ++i) |
| 165 | { |
| 166 | std::string_view src = col_query_string->getDataAt(i); |
| 167 | |
| 168 | UInt64 seed_value = 0; |
| 169 | if (mode == Mode::WithProvidedSeed && arguments.size() >= 2) |
| 170 | { |
| 171 | seed_value = const_seed_hash ? *const_seed_hash : extractSeedFromArg(arguments[1].column, i); |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | seed_value = thread_local_rng(); |
| 176 | } |
| 177 | |
| 178 | WordMap obfuscate_map; |
| 179 | WordSet used_nouns; |
| 180 | |
| 181 | SipHash hash_func; |
| 182 | hash_func.update(seed_value); |
| 183 | |
| 184 | WriteBufferFromOwnString wb; |
| 185 | obfuscateQueries(src, wb, obfuscate_map, used_nouns, hash_func, known_identifier_func); |
| 186 | auto & out = wb.str(); |
| 187 | |
| 188 | col_res->insertData(out.data(), out.size()); |
| 189 | } |
| 190 | } |
| 191 | else if (const ColumnConst * col_query_const = checkAndGetColumnConst<ColumnString>(col_query.get())) |
| 192 | { |
| 193 | const String & const_query = col_query_const->getValue<String>(); |
| 194 | for (size_t i = 0; i < input_rows_count; ++i) |
| 195 | { |
| 196 | UInt64 seed_value = 0; |
| 197 | if (mode == Mode::WithProvidedSeed && arguments.size() >= 2) |
| 198 | { |
| 199 | seed_value = const_seed_hash ? *const_seed_hash : extractSeedFromArg(arguments[1].column, i); |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | seed_value = thread_local_rng(); |
| 204 | } |
| 205 | |
| 206 | WordMap obfuscate_map; |
| 207 | WordSet used_nouns; |
| 208 | |
| 209 | SipHash hash_func; |
| 210 | hash_func.update(seed_value); |
no test coverage detected