Fix SQL query routing to analytics engine#5453
Conversation
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit e5c29fd.
The table above displays the top 10 most important findings. Pull Requests Author(s): Please update your Pull Request according to the report above. Repository Maintainer(s): You can Thanks. |
PR Reviewer Guide 🔍(Review updated until commit e5c29fd)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to e5c29fd
Previous suggestionsSuggestions up to commit b70eeb0
|
…dices
The SQL path in RestUnifiedQueryAction.isAnalyticsIndex() was failing to
route queries to the analytics engine because:
1. extractIndexName() used context.getParser() which returns SqlV2QueryParser
(producing UnresolvedPlan), but the SQL branch expected a Calcite SqlNode.
The V2 parser also treats 'score' as a reserved keyword, causing parse
failures on common column names.
2. SqlTableNameExtractor did not handle SqlOrderBy, which Calcite wraps
around SELECT...LIMIT queries.
3. Calcite's default parser uppercases unquoted identifiers, but index
names in OpenSearch are lowercase.
Fix:
- Use SqlParser.create(query).parseQuery() (Calcite parser) for the SQL
branch, which correctly returns SqlNode and handles standard SQL without
reserved-word conflicts.
- Add SqlOrderBy handling in SqlTableNameExtractor to unwrap LIMIT queries.
- Lowercase the extracted table name before cluster state lookup.
Signed-off-by: Finn Carroll <carrofin@amazon.com>
b70eeb0 to
e5c29fd
Compare
|
Persistent review updated to latest commit e5c29fd |
|
Fix in: #5456 |
Description
SQL plugin appears to be falling back to the V2 engine instead of using the analytics engine due to the recent move to V2. It seems like when we are making our routing decision to see if we can use analytics engine we fetch a parser from the context such that we can parse the raw query and inspect the index (to determine if it's analytics plugin compatible).
However, this no longer returns a
SqlNodeas we are now using theSqlV2QueryParser. This causes a casting exception to be thrown and caught upstream, where we fallback to the regular SQL V2 engine.Added a test which fails on main but passes with this PR.
Related Issues
N/A
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.