fix(chsql/vector_set_op): canonicalise UNION arms so 'or' over matrix RangeWindow doesn't fail at CH#706
Merged
Conversation
…type error doesn't fire PromQL `or` chains like `sum(increase(A[5m]) or increase(B[5m]) or increase(C[5m]))` (PR #701's otelcol-observability dashboard) failed at CH with `code: 386 — There is no supertype for types String, Map(LowCardinality(String), String)`. `A or B or C` parses as `(A or B) or C`; the inner `(A or B)` arm projected the canonical 4 columns (`MetricName, Attributes, TimeUnix, Value` — String, Map, …), while the matrix-shape `RangeWindow` for `C` exposed `Attributes, anchor_ts, TimeUnix, Value` (Map first, no MetricName because `increase` drops `__name__`). The UNION ALL then asked CH to unify String + Map at column position 0. Every VectorSetOp arm now projects the canonical 4-column shape explicitly, synthesising `'' AS MetricName` for derived-shape arms (RangeWindow / Aggregate / MetricsAggregate / MetricsHistogramOverTime / a Project on top of one of those) — mirroring `wrapWithSampleProjection`'s derived-shape branch. Positional column unification across the UNION arms now always sees matching types. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
4 tasks
tsouza
added a commit
that referenced
this pull request
May 22, 2026
…rms (#707) PR #706's vectorSetOpCanonicalArmFrag projects every VectorSetOp arm as SELECT MetricName, Attributes, TimeUnix, Value but the inner SELECT for an instant-mode RangeWindow / Aggregate / MetricsAggregate / MetricsHistogramOverTime only exposes (group-keys..., Value). The bare TimeUnix column reference then fails at CH 24.x with "Unknown expression identifier 'TimeUnix'" / "Resolve identifier 'TimeUnix' from parent scope only supported for constants and CTE". PR #701's new otelcol-observability dashboard surfaced the residue on the "Send failures (5m)" + "Processor refusals (5m)" stat panels, which Grafana renders via instant /api/v1/query (no step). Both fire as sum(increase(otelcol_..._log_records[5m]) or increase(otelcol_..._metric_points[5m]) or increase(otelcol_..._spans[5m])) and consistently 502 the cerberus engine (browser shows 400). Mirror the wrapWithSampleProjection instant branch: synthesize TimeUnix as (now64(9) - toIntervalNanosecond(5_000_000_000)) for derived-shape arms in instant mode. Matrix-mode arms (OuterRange > 0) still reference TimeUnix by name because emitWindowedArrayPairsMatrix already aliases anchor_ts AS TimeUnix on the outer SELECT — covered by the existing binary_or_increase_range_canonicalises_arms fixture; the new binary_or_increase_instant_canonicalises_arms fixture pins the instant-mode path. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This was referenced May 22, 2026
Merged
tsouza
added a commit
that referenced
this pull request
May 22, 2026
… (#720) PR #706 / #707 added per-arm canonical-shape projection + instant-mode TimeUnix synthesis to fix SQL emission errors on nested PromQL or-chains. The 2026-05-22 dirty-fixes audit asked whether these helpers became unreachable after PR #710 (TableFor -> TablesFor for unsuffixed OTel sums) and PR #716 (extended to _count/_sum suffixes). Reachability test on the post-#710/#716 tree lowered the PR #706 failing-shape query and recorded vectorSetOpCanonicalArmFrag invocations on both arms with derived=true and the synthesised anchor branch taken. The workarounds remain on the live emit path because #710/#716 fix which Scan tables get resolved (orthogonal to UNION ALL column-type unification + missing-identifier-on-derived-inner). Adds a NOTE block to vectorSetOpCanonicalArmFrag's docstring documenting the audit so a future reviewer does not delete the helpers on the assumption they were per-shape patches for the gauge/sum routing bug.
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.
Summary
orqueries on the newotelcol-observabilitydashboard returning 502s withcode: 386, message: There is no supertype for types String, Map(LowCardinality(String), String) because some of them are Maps and some of them are not.A or B or Cparses as(A or B) or C. The inner(A or B)VectorSetOrarm projected the canonical 4-column shape (MetricName, Attributes, TimeUnix, Value— String, Map, DateTime64, Float64); the outer right armCwas a matrix-shapeRangeWindowwhoseSELECT *exposedAttributes, anchor_ts, TimeUnix, Value(Map first, noMetricNamebecauseincreasedrops__name__). TheUNION ALLthen asked CH to unify String + Map at column position 0.internal/chsql/vector_set_op.go: everyVectorSetOparm now explicitly projects the canonical 4-column shape via a newvectorSetOpCanonicalArmFraghelper, synthesising'' AS MetricNamefor derived-shape arms (RangeWindow/Aggregate/MetricsAggregate/MetricsHistogramOverTime/ aProjecton top of one of those) — mirroringwrapWithSampleProjection's derived-shape branch ininternal/api/prom/handler.go. Positional column unification across the UNION arms now always sees matching column types.test/spec/promql/binary_or_increase_range_canonicalises_arms.txtarpins the failing 3-armsum(increase(...)[5m] or increase(...)[5m] or increase(...)[5m])shape withrange_step: 1m; the chplan shows the nestedVectorSetOpover matrixRangeWindowarms that the bug surfaced.binary_{and,or,unless}{,_ignoring,_on}.txtarSQL goldens regenerated for the canonical-arm wrap; behaviour is unchanged (the canonical-shape arms already exposedMetricName, the added projection is a passthrough CH's optimizer fuses).Test plan
go test ./internal/promql/ ./internal/chsql/ ./internal/api/prom/ ./internal/api/loki/ ./internal/api/tempo/ ./internal/optimizer/— 2325 tests pass.binary_or_increase_range_canonicalises_arms.txtarpins the regressing shape and its post-fix SQL.otelcol-observabilitydashboard sweep clears (PR-side CI rerun).🤖 Generated with Claude Code