Skip to content

[FEATURE] SQL query support for Analytics engine integration #5248

Open

Description

@dai-chen

Is your feature request related to a problem?

The Analytics engine integration requires ANSI SQL support to enable SQL queries against non-Lucene indices. However, the unified query API currently only supports PPL V3. The PPL integration (tracked in the sibling issue) establishes the query routing, execution engine, and response formatting infrastructure — this issue covers the additional work needed for SQL support.

Technical requirements:

  • ANSI SQL queries against non-Lucene indices return correct results through _plugins/_sql endpoint
  • SQL explain API (_plugins/_sql/_explain) returns the logical plan
  • OpenSearch full-text search functions (match, match_phrase, query_string) available in ANSI SQL syntax
  • Existing V2 SQL queries are unaffected (backward compatible, ANSI SQL is opt-in)
  • Same response format, error handling, and observability as the PPL unified path

What solution would you like?

Unified query API:

  1. Enable Calcite SQL in unified query API: Add the Calcite native SQL parser path (SqlParser → SqlValidator → SqlToRelConverter → RelNode) in UnifiedQueryPlanner with proper SQL conformance, case sensitivity, and identifier handling
  2. Register full-text search functions: Register search functions (match, match_phrase, query_string) with same signatures and return types

SQL plugin:

  1. Integrate with SQL REST endpoint: Add ANSI SQL mode routing in RestSqlAction (via mode parameter or auto-detection) through the unified query pipeline established by the PPL issue, with explain support and backward compatibility for existing V2 SQL queries.
  2. Integration tests: End-to-end ITs verifying ANSI SQL query, explain, full-text search functions, response format, and breaking changes in existing V2 SQL queries.What alternatives have you considered?

See parent issue #5246 for the design comparison of Option A (Query Delegation), Option B (Unified Query Pipeline), and Option C (Calcite Schema Adapter).

Do you have any additional context?

  • PoC PR: dai-chen/sql-1#10 — demonstrates ANSI SQL RelNode generation via Calcite's native parser in UnifiedQueryPlanner
  • Depends on PPL Analytics engine integration (sibling issue) for query routing, execution engine, and response formatting infrastructure

Activity

  1. added
    enhancement
    on Mar 18, 2026
  2. self-assigned this
    on Mar 23, 2026
  3. added
    Meta
    and removed on Mar 26, 2026
  4. dai-chen commented on Mar 30, 2026

    @dai-chen
    CollaboratorAuthor

    Unified Query API — SQL Gap Analysis Report (Consolidated)

    Date: 2026-03-30
    Branch: https://github.com/dai-chen/sql-1/tree/poc/gap-analysis-on-formal
    Scope: All SQL IT tests — V2 (org.opensearch.sql.sql.*IT, 50 classes) + Legacy (org.opensearch.sql.legacy.*IT, 39 classes) — 807 queries
    Pipeline: UnifiedQueryPlanner (Calcite native SQL parser) → UnifiedQueryCompiler → PreparedStatement.executeQuery()

    Consolidates the Mar 24 baseline (exception-based failures) and Mar 25 update (added result-mismatch detection).


    Moved to #5346 (comment).

  5. penghuo commented on Apr 1, 2026

    @penghuo
    Collaborator

    Intentionally not carrying forward

    All of them are bugs in V2, right?

  6. 2 remaining items

  7. dai-chen commented on May 19, 2026

    @dai-chen
    CollaboratorAuthor

    Here is the gap analysis report based on the new SQL pipeline (SQL V2 parser + CalciteRelNodeVisitor): https://github.com/dai-chen/sql-1/blob/sql-v2-calcite-gap-analysis/docs/report/sql-v2-calcite-gap-analysis.md

    After all the PR merged above, below is the remaining gaps:

    Major Gaps

    # Cat Gap Effort Failures Notes
    A3 / B5 A + B PartiQL nested syntax (SELECT * FROM nested_type e, e.message m) + NESTED function L ~40 A3: extend FROM grammar for comma-join + nested path. B5: NESTED function support.
    B3 B Pagination unsupported (fetchSize/cursor) L 40 visitPaginate and visitFetchCursor throw unsupported. Includes B17 (fallback tests).
    B4 B Table function unsupported (vectorSearch) L 26 visitTableFunction is a stub. Implement KNN scan translation.
    B9 (partial) B RANK / DENSE_RANK S ~6 Deferred — overlaps with PPL issue #5168, unresolved ORDER BY semantics. ROW_NUMBER fixed.

    Minor Gaps

    # Cat Gap Effort Failures Notes
    A2 A SHOW/DESCRIBE with unquoted hyphenated identifiers S 11 tableFilter only accepts STRING_LITERAL. Extend to accept ID.
    A4 A PERCENTILES / STATS / EXTENDED_STATS M 7 Tokens exist in lexer but unused in parser. PERCENTILE (singular) is supported.
    A5 A Legacy method syntax field=FUNC('arg') M 5 Only MATCH_QUERY/MATCHPHRASE have altSingleFieldRelevanceFunction. Extend grammar.
    A6/B10 A Index names with dots S 3 Grammar splits on dots; 01 fails as ident. Workaround: backtick quoting.
    A8 A Qualified wildcard alias.* S 2 Add qualifiedStar rule to selectElement.
    A9 A Multi-table FROM (comma-join, non-nested) S 1 Allow comma-separated table list in FROM.
    A10 A date_histogram S 1 Add date_histogram to function name tokens.
    A11 A Index/type syntax /type S 1 Add optional /type suffix to table reference rule. (Already deprecated in OS)
    A12 A UNION / INTERSECT / MINUS L 0 (excluded) Hidden gap — tests excluded. Add set-operation rules + AST nodes.
    B14 (partial) B IFNULL with NULL literal S ~2 Edge case — IFNULL(null, x) fails type resolution. ISNULL fixed.
    B15 B Explain format mismatch S 3 Calcite explain JSON differs from V2. Update test or add V2-compatible format.
    B18 B typeof type name mismatch S 1 Calcite returns BIGINT; V2 returns LONG. Map back in typeof() impl.
    B20 B SCORE / SCORE_QUERY / SCOREQUERY M TBD Need implementation in CalciteRelNodeVisitor. visitScoreFunction throws unconditionally.
    B21 B HIGHLIGHT M TBD Need implementation in CalciteRelNodeVisitor. visitHighlightFunction throws unconditionally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

MetaSQLenhancement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions