Repository navigation
Preserve known identifiers in obfuscateQuery - #103843
Merged
Merged
Conversation
The SQL function `obfuscateQuery` (and `obfuscateQueryWithSeed`) used to pass an empty `known_identifier_func` to `obfuscateQueries`, so names of built-in functions, aggregate functions, table functions, formats, data types, storages, codecs and settings were replaced by random words — making the output less readable and inconsistent with `clickhouse-format --obfuscate`. Mirror the logic from `programs/format/Format.cpp` so all registered names are kept as-is. The set is built lazily once per process. Adds a regression test in `tests/queries/0_stateless/04145_obfuscate_query_known_identifiers.sql`.
Contributor
|
Workflow [PR], commit [ea742cb] Summary: ❌
AI ReviewSummaryThis PR makes ClickHouse Rules
Final Verdict
|
…ery` `TableFunctionFactory::isTableFunctionName` only checks the case-sensitive map and ignores aliases, so table functions written in uppercase (e.g. `NUMBERS(10)`) were still obfuscated. Add table function names to the pre-built `names` set instead — the existing case-insensitive fallback then matches `NUMBERS` to `numbers`, and `getAllRegisteredNames` already includes aliases.
`Format.cpp` had the same bug as the SQL function: table function names written in uppercase or via aliases (e.g. `NUMBERS(10)`) were obfuscated because `TableFunctionFactory::isTableFunctionName` is exact-case only and ignores aliases. Add the table function names to the `additional_names` set so the existing case-insensitive fallback covers them.
The previous workarounds in \`obfuscateQuery\` and \`clickhouse-format\` papered over a real bug in \`TableFunctionFactory::isTableFunctionName\`, which only checked the exact-case map and ignored aliases as well as the \`case_insensitive_table_functions\` map maintained by the same factory. Mirror the lookup logic from \`tryGet\` so the method now resolves aliases via \`getAliasToOrName\` and falls back to the case-insensitive map. This benefits all callers (e.g. \`TableFunctionRemote\`, \`QueryAnalyzer\`, \`QueryFuzzer\`) and lets the obfuscators rely on \`isTableFunctionName\` directly without their own table function set. Revert the workarounds in \`obfuscateQuery.cpp\` and \`Format.cpp\`. Update the regression test to use \`VALUES\` (a case-insensitive table function) instead of \`NUMBERS\`, which is in fact case-sensitive.
1 task
1 task done
`master` added `04145_h3_polygon_to_cells_invalid_type` and `04145_url_glob_parallelize_output` after this branch was created, so shift our test to the next available number. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
LLVM Coverage Report
Changed lines: 100.00% (51/51) · Uncovered code |
pull Bot
pushed a commit
to Mattlk13/ClickHouse
that referenced
this pull request
May 5, 2026
…Logs` flush `SystemLogs::flushImpl` calls `BaseDaemon::instance().flushTextLogs()` to drain the async logger before iterating system log queues. `BaseDaemon::instance()` is `dynamic_cast<BaseDaemon &>(Poco::Util::Application::instance())`, so when the application is `ClientApplicationBase`-derived (e.g. `clickhouse-local`, `clickhouse-client`) the cast throws `std::bad_cast`. The exception escapes `SystemLogs::flushAndShutdown` -> `DatabaseCatalog::shutdownImpl` -> `Context::shutdown`, leaving the saving threads alive. When the holder of the last `Context` reference drops it, `~ContextSharedPart` runs `~SystemLogs` -> `~SystemLog<T>`. `queue` lives in `SystemLogBase<T>` and `saving_thread` in `ISystemLog`, so member destruction tears down the `SystemLogQueue` and its condition variables before the saving thread has been joined. `pthread_cond_destroy` then blocks forever because the saving thread is still parked in `pop()` waiting on `flush_event`. Meanwhile the periodic saving-thread flushes that fire after `~Application` has already nulled `_pInstance` show up as `Null pointer: _pInstance` from `Context::getConfigRef()` -> `Application::instance().config()` (via `InterpreterCreateQuery::createTable` -> `UserDefinedSQLFunctionFactory::empty` -> `Context::getUserDefinedSQLObjectsStorage`), which is the symptom reported on the docs check. Two fixes: * `SystemLogs::flushImpl` now calls a small `flushAsyncTextLogsIfPossible` helper that uses `BaseDaemon::tryGetInstance` (a `dynamic_cast<BaseDaemon *>` internally) and skips the call when the application is not a `BaseDaemon`, so flushing on `clickhouse-local`/`clickhouse-client` is a no-op instead of raising `std::bad_cast`. * `SystemLogBase<T>` now has an explicit destructor that calls `stopFlushThread()`, joining the saving thread before any of the queue's condition variables can be destroyed. This is defence-in-depth so that any future path that bypasses `flushAndShutdown` cannot reproduce the same hang. Reproduction with the affected docs config (~30 system log sections, `SELECT 1`) on master: query takes 54+ s and the process hangs in `pthread_cond_destroy` from `~SystemLogQueue<FilesystemCacheLogElement>`. With this change the same invocation completes in ~3.2 s (the residual time is the cost of constructing every configured `SystemLog`) and exits cleanly. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=103843&sha=41c0a8a98f6f189f2c3c7025a979112c40ce7220&name_0=PR&name_1=Docs%20check PR: ClickHouse#103843 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
alexey-milovidov
added a commit
that referenced
this pull request
May 6, 2026
The original PR fixes both the SQL `obfuscateQuery` function (which does not exist in 26.4) and `clickhouse-format --obfuscate`. The root-cause fix in `TableFunctionFactory::isTableFunctionName` — consulting aliases and the case-insensitive map in addition to the exact-case map — is the only part that applies to 26.4 and is sufficient to preserve known table function names (including aliases like `VALUES` and `url`) when running `clickhouse-format --obfuscate`. Original pull-request: #103843 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
robot-ch-test-poll1
added a commit
that referenced
this pull request
May 6, 2026
Cherry pick #103843 to 26.4: Preserve known identifiers in `obfuscateQuery`
robot-clickhouse
added a commit
that referenced
this pull request
May 6, 2026
alexey-milovidov
added a commit
that referenced
this pull request
May 6, 2026
The SQL function `obfuscateQuery` (and `obfuscateQueryWithSeed`) used to pass an empty `known_identifier_func` to `obfuscateQueries`, so names of built-in functions, aggregate functions, table functions, formats, data types, storages, codecs and settings were replaced by random words — making the output less readable and inconsistent with `clickhouse-format --obfuscate`. Mirror the logic from `programs/format/Format.cpp` so all registered names are kept as-is. The set is built lazily once per process. Also fix `TableFunctionFactory::isTableFunctionName` to consult aliases and the case-insensitive map (mirroring `tryGet`), so table functions written in uppercase (e.g. `VALUES`) or via aliases are recognized as known identifiers by both `obfuscateQuery` and `clickhouse-format --obfuscate`. Adds a regression test in `tests/queries/0_stateless/04146_obfuscate_query_known_identifiers.sql`. Original pull-request: #103843 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
alexey-milovidov
added a commit
that referenced
this pull request
May 6, 2026
Backport #103843 to 26.4: Preserve known identifiers in `obfuscateQuery`
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…fuscateQuery` The SQL function `obfuscateQuery` (and `obfuscateQueryWithSeed`) used to pass an empty `known_identifier_func` to `obfuscateQueries`, so names of built-in functions, aggregate functions, table functions, formats, data types, storages, codecs and settings were replaced by random words — making the output less readable and inconsistent with `clickhouse-format --obfuscate`. Mirror the logic from `programs/format/Format.cpp` so all registered names are kept as-is. The set is built lazily once per process. Also fix `TableFunctionFactory::isTableFunctionName` to consult aliases and the case-insensitive map (mirroring `tryGet`), so table functions written in uppercase (e.g. `VALUES`) or via aliases are recognized as known identifiers by both `obfuscateQuery` and `clickhouse-format --obfuscate`. Adds a regression test in `tests/queries/0_stateless/04146_obfuscate_query_known_identifiers.sql`. Original pull-request: ClickHouse#103843 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…3843 Backport ClickHouse#103843 to 26.4: Preserve known identifiers in `obfuscateQuery`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The SQL function
obfuscateQuery(andobfuscateQueryWithSeed) used to pass an emptyknown_identifier_functoobfuscateQueries, so names of built-in functions, aggregate functions, table functions, formats, data types, storages, codecs and settings were replaced by random words. This made the output less readable and inconsistent withclickhouse-format --obfuscate, which already builds a comprehensive set of known names from all factories.This PR mirrors the logic from
programs/format/Format.cpp: build aKnownIdentifierFunconce per process that consultsFunctionFactory,AggregateFunctionFactory,TableFunctionFactory,FormatFactory, plus storages, data types, settings, MergeTree settings, MergeTree indices, codecs, databases, dictionary layouts and sources, and time-zone components, with a case-insensitive fallback. Inside the server, all these factories are already populated at startup, so no additional registration is needed.Before:
After:
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
obfuscateQueryandobfuscateQueryWithSeednow preserve names of built-in functions, aggregate functions, table functions, formats, data types, storages, codecs and settings, matching the behaviour ofclickhouse-format --obfuscate.Documentation entry for user-facing changes
Version info
26.4.2.9