Repository navigation
fix: resolve Distributed table to local table for mergeTreeTextIndex - #2930
Vansh98789 wants to merge 2 commits into
Conversation
Text-index metadata queries (getMapKeys, getMapTextIndexKeyValues,
getTextIndexKeyValues) were passing the Distributed table name straight
to mergeTreeTextIndex(...) and system.parts, which only understand
MergeTree-family tables. This caused BAD_ARGUMENTS ('There is no index
with name ...') for any source pointing at a Distributed table.
Resolves the Distributed table to its underlying local table + cluster
(reusing the same getDistributedTableArgs/queryTableMetadata pattern
getSkipIndices already uses) and wraps the table function in cluster(...).
getMapKeys also now falls through to the MV/raw-table-scan tiers instead
of returning [] when the text-index query fails, so a transient failure
degrades gracefully instead of hiding all keys for that column.
Fixes ClickHouse#2880
🦋 Changeset detectedLatest commit: 4be7ce6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
@Vansh98789 is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR resolves Distributed source tables to their local MergeTree tables before querying text-index metadata and adds graceful fallback behavior for map-key discovery.
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking issue established. The changed metadata paths consistently resolve Distributed tables before building text-index and parts queries, while the new tests cover the principal routing and fallback behavior.
|
| Filename | Overview |
|---|---|
| packages/common-utils/src/core/metadata.ts | Adds centralized Distributed-to-local table resolution, cluster-aware text-index SQL generation, and map-key fallback behavior without an accepted correctness issue. |
| packages/common-utils/src/tests/metadata.test.ts | Adds regression tests covering Distributed map-key and TraceId text-index routing plus raw-scan fallback after an index-query failure. |
| .changeset/fix-text-index-distributed-table.md | Accurately documents the patch-level Distributed text-index metadata fix and fallback behavior. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Metadata request for source table] --> B{Table engine}
B -->|MergeTree| C[Use original database and table]
B -->|Distributed| D[Resolve cluster and local MergeTree table]
C --> E[Build mergeTreeTextIndex expression]
D --> F[Wrap mergeTreeTextIndex in cluster]
E --> G[Apply system.parts overlap filter]
F --> G
G --> H{Text-index query succeeds}
H -->|Yes| I[Return metadata keys or values]
H -->|No, map-key path| J[Fall through to MV or raw-table scan]
Reviews (1): Last reviewed commit: "Merge branch 'main' into fix/text-index-..." | Re-trigger Greptile
|
Please stop spinning up agents to pick up issues unless you really understand what the issue is about. |
@wrn14897, I understand the concern. I did use AI assistance while working on this PR, but I didn’t blindly pick up the issue. I went through #2880, the existing I’m confident in the approach, but if you believe #2930 is technically incorrect, I’m happy to investigate and fix it. I’d just appreciate pointing me to the specific part of the implementation that is wrong so I can understand the concern and address it properly. |
Summary
Fixes #2880 — text-index metadata queries fail with
BAD_ARGUMENTS(There is no index with name ...) when a source's table isDistributed.Root cause
mergeTreeTextIndex(...)andsystem.partsonly understand MergeTree-family tables — aDistributedtable has neither the index nor any local parts. Index discovery already resolvesDistributed→ local table (viagetSkipIndices/getDistributedTableArgs), but index reads inpackages/common-utils/src/core/metadata.tswere passing the Distributed table name straight through in four places:getMapKeys— key-index branchgetMapKeys— kv-index branchgetMapTextIndexKeyValuesgetTextIndexKeyValuespartsOverlapFilteralso queriedsystem.partsusing the Distributed table name, which has no local parts, so even fixing the index name alone would have produced an empty (but not erroring) predicate.Because the error was only
console.warn-ed andgetMapKeysreturned[]on failure, this failed silently: noSpanAttributes/LogAttributeskeys in autocomplete or the field picker, and no filter values for columns routed to the text index — for any source backed by aDistributedtable (e.g.otel_traces/otel_logsin a standard multi-shard setup).Fix
resolveTextIndexTableRef()— resolves aDistributedtable to its underlying local table + cluster, reusing the samegetDistributedTableArgs/queryTableMetadatapatterngetSkipIndicesalready uses.mergeTreeTextIndexExpr()— builds themergeTreeTextIndex(...)table function expression, wrapping it incluster(...)when the caller resolved a Distributed table, so all shards are queried.mergeTreeTextIndex(...)andpartsOverlapFilter'ssystem.partslookup.getMapKeys's two text-indexcatchblocks no longerreturn []on failure — they now fall through to the MV / raw-table-scan tiers, so a transient text-index failure degrades gracefully instead of silently hiding all keys for that column (per the issue's proposed fix).Before / after
Before (against a
Distributedsource):→
Code: 36. DB::Exception: There is no index with name 'idx_span_attr_items'. (BAD_ARGUMENTS)After:
Testing
New regression tests in
metadata.test.ts:getMapKeysresolves aDistributedtable to its local table +cluster()for bothmergeTreeTextIndexandsystem.parts, and never leaks the Distributed table name into query params.getMapKeysfalls through to the raw-table scan (not[]) when the text-index query throwsBAD_ARGUMENTS.getAllKeyValuesroutes a Distributed-sourceTraceIdlookup throughgetTextIndexKeyValuesusing the resolved local table + cluster.Full
metadata.test.tssuite passes (112/112, no regressions).Changeset
Included —
patchon@hyperdx/common-utils.Related
Closes #2880