Repository navigation
Description
Is your feature request related to a problem?
The SQL/PPL plugin currently only supports querying Lucene-backed OpenSearch indices. A new Analytics engine introduces Parquet as an alternate storage format with an embedded query engine (DataFusion) for log analytics workloads. Users expect to query Parquet-backed indices using the same _plugins/_sql and _plugins/_ppl REST endpoints with the same SQL/PPL language support, but the current plugin has no integration path to route queries to the Analytics engine for execution.
Technical Requirements
- UX consistency: Same REST endpoints, response format, error messages, and explain output for both Lucene and non-Lucene queries
- Engineering complexity: Minimal changes to existing SQL/PPL plugin code; reuse existing parsing, formatting, and metrics infrastructure
- Plugin coupling: Clean API boundary between SQL/PPL plugin and Analytics engine; each can evolve independently
- Performance: No unnecessary performance overhead or data copying in the query handoff path
- Resource management: Query size limits, circuit breakers, and timeouts enforced on the unified path
- Monitoring/Observability: Request/failure metrics, query profiling, and logging for the unified path consistent with existing paths
- Security: Index-level authorization during routing; security context propagated to execution thread
- Testability: End-to-end integration tests with the real Analytics engine plugin loaded in the test cluster
- Long-term alignment: Architecture supports future ANSI SQL, cross-engine JOINs, and additional storage engines
What solution would you like?
High-level Design
The SQL/PPL plugin integrates with the Analytics engine through a new Unified Query Pipeline: the plugin handles query routing, parsing, and generating engine-agnostic Calcite RelNode logical plans, then hands them off to the Analytics engine for physical optimization, distributed planning, and execution.
Here is the high-level workflow:
RestSqlAction/RestPPLQueryActionroutes queries targeting non-Lucene indices to a newRestUnifiedQueryAction; Lucene queries fall through to the existing V2/V3 path unchanged.RestUnifiedQueryActionbuilds a Calcite schema from cluster state via the Analytics engine'sOpenSearchSchemaBuilder(standard SQL types, no UDTs).UnifiedQueryPlanner.plan()parses the query (Calcite native SQL parser or PPL V3 Calcite path) and generates a logicalRelNode.AnalyticsExecutionEnginepasses theRelNodedirectly to the Analytics engine'sQueryPlanExecutor.execute()— no serialization needed (shared classloader via extendedPlugins).- Results (
Iterable<Object[]>) are converted toExprValueand formatted as JDBC JSON via the existingJdbcResponseFormatter.
Component Responsibilities
| SQL/PPL Plugin | Analytics Engine | |
|---|---|---|
| Query routing | Detect non-Lucene indices by routing rules from Analytics engine and route to unified pipeline | Provide index settings-based routing rules |
| Parsing | Parse SQL (Calcite native parser) and PPL (ANTLR → CalciteRelNodeVisitor) into RelNode | — |
| Logical optimization | Apply language-specific HepPlanner rewrites (PPL dedup/stats simplification) | — |
| Physical optimization | — | Pushdown optimization by rules registered in TableScan.register() |
| Distributed query planning | — | Fragment the plan across data nodes, manage distributed execution and result aggregation |
| Schema | Pass schema to UnifiedQueryContext for planning |
Provide OpenSearchSchemaBuilder to build Calcite SchemaPlus from cluster state |
| Execution | Hand off RelNode to QueryPlanExecutor |
Execute plan via back-end engines, return Iterable<Object[]> |
| Exception handling | Catch and return error responses | Fail-fast and throw exceptions for unsupported operations |
| Response formatting | Convert results to default format via existing formatter | — |
| Observability | Metrics, logging, profiling for unified path | — |
API Contract
- SQL/PPL → Analytics engine:
RelNodelogical plan with standard Calcite types and PPL/SQL UDF nodes (e.g., match, match_phrase) - Analytics engine → SQL/PPL:
SchemaBuilderfor schema provisioning,QueryPlanExecutor.execute(RelNode, context)returning Iterable<Object[]>, routing rules for index detection
What alternatives have you considered?
- Option A (Query Delegation): Forward raw SQL/PPL query text to the Analytics engine via transport action. Simplest coupling, but bypasses the SQL/PPL plugin entirely and does not cleanly separate the query language frontend from the execution backend.
- Option C (Calcite Schema Adapter): Register a Parquet Calcite adapter in the existing PPL V3 pipeline. Tightest coupling with the current codebase — inherits the most infrastructure, but carries compatibility risk as the Analytics engine. The SQL execution path would still need a separate integration, since the current pipeline is PPL-only.
Option B (Unified Query Pipeline) was selected for its clean separation of query language frontend (SQL/PPL plugin) and execution backend (Analytics engine), reuse of existing plugin infrastructure, and a single integration path that serves both SQL and PPL.
Do you have any additional context?
- Analytics engine: https://github.com/opensearch-project/OpenSearch/tree/main/sandbox/plugins/analytics-engine
- PoC branch: [PoC] SQL/PPL support for analytics engine dai-chen/sql-1#10
- Pending alignment:
- API contract finalization
- Plugin integration mechanism (extendedPlugins vs transport action)
- SQL search function support scope
- Integration-ready Analytics engine build
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNew
Activity
ahkcs commentedon Apr 7, 2026
Follow-up Items from Recent PRs
1. SQL Profiling Support
Currently SQL analytics path hardcodes
profiling=falseandExplainMode.STANDARDsinceSQLQueryRequestdoesn't have these fields yet. PPL supports profiling viaPPLQueryRequest.profile()and explain modes viaPPLQueryRequest.mode(). We should add equivalent support for SQL.Ref: #5317 (comment)
2. EXPLAIN PLAN FOR Statement Support
Calcite SQL supports
EXPLAIN PLAN FORas a standard SQL statement (ref: Calcite SQL reference). Currently it fails because:SqlToRelConverter.convertQueryRecursive()throwsAssertionError("not a query")forSqlExplainnodes — Calcite treats it as a meta-statement handled at the JDBC layer, not at theSqlToRelConverterlevelSqlTableNameExtractordoesn't unwrapSqlExplainto find the table name for routingTo support it, we'd need to detect
SqlExplaininCalciteNativeStrategy.plan(), unwrap the inner query, plan it, and return the plan as a formatted result. Note that the resulting plan would be identical to what/_plugins/_sql/_explainalready returns — the only difference is the response format (result row vs JSON explain response).Ref: #5317 (comment)
3. Context Classloader Approach Impact
The patched Calcite (CALCITE-3745) uses
Thread.currentThread().getContextClassLoader()for Janino compilation. We set this inQueryService.executeWithCalcite(),QueryService.explainWithCalcite(), andCalciteScriptEngine.compile(). However, any new code path that triggers Janino without the wrapper would silently fail (e.g., constant folding falls back to unreduced expressions). This is a fragile pattern — developers adding new Calcite features could hit crypticCompileExceptionwithout knowing they need the wrapper. Long-term, Option D (transport actions) would eliminate this concern entirely.Ref: #5302 (review)
4. context.measure() for Analytics Path
The analytics execution path doesn't use
context.measure()for profiling metrics. The PPL unified path records ANALYZE/EXECUTE/FORMAT metrics, but the SQL analytics path currently skips this. Should align profiling instrumentation across both paths.Ref: #5285 (comment)
ahkcs commentedon Apr 8, 2026
5. Optional Analytics-Engine Dependency with Guice Provider
Marc suggested making analytics-engine an optional dependency of the SQL plugin using a provider/Guice injection pattern instead of a hard
extendedPluginsdependency. OpenSearch supportsoptional=truesyntax (analytics-engine;optional=true), which allows the SQL plugin to start without analytics-engine installed.The approach: analytics-engine registers its components (executor, schema, rules) via Guice bindings at startup. The SQL plugin discovers them at runtime through the node-level injector. If analytics-engine is not installed, the SQL plugin skips the analytics path gracefully.
This decouples the SQL plugin from concrete analytics-engine classes — the SQL plugin only depends on interfaces, not implementations.
Ref: #5302 (comment)
ahkcs commentedon May 12, 2026
3/5 completed
Ref:
#5302
opensearch-project/OpenSearch#21501
opensearch-project/OpenSearch#21549
#5430
#5426
[Analytics-Engine] Decorrelate RexSubQuery before marking in PlannerI…
[Analytics-Engine] Decorrelate RexSubQuery before marking in PlannerI…