Skip to content

feat(calcite): fix visitor issues for V2 SQL AST integration#25

Draft
dai-chen wants to merge 1 commit into
mainfrom
fix/calcite-visitor-issues
Draft

feat(calcite): fix visitor issues for V2 SQL AST integration#25
dai-chen wants to merge 1 commit into
mainfrom
fix/calcite-visitor-issues

Conversation

@dai-chen

Copy link
Copy Markdown
Owner

Fix four CalciteRelNodeVisitor/RexNodeVisitor gaps surfaced when routing the V2 SQL AST through the unified query path:

  • Add Alias case in project expansion: SQL SELECT COUNT(*) AS cnt ... GROUP BY ... previously crashed with "Unexpected expression type: Alias". Reference already-computed aggregates by schema name instead of re-analyzing.
  • Add visitLimit override for SQL LIMIT/OFFSET. PPL is unaffected (uses the Head node).
  • Fix bucketNullable NPE when SQL GROUP BY produces an Aggregation without BUCKET_NULLABLE arg. Use getOrDefault(..., Literal.TRUE) to match Analyzer.java.
  • Rewrite visitWindowFunction to handle AggregateFunction (V2 SQL) + DISTINCT + OVER ORDER BY (previously hardcoded to List.of()). Register ROW_NUMBER/RANK/DENSE_RANK in WINDOW_FUNC_MAPPING and bypass aggregate validation for these pure window functions. Add a makeOver overload with a distinct parameter (old signature delegates with false to preserve PPL behavior).

Add seven tests in UnifiedQueryPlannerSqlTest, one per fix. Verified zero PPL regressions across 2300+ existing tests.

Description

[Describe what this change achieves]

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@dai-chen dai-chen force-pushed the fix/calcite-visitor-issues branch from ebf6089 to 3acba66 Compare May 16, 2026 05:53
Fix CalciteRelNodeVisitor/RexNodeVisitor gaps surfaced when routing the
V2 SQL AST through the unified query path:

- expandProjectFields: add Alias case so already-computed aggregates
  are referenced by schema name (was throwing "Unexpected expression
  type: Alias").
- visitLimit: new override for SQL LIMIT/OFFSET. PPL is unaffected
  (uses Head node).
- visitAggregation: fix BUCKET_NULLABLE NPE when SQL GROUP BY produces
  an Aggregation without that arg. Use getOrDefault(..., Literal.TRUE).
- visitRelationSubquery: new override for derived tables in FROM
  (SELECT ... FROM (SELECT ...) AS t).
- visitValues: handle (a) dual-table [[]] for SELECT without FROM and
  (b) non-empty inline VALUES via relBuilder.values(fieldNames, flat).
- visitWindowFunction: handle AggregateFunction (V2 SQL) + DISTINCT +
  OVER ORDER BY (was hardcoded to List.of()). Register
  ROW_NUMBER/RANK/DENSE_RANK in WINDOW_FUNC_MAPPING and bypass
  aggregate validation for these pure window functions. Add a makeOver
  overload with a distinct parameter (old signature delegates with
  false to preserve PPL behavior).

Add nine tests in UnifiedQueryPlannerSqlTest, one per fix. Verified
zero PPL regressions across 2300+ existing tests.

Signed-off-by: Chen Dai <daichen@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant