This is an automated email from the ASF dual-hosted git repository.

xiangfu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new b3c87ec195 Return better error info when no servers instances can be 
found in mu… (#11440)
b3c87ec195 is described below

commit b3c87ec195c67d43d5bc0f1f6f836bb39eb4a215
Author: Gonzalo Ortiz Jaureguizar <[email protected]>
AuthorDate: Wed Sep 6 17:13:24 2023 +0200

    Return better error info when no servers instances can be found in mu… 
(#11440)
    
    * Classify as planning errors some errors that were previously classified 
as parsing
    
    * Fix test
    
    * Fix another test
---
 .../requesthandler/MultiStageBrokerRequestHandler.java  | 17 ++++++++++++++---
 .../apache/pinot/common/exception/QueryException.java   |  3 +++
 .../tests/MultiStageEngineIntegrationTest.java          |  5 ++++-
 .../pinot/integration/tests/custom/JsonPathTest.java    | 13 ++++++++++---
 .../org/apache/pinot/query/routing/WorkerManager.java   |  2 +-
 5 files changed, 32 insertions(+), 8 deletions(-)

diff --git 
a/pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/MultiStageBrokerRequestHandler.java
 
b/pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/MultiStageBrokerRequestHandler.java
index 8321d6aa7a..620f81367b 100644
--- 
a/pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/MultiStageBrokerRequestHandler.java
+++ 
b/pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/MultiStageBrokerRequestHandler.java
@@ -106,6 +106,15 @@ public class MultiStageBrokerRequestHandler extends 
BaseBrokerRequestHandler {
     try {
       // Parse the request
       sqlNodeAndOptions = sqlNodeAndOptions != null ? sqlNodeAndOptions : 
RequestUtils.parseQuery(query, request);
+    } catch (RuntimeException e) {
+      String consolidatedMessage = 
ExceptionUtils.consolidateExceptionMessages(e);
+      LOGGER.info("Caught exception parsing request {}: {}, {}", requestId, 
query, consolidatedMessage);
+      
_brokerMetrics.addMeteredGlobalValue(BrokerMeter.REQUEST_COMPILATION_EXCEPTIONS,
 1);
+      requestContext.setErrorCode(QueryException.SQL_PARSING_ERROR_CODE);
+      return new BrokerResponseNative(
+          QueryException.getException(QueryException.SQL_PARSING_ERROR, 
consolidatedMessage));
+    }
+    try {
       Long timeoutMsFromQueryOption = 
QueryOptionsUtils.getTimeoutMs(sqlNodeAndOptions.getOptions());
       queryTimeoutMs = timeoutMsFromQueryOption == null ? _brokerTimeoutMs : 
timeoutMsFromQueryOption;
       // Compile the request
@@ -125,13 +134,15 @@ public class MultiStageBrokerRequestHandler extends 
BaseBrokerRequestHandler {
           queryPlanResult = _queryEnvironment.planQuery(query, 
sqlNodeAndOptions, requestId);
           break;
       }
-    } catch (Exception e) {
+    } catch (WebApplicationException e) {
+      throw e;
+    } catch (RuntimeException e) {
       String consolidatedMessage = 
ExceptionUtils.consolidateExceptionMessages(e);
       LOGGER.info("Caught exception compiling request {}: {}, {}", requestId, 
query, consolidatedMessage);
       
_brokerMetrics.addMeteredGlobalValue(BrokerMeter.REQUEST_COMPILATION_EXCEPTIONS,
 1);
-      requestContext.setErrorCode(QueryException.SQL_PARSING_ERROR_CODE);
+      requestContext.setErrorCode(QueryException.QUERY_PLANNING_ERROR_CODE);
       return new BrokerResponseNative(
-          QueryException.getException(QueryException.SQL_PARSING_ERROR, 
consolidatedMessage));
+          QueryException.getException(QueryException.QUERY_PLANNING_ERROR, 
consolidatedMessage));
     }
 
     DispatchableSubPlan dispatchableSubPlan = queryPlanResult.getQueryPlan();
diff --git 
a/pinot-common/src/main/java/org/apache/pinot/common/exception/QueryException.java
 
b/pinot-common/src/main/java/org/apache/pinot/common/exception/QueryException.java
index fc82d853e7..52bc0ee6b3 100644
--- 
a/pinot-common/src/main/java/org/apache/pinot/common/exception/QueryException.java
+++ 
b/pinot-common/src/main/java/org/apache/pinot/common/exception/QueryException.java
@@ -80,12 +80,14 @@ public class QueryException {
   public static final int COMBINE_GROUP_BY_EXCEPTION_ERROR_CODE = 600;
   public static final int QUERY_VALIDATION_ERROR_CODE = 700;
   public static final int UNKNOWN_COLUMN_ERROR_CODE = 710;
+  public static final int QUERY_PLANNING_ERROR_CODE = 720;
   public static final int UNKNOWN_ERROR_CODE = 1000;
   // NOTE: update isClientError() method appropriately when new codes are added
 
   public static final ProcessingException JSON_PARSING_ERROR = new 
ProcessingException(JSON_PARSING_ERROR_CODE);
   public static final ProcessingException JSON_COMPILATION_ERROR = new 
ProcessingException(JSON_COMPILATION_ERROR_CODE);
   public static final ProcessingException SQL_PARSING_ERROR = new 
ProcessingException(SQL_PARSING_ERROR_CODE);
+  public static final ProcessingException QUERY_PLANNING_ERROR = new 
ProcessingException(QUERY_PLANNING_ERROR_CODE);
   public static final ProcessingException ACCESS_DENIED_ERROR = new 
ProcessingException(ACCESS_DENIED_ERROR_CODE);
   public static final ProcessingException SEGMENT_PLAN_EXECUTION_ERROR =
       new ProcessingException(SEGMENT_PLAN_EXECUTION_ERROR_CODE);
@@ -140,6 +142,7 @@ public class QueryException {
     JSON_PARSING_ERROR.setMessage("JsonParsingError");
     JSON_COMPILATION_ERROR.setMessage("JsonCompilationError");
     SQL_PARSING_ERROR.setMessage("SQLParsingError");
+    QUERY_PLANNING_ERROR.setMessage("QueryPlanningError");
     SEGMENT_PLAN_EXECUTION_ERROR.setMessage("SegmentPlanExecutionError");
     
COMBINE_SEGMENT_PLAN_TIMEOUT_ERROR.setMessage("CombineSegmentPlanTimeoutError");
     TABLE_DOES_NOT_EXIST_ERROR.setMessage("TableDoesNotExistError");
diff --git 
a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/MultiStageEngineIntegrationTest.java
 
b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/MultiStageEngineIntegrationTest.java
index 31583b1a0b..4099b744c2 100644
--- 
a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/MultiStageEngineIntegrationTest.java
+++ 
b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/MultiStageEngineIntegrationTest.java
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Pattern;
 import org.apache.commons.io.FileUtils;
+import org.apache.pinot.common.exception.QueryException;
 import org.apache.pinot.spi.config.table.TableConfig;
 import org.apache.pinot.spi.data.Schema;
 import org.apache.pinot.util.TestUtils;
@@ -451,7 +452,9 @@ public class MultiStageEngineIntegrationTest extends 
BaseClusterIntegrationTestS
     // invalid argument
     sqlQuery = "SELECT toBase64('hello!') FROM mytable";
     response = postQuery(sqlQuery);
-    
assertTrue(response.get("exceptions").get(0).get("message").toString().contains("SQLParsingError"));
+    int expectedStatusCode = useMultiStageQueryEngine() ? 
QueryException.QUERY_PLANNING_ERROR_CODE
+        : QueryException.SQL_PARSING_ERROR_CODE;
+    
Assert.assertEquals(response.get("exceptions").get(0).get("errorCode").asInt(), 
expectedStatusCode);
 
     // invalid argument
     sqlQuery = "SELECT fromBase64('hello!') FROM mytable";
diff --git 
a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/JsonPathTest.java
 
b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/JsonPathTest.java
index 0526321e0a..c310417b7d 100644
--- 
a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/JsonPathTest.java
+++ 
b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/JsonPathTest.java
@@ -33,6 +33,7 @@ import java.util.Map;
 import org.apache.avro.file.DataFileWriter;
 import org.apache.avro.generic.GenericData;
 import org.apache.avro.generic.GenericDatumWriter;
+import org.apache.pinot.common.exception.QueryException;
 import org.apache.pinot.common.function.JsonPathCache;
 import org.apache.pinot.spi.config.table.TableConfig;
 import org.apache.pinot.spi.config.table.TableType;
@@ -336,21 +337,27 @@ public class JsonPathTest extends 
CustomDataQueryClusterIntegrationTest {
     setUseMultiStageQueryEngine(useMultiStageQueryEngine);
     String query = "Select jsonExtractScalar(myMapStr,\"$.k1\",\"STRING\") 
from " + getTableName();
     JsonNode pinotResponse = postQuery(query);
-    
Assert.assertEquals(pinotResponse.get("exceptions").get(0).get("errorCode").asInt(),
 150);
+    int expectedStatusCode;
+    if (useMultiStageQueryEngine) {
+      expectedStatusCode = QueryException.QUERY_PLANNING_ERROR_CODE;
+    } else {
+      expectedStatusCode = QueryException.SQL_PARSING_ERROR_CODE;
+    }
+    
Assert.assertEquals(pinotResponse.get("exceptions").get(0).get("errorCode").asInt(),
 expectedStatusCode);
     Assert.assertEquals(pinotResponse.get("numDocsScanned").asInt(), 0);
     Assert.assertEquals(pinotResponse.get("totalDocs").asInt(), 0);
 
     query = "Select myMapStr from " + getTableName()
         + "  where jsonExtractScalar(myMapStr, '$.k1',\"STRING\") = 
'value-k1-0'";
     pinotResponse = postQuery(query);
-    
Assert.assertEquals(pinotResponse.get("exceptions").get(0).get("errorCode").asInt(),
 150);
+    
Assert.assertEquals(pinotResponse.get("exceptions").get(0).get("errorCode").asInt(),
 expectedStatusCode);
     Assert.assertEquals(pinotResponse.get("numDocsScanned").asInt(), 0);
     Assert.assertEquals(pinotResponse.get("totalDocs").asInt(), 0);
 
     query = "Select jsonExtractScalar(myMapStr,\"$.k1\", 'STRING') from " + 
getTableName()
         + "  where jsonExtractScalar(myMapStr, '$.k1', 'STRING') = 
'value-k1-0'";
     pinotResponse = postQuery(query);
-    
Assert.assertEquals(pinotResponse.get("exceptions").get(0).get("errorCode").asInt(),
 150);
+    
Assert.assertEquals(pinotResponse.get("exceptions").get(0).get("errorCode").asInt(),
 expectedStatusCode);
     Assert.assertEquals(pinotResponse.get("numDocsScanned").asInt(), 0);
     Assert.assertEquals(pinotResponse.get("totalDocs").asInt(), 0);
   }
diff --git 
a/pinot-query-planner/src/main/java/org/apache/pinot/query/routing/WorkerManager.java
 
b/pinot-query-planner/src/main/java/org/apache/pinot/query/routing/WorkerManager.java
index 163ccb6bd6..e8188b3987 100644
--- 
a/pinot-query-planner/src/main/java/org/apache/pinot/query/routing/WorkerManager.java
+++ 
b/pinot-query-planner/src/main/java/org/apache/pinot/query/routing/WorkerManager.java
@@ -230,7 +230,7 @@ public class WorkerManager {
       ServerInstance serverInstance =
           pickEnabledServer(partitionInfo._fullyReplicatedServers, 
enabledServerInstanceMap, indexToPick++);
       Preconditions.checkState(serverInstance != null,
-          "Failed to find enabled fully replicated server for table: %s, 
partition: %s in table: %s", tableName, i);
+          "Failed to find enabled fully replicated server for table: %s, 
partition: %s", tableName, i);
       workedIdToServerInstanceMap.put(workerId, new 
QueryServerInstance(serverInstance));
       workerIdToSegmentsMap.put(workerId, getSegmentsMap(partitionInfo));
       workerId++;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to