6161import org .opensearch .sql .legacy .request .SqlRequestParam ;
6262import org .opensearch .sql .legacy .rewriter .matchtoterm .VerificationException ;
6363import org .opensearch .sql .legacy .utils .JsonPrettyFormatter ;
64- import org .opensearch .sql .legacy .utils .QueryDataAnonymizer ;
6564import org .opensearch .sql .sql .domain .SQLQueryRequest ;
6665import org .opensearch .transport .client .Client ;
6766import org .opensearch .transport .client .node .NodeClient ;
@@ -85,16 +84,12 @@ public class RestSqlAction extends BaseRestHandler {
8584 private final RestSQLQueryAction newSqlQueryHandler ;
8685
8786 /**
88- * Optional analytics router. If set, it's called before the normal SQL engine. Accepts the
89- * request and channel, returns {@code true} if it handled the request, {@code false} to fall
90- * through to normal SQL engine.
87+ * Analytics router. Called before the normal SQL engine. Accepts the request and channel, returns
88+ * {@code true} if it handled the request (analytics index) , {@code false} to fall through to
89+ * normal SQL engine.
9190 */
9291 private final BiFunction <SQLQueryRequest , RestChannel , Boolean > analyticsRouter ;
9392
94- public RestSqlAction (Settings settings , Injector injector ) {
95- this (settings , injector , null );
96- }
97-
9893 public RestSqlAction (
9994 Settings settings ,
10095 Injector injector ,
@@ -160,54 +155,30 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
160155
161156 // Route to analytics engine for non-Lucene (e.g., Parquet-backed) indices.
162157 // The router returns true and sends the response directly if it handled the request.
163- if (analyticsRouter != null ) {
164- final SQLQueryRequest finalRequest = newSqlRequest ;
165- return channel -> {
166- if (!analyticsRouter .apply (finalRequest , channel )) {
167- // Not an analytics query — delegate to normal SQL engine
168- try {
169- newSqlQueryHandler
170- .prepareRequest (
171- finalRequest ,
172- (ch , ex ) -> {
173- try {
174- Format fmt = SqlRequestParam .getFormat (request .params ());
175- QueryAction qa = explainRequest (client , sqlRequest , fmt );
176- executeSqlRequest (request , qa , client , ch );
177- } catch (Exception e ) {
178- handleException (ch , e );
179- }
180- },
181- this ::handleException )
182- .accept (channel );
183- } catch (Exception e ) {
184- handleException (channel , e );
185- }
158+ final SQLQueryRequest finalRequest = newSqlRequest ;
159+ return channel -> {
160+ if (!analyticsRouter .apply (finalRequest , channel )) {
161+ // Not an analytics query — delegate to normal SQL engine
162+ try {
163+ newSqlQueryHandler
164+ .prepareRequest (
165+ finalRequest ,
166+ (ch , ex ) -> {
167+ try {
168+ Format fmt = SqlRequestParam .getFormat (request .params ());
169+ QueryAction qa = explainRequest (client , sqlRequest , fmt );
170+ executeSqlRequest (request , qa , client , ch );
171+ } catch (Exception e ) {
172+ handleException (ch , e );
173+ }
174+ },
175+ this ::handleException )
176+ .accept (channel );
177+ } catch (Exception e ) {
178+ handleException (channel , e );
186179 }
187- };
188- }
189-
190- // Route request to new query engine if it's supported already
191- return newSqlQueryHandler .prepareRequest (
192- newSqlRequest ,
193- (restChannel , exception ) -> {
194- try {
195- if (newSqlRequest .isExplainRequest ()) {
196- LOG .info (
197- "Request is falling back to old SQL engine due to: " + exception .getMessage ());
198- }
199- LOG .info (
200- "[{}] Request {} is not supported and falling back to old SQL engine" ,
201- QueryContext .getRequestId (),
202- newSqlRequest );
203- LOG .info ("Request Query: {}" , QueryDataAnonymizer .anonymizeData (sqlRequest .getSql ()));
204- QueryAction queryAction = explainRequest (client , sqlRequest , format );
205- executeSqlRequest (request , queryAction , client , restChannel );
206- } catch (Exception e ) {
207- handleException (restChannel , e );
208- }
209- },
210- this ::handleException );
180+ }
181+ };
211182 } catch (Exception e ) {
212183 return channel -> handleException (channel , e );
213184 }
0 commit comments