fix(chsql): synthesize TimeUnix on instant-mode VectorSetOp derived arms#707
Merged
Conversation
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
PR #706 introduced a per-arm canonical 4-column projection (
SELECT MetricName, Attributes, TimeUnix, Value FROM (<arm>)) on everyVectorSetOparm so a UNION ALL between matrix-shape and canonical-shape arms unifies positional column types. That fix covered the matrix-mode path (range-step) but the same canonical-shape SELECT trips CH 24.x in instant mode (no step):or, on a different folding,
The inner SELECT for an instant-mode
RangeWindow/Aggregate/MetricsAggregate/MetricsHistogramOverTimeonly exposes(group-keys..., <ValueColumn>)— noTimeUnixcolumn to reference. PR #701's newotelcol-observabilitydashboard surfaced the residue on the "Send failures (5m)" + "Processor refusals (5m)" stat panels (instant/api/v1/query, notquery_range):both 502 the cerberus engine; Grafana surfaces them to the browser as a 400, and the panel-kiosk spec catches the resulting console-error trail.
Fix
vectorSetOpCanonicalArmFragnow mirrorswrapWithSampleProjection's instant branch: for derived-shape arms in instant mode, synthesizeTimeUnixas(now64(9) - toIntervalNanosecond(5_000_000_000))instead of referencing it as a column. Matrix-mode arms (OuterRange > 0) still referenceTimeUnixby name becauseemitWindowedArrayPairsMatrix/emitWindowedArrayMatrixalready aliasanchor_ts AS TimeUnixon the outer SELECT.The matrix path is unchanged — covered by the existing
binary_or_increase_range_canonicalises_arms.txtarfixture. The newbinary_or_increase_instant_canonicalises_arms.txtarfixture pins the instant-mode path so this residue can't silently regress.Live verification
Against the rebuilt compose stack (PR #701 dashboards applied locally), both failing queries return HTTP 200 with the fix:
Test plan
go test ./internal/promql/ -run TestLower— passes (new fixture goldens are in)go test ./internal/chsql/...— passescompose-smoke(panel-kiosk) — must turn green to unblock PR feat(quickstart): rich ClickHouse / host / otelcol observability via OTel collector #701🤖 Generated with Claude Code