Repository navigation
Conversation
| ColumnString::Chars & res_data, | ||
| ColumnString::Offsets & res_offsets) | ||
| { | ||
| std::string_view query(reinterpret_cast<const char *>(data.data() + offsets[- 1]), offsets[0] - offsets[- 1] - 1); |
There was a problem hiding this comment.
This functions doesn't handle columns correctly. It only works on the first string.
To get an idea of what this code should be like you can take a look at
ClickHouse/src/Functions/soundex.cpp
Lines 78 to 99 in 700492f
There was a problem hiding this comment.
This applies also to other functions.
| // Obfuscated queries are usually don't take more than x2 characters. | ||
| res_data.reserve(res.size() * 2); | ||
|
|
||
| memcpySmallAllowReadWriteOverflow15(res_data.data(), res.c_str(), res.size()); |
There was a problem hiding this comment.
I don't think it's safe to use this function in this specific case.
You don't know if those buffers have up to res.size()+15 memory allocated.
This comment probably applies to other uses of this function.
| return res_col; | ||
| } | ||
| private: | ||
| String getStringColumnValue(const ColumnPtr & column) const |
There was a problem hiding this comment.
This function makes unnecessary copies. It also doesn't handle the whole column, but just the first value.
|
|
||
| std::string res = buffer.str(); | ||
| // Obfuscated queries are usually don't take more than x2 characters. | ||
| res_data.reserve(res.size() * 2); |
There was a problem hiding this comment.
Isn't res.size() already the correct size?
Also you will need to resize res_data at some point, just reserve is not enough.
| res_offsets.resize(1); | ||
| obfuscateQueries(query, buffer, obfuscated_words_map, used_nouns, hash_func, is_known_identifier); | ||
|
|
||
| std::string res = buffer.str(); |
|
Implemented in other PRs. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Added 4 new query-rewrite functions to SQL dialect (obfuscateQuery, tokenizeQuery[OneLine], formatQuery)
Documentation entry for user-facing changes
Feature was being developed based on #29922 ticket.
This PR adds 4 functions to obfuscate/tokenize/format query within user query.
Functions were added directly to SQL dialect - IMO it's the most straightforward and obvious way for user to use them in their queries, moreover this is consistent with query normalization functions. Implementing these functions in imitation to EXPLAIN would be too broad for such functions which mostly would be used as meta-tools for requests.
Functionality is based on already (obviously) present query tokenization used in Clickhouse and on clickhouse-format utility to be more consistent within Clickhouse already present utilities.