Skip to content

Commit 1f8ee7c

Browse files
committed
Use queryType to branch index extraction instead of instanceof
Signed-off-by: Kai Huang <ahkcs@amazon.com>
1 parent 5c25195 commit 1f8ee7c

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

plugin/src/main/java/org/opensearch/sql/plugin/rest/RestUnifiedQueryAction.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public boolean isAnalyticsIndex(String query, QueryType queryType) {
8181
return false;
8282
}
8383
try (UnifiedQueryContext context = buildParsingContext(queryType)) {
84-
String indexName = extractIndexName(query, context);
84+
String indexName = extractIndexName(query, queryType, context);
8585
if (indexName == null) {
8686
return false;
8787
}
@@ -182,15 +182,14 @@ private UnifiedQueryContext buildContext(QueryType queryType, boolean profiling)
182182
* Extract the source index name by parsing the query and visiting the AST to find the Relation
183183
* node. Uses the context's parser which supports both PPL and SQL.
184184
*/
185-
private static String extractIndexName(String query, UnifiedQueryContext context) {
186-
Object parseResult = context.getParser().parse(query);
187-
if (parseResult instanceof UnresolvedPlan unresolvedPlan) {
185+
private static String extractIndexName(
186+
String query, QueryType queryType, UnifiedQueryContext context) {
187+
if (queryType == QueryType.PPL) {
188+
UnresolvedPlan unresolvedPlan = (UnresolvedPlan) context.getParser().parse(query);
188189
return unresolvedPlan.accept(new IndexNameExtractor(), null);
189190
}
190-
if (parseResult instanceof SqlNode sqlNode) {
191-
return extractTableNameFromSqlNode(sqlNode);
192-
}
193-
return null;
191+
SqlNode sqlNode = (SqlNode) context.getParser().parse(query);
192+
return extractTableNameFromSqlNode(sqlNode);
194193
}
195194

196195
/**

0 commit comments

Comments
 (0)