Sql v2 calcite gap analysis#21
Draft
dai-chen wants to merge 11 commits into
Draft
Conversation
Bridge SQL V2 parser output to PPL V3's CalciteRelNodeVisitor path: - QueryService.shouldUseCalcite() accepts QueryType.SQL - CalciteRelNodeVisitor handles Alias expression in project list - OpenSearchExecutionEngine returns Cursor.None instead of null - Disable REST-level V2-to-legacy fallback to expose all gaps - Enable Calcite + disallow fallback in SQL IT test base class These are temporary changes for gap analysis, not production-ready.
Comprehensive gap analysis for Mustang SQL design decision: - 572/964 tests pass (59.3%) with V2 AST routed through Calcite - Category A: 13 grammar gaps (JOINs, IN/EXISTS, UNION, etc.) - Category B: 20 visitor gaps (ArgumentMap NPE, AggFunc cast, etc.) - Quick wins identified: ~158 tests unlockable with S-effort fixes - Verified against grammar, AST builder, and visitor source code
- Null-check BUCKET_NULLABLE in visitAggregation (B1) - Handle AggregateFunction in visitWindowFunction (B2) - Add visitLimit override for SQL LIMIT clause (B8) - Add RANK/DENSE_RANK/ROW_NUMBER to WINDOW_FUNC_MAPPING (B9) - Fix table name resolution to pass single-element list (B10) - Register relevance function aliases: MATCH_QUERY, MATCHQUERY, etc (B7) - Register ISNULL, fix IFNULL to use ENHANCED_COALESCE (B14)
- Add joinClause and joinType rules to fromClause - Add UNION ALL / EXCEPT to selectStatement - Add IN subquery predicate alternative - Add EXISTS expression atom - Default AstBuilder throws SyntaxCheckException (preserves legacy fallback) - Add createExpressionBuilder() factory for subclass override - Make visitAstExpression protected for subclass access
…ISTS) Demonstrates the pattern: override AstBuilder in SQLService to build AST nodes for features gated in the default path. In production, this override moves to the unified query API's CustomVisitorStrategy. QueryService.shouldUseCalcite() temporarily accepts SQL for PoC testing. This flag is not for production — SQL should route through unified query API (RestUnifiedQueryAction) in the final integration.
…ias encoding - Pass window function sortList as orderKeys to PlanUtils.makeOver - Add RANK and DENSE_RANK cases to PlanUtils.makeOver switch - Add makeOver overload with distinct parameter for COUNT(DISTINCT) OVER - Bypass aggFunctionRegistry validation for pure window functions - Encode expression name + alias in Calcite field name for SQL queries - Decode alias in OpenSearchExecutionEngine response schema builder - Fix NPE in ANY-type lookup when alias is present
…dation for SQL - Add ThreadLocal<QueryType> to CalcitePlanContext with cleanup in finally - typeof() now uses getCurrentQueryType() instead of hardcoded PPL - SQL queries bypass strict PPL type validation for aggregation functions - Allows AVG on TIMESTAMP/DATE/TIME in SQL (Calcite handles coercion)
…ow mapping - Add WILDCARD_QUERY and WILDCARDQUERY to PPLFuncImpTable - Add wildcard_query UDF in PPLBuiltinOperators - Add percentile/percentile_approx to WINDOW_FUNC_MAPPING
For SQL queries, detect temporal-typed fields (UDT or standard datetime) passed to AVG and cast them to BIGINT before aggregation. This resolves the 'Error while preparing plan' failure where Calcite's AVG rejects non-numeric operands. Result type is numeric (not timestamp).
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.
Description
[Describe what this change achieves]
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
--signoffor-s.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.