fix: backtick-escape column names in filter queries#2488
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 76b889d The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Greptile SummaryThis PR fixes ClickHouse identifier escaping for filter keys containing special characters (hyphens, dots-in-column-names), which were previously interpolated verbatim, causing ClickHouse to misparse them as arithmetic expressions. The fix introduces a new
Confidence Score: 5/5Safe to merge. The core escaping logic is correct, well-tested (unit + E2E), and the design cleanly separates the persisted form (unquoted URL state) from the SQL-generation form (quoted at query time). The changes are tightly scoped: new quoting helpers are covered by unit tests, the dashboard getFilterQueriesForSource bug is a one-line fix that aligns two previously-divergent code paths, and the E2E suite validates the full round-trip for all key shapes including hyphens, dots-in-column-names, and Map bracket access. The one gap identified — toString(...) keys falling through to incorrect segment quoting — cannot be reached through any current call path and is a hardening suggestion only. packages/app/src/components/DBSearchPageFilters/utils.ts — the toQuotedClickHouseKeyExpression function has a narrow toString(...) edge case worth closing; everything else in the file is solid. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User selects filter value in UI] --> B[setFilterValue stores unquoted key e.g. service-name]
B --> C[filtersToQuery emits verbatim: service-name IN 'foo']
C --> D[URL / persisted Filter array stores unquoted key]
D --> E{Context}
E -->|Search page| F[escapeFilterKeysForSql rewriteFilterConditionKey]
F --> G[toQuotedClickHouseKeyExpression with knownColumns set]
G --> H{Is key a known flat column?}
H -->|Yes e.g. __hdx_materialized_k8s.cluster.name| I[Quote whole name as single backtick identifier]
H -->|No - map bracket form| J[Quote only the root column name]
H -->|No - plain needs quoting| K[Quote each dot segment]
I --> L[ClickHouse query with escaped keys]
J --> L
K --> L
E -->|Dashboard page| M[filtersToQuery with stringifyKeys=true]
M --> N[toString wrapped key e.g. toString service-name]
N --> O[ClickHouse query - user must pre-quote special identifiers]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[User selects filter value in UI] --> B[setFilterValue stores unquoted key e.g. service-name]
B --> C[filtersToQuery emits verbatim: service-name IN 'foo']
C --> D[URL / persisted Filter array stores unquoted key]
D --> E{Context}
E -->|Search page| F[escapeFilterKeysForSql rewriteFilterConditionKey]
F --> G[toQuotedClickHouseKeyExpression with knownColumns set]
G --> H{Is key a known flat column?}
H -->|Yes e.g. __hdx_materialized_k8s.cluster.name| I[Quote whole name as single backtick identifier]
H -->|No - map bracket form| J[Quote only the root column name]
H -->|No - plain needs quoting| K[Quote each dot segment]
I --> L[ClickHouse query with escaped keys]
J --> L
K --> L
E -->|Dashboard page| M[filtersToQuery with stringifyKeys=true]
M --> N[toString wrapped key e.g. toString service-name]
N --> O[ClickHouse query - user must pre-quote special identifiers]
Reviews (9): Last reviewed commit: "fix: correct filter handling for columns..." | Re-trigger Greptile |
E2E Test Results❌ 1 test failed • 208 passed • 3 skipped • 1483s
Tests ran across 4 shards in parallel. |
c4a4ea1 to
a828317
Compare
5ed3770 to
4ba6bb0
Compare
4ba6bb0 to
13e4cea
Compare
13e4cea to
76b889d
Compare
Summary
Fixes [HDX-4585]: Column names containing special characters (e.g. hyphens like
log-status,az-id,flow-direction) were interpolated as bare identifiers in filter/key-value queries, causing ClickHouse to misparse them. For example,log-statuswas interpreted aslogminusstatus.Expressions are now backtick-quoted using
SqlString.escapeIdprior to being queried as filter keys:LogStatusThis has been fixed both when querying for filter key/values and when generating query conditions based on selected filters.
Testing
I've added a fairly comprehensive set of E2E tests testing the following cases
ServiceName,ResourceAttributes['key.subKey.subSubKey'],__hdx_materialized_k8s.cluster.name, andservice-nameServiceName,ResourceAttributes['key.subKey.subSubKey'],__hdx_materialized_k8s.cluster.name,ResourceAttributesJSON.key.subKey.subSubKeyandservice-nameLinear Issue: Closes HDX-4585