Skip to content

Commit 80233de

Browse files
committed
fix(plugin): keep SHOW/DESCRIBE on default pipeline under cluster composite
When cluster.pluggable.dataformat=composite, isAnalyticsIndex routed every query to the analytics engine, which cannot serve the system catalog (*_ODFE_SYS_TABLE) that SHOW/DESCRIBE resolve. Detect system-catalog queries and keep them on the default pipeline while data queries continue to the analytics engine. Signed-off-by: Chen Dai <daichen@amazon.com>
1 parent f861d02 commit 80233de

2 files changed

Lines changed: 68 additions & 3 deletions

File tree

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.opensearch.sql.protocol.response.QueryResult;
4141
import org.opensearch.sql.protocol.response.format.ResponseFormatter;
4242
import org.opensearch.sql.protocol.response.format.SimpleJsonResponseFormatter;
43+
import org.opensearch.sql.utils.SystemIndexUtils;
4344
import org.opensearch.transport.client.node.NodeClient;
4445

4546
/**
@@ -95,7 +96,17 @@ public boolean isAnalyticsIndex(String query, QueryType queryType) {
9596
.equals(
9697
IndicesService.CLUSTER_PLUGGABLE_DATAFORMAT_VALUE_SETTING.get(
9798
clusterService.getSettings()))) {
98-
return true;
99+
// Analytics engine can't serve system catalog; SHOW/DESCRIBE fall back to default pipeline
100+
try (UnifiedQueryContext context = buildParsingContext(queryType)) {
101+
boolean systemCatalog =
102+
extractIndexName(query, queryType, context)
103+
.map(SystemIndexUtils::isSystemIndex)
104+
.orElse(false);
105+
return !systemCatalog;
106+
} catch (Exception e) {
107+
// Let the analytics engine re-parse and surface the syntax error
108+
return true;
109+
}
99110
}
100111
try (UnifiedQueryContext context = buildParsingContext(queryType)) {
101112
return extractIndexName(query, queryType, context)

plugin/src/test/java/org/opensearch/sql/plugin/rest/RestUnifiedQueryActionTest.java

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.opensearch.cluster.service.ClusterService;
2222
import org.opensearch.common.settings.Settings;
2323
import org.opensearch.index.IndexSettings;
24+
import org.opensearch.indices.IndicesService;
2425
import org.opensearch.sql.executor.QueryType;
2526
import org.opensearch.transport.client.node.NodeClient;
2627

@@ -142,7 +143,7 @@ public void nullAndEmptyQueriesRouteToLucene() {
142143
}
143144

144145
@Test
145-
public void showStatementRoutesToLucene() {
146+
public void showStatementNotRoutedToAnalyticsEngine() {
146147
registerIndex(
147148
"parquet_logs",
148149
Settings.builder()
@@ -154,7 +155,7 @@ public void showStatementRoutesToLucene() {
154155
}
155156

156157
@Test
157-
public void describeStatementRoutesToLucene() {
158+
public void describeStatementNotRoutedToAnalyticsEngine() {
158159
registerIndex(
159160
"parquet_logs",
160161
Settings.builder()
@@ -165,6 +166,59 @@ public void describeStatementRoutesToLucene() {
165166
assertFalse(action.isAnalyticsIndex("DESCRIBE TABLES LIKE 'parquet_logs'", QueryType.SQL));
166167
}
167168

169+
@Test
170+
public void showStatementNotRoutedToAnalyticsEngineUnderClusterComposite() {
171+
enableClusterComposite();
172+
assertFalse(action.isAnalyticsIndex("SHOW TABLES LIKE 'parquet_logs'", QueryType.SQL));
173+
}
174+
175+
@Test
176+
public void describeStatementNotRoutedToAnalyticsEngineUnderClusterComposite() {
177+
enableClusterComposite();
178+
assertFalse(action.isAnalyticsIndex("DESCRIBE TABLES LIKE 'parquet_logs'", QueryType.SQL));
179+
}
180+
181+
@Test
182+
public void dataQueryStillRoutesToAnalyticsUnderClusterComposite() {
183+
enableClusterComposite();
184+
assertTrue(action.isAnalyticsIndex("SELECT * FROM parquet_logs", QueryType.SQL));
185+
}
186+
187+
@Test
188+
public void unparseableQueryRoutesToAnalyticsUnderClusterComposite() {
189+
enableClusterComposite();
190+
// malformed -> AE re-parses & reports
191+
assertTrue(action.isAnalyticsIndex("SELECT FROM WHERE", QueryType.SQL));
192+
}
193+
194+
@Test
195+
public void pplDescribeNotRoutedToAnalyticsEngineUnderClusterComposite() {
196+
enableClusterComposite();
197+
assertFalse(action.isAnalyticsIndex("describe parquet_logs", QueryType.PPL));
198+
}
199+
200+
@Test
201+
public void pplDataQueryStillRoutesToAnalyticsUnderClusterComposite() {
202+
enableClusterComposite();
203+
assertTrue(action.isAnalyticsIndex("source = parquet_logs | fields ts", QueryType.PPL));
204+
}
205+
206+
@Test
207+
public void pplUnparseableQueryRoutesToAnalyticsUnderClusterComposite() {
208+
enableClusterComposite();
209+
// malformed -> AE re-parses & reports
210+
assertTrue(action.isAnalyticsIndex("source = parquet_logs | | fields ts", QueryType.PPL));
211+
}
212+
213+
private void enableClusterComposite() {
214+
when(clusterService.getSettings())
215+
.thenReturn(
216+
Settings.builder()
217+
.put(
218+
IndicesService.CLUSTER_PLUGGABLE_DATAFORMAT_VALUE_SETTING.getKey(), "composite")
219+
.build());
220+
}
221+
168222
private void registerIndex(String name, Settings settings) {
169223
IndexMetadata indexMetadata = mock(IndexMetadata.class);
170224
when(indexMetadata.getSettings()).thenReturn(settings);

0 commit comments

Comments
 (0)