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 f82d61b6b7 Provide more detailed/consolidated exceptions (#11363)
f82d61b6b7 is described below

commit f82d61b6b735e419cabb916b270ee0e4a881aa19
Author: Xiang Fu <[email protected]>
AuthorDate: Wed Aug 16 21:34:47 2023 -0700

    Provide more detailed/consolidated exceptions (#11363)
---
 .../MultiStageBrokerRequestHandler.java            |  7 ++-
 .../apache/pinot/common/utils/ExceptionUtils.java  | 62 ++++++++++++++++++++++
 .../apache/pinot/query/catalog/PinotCatalog.java   |  5 +-
 .../runtime/operator/exchange/BlockExchange.java   |  4 +-
 4 files changed, 71 insertions(+), 7 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 680145e3e8..86d0053a88 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
@@ -50,6 +50,7 @@ import 
org.apache.pinot.common.response.broker.BrokerResponseStats;
 import org.apache.pinot.common.response.broker.QueryProcessingException;
 import org.apache.pinot.common.response.broker.ResultTable;
 import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.common.utils.ExceptionUtils;
 import org.apache.pinot.common.utils.NamedThreadFactory;
 import org.apache.pinot.common.utils.config.QueryOptionsUtils;
 import org.apache.pinot.common.utils.request.RequestUtils;
@@ -152,10 +153,12 @@ public class MultiStageBrokerRequestHandler extends 
BaseBrokerRequestHandler {
           break;
       }
     } catch (Exception e) {
-      LOGGER.info("Caught exception while compiling SQL request {}: {}, {}", 
requestId, query, e.getMessage());
+      LOGGER.info("Caught exception while compiling SQL request {}: {}, {}", 
requestId, query,
+          ExceptionUtils.consolidateExceptionMessages(e));
       
_brokerMetrics.addMeteredGlobalValue(BrokerMeter.REQUEST_COMPILATION_EXCEPTIONS,
 1);
       requestContext.setErrorCode(QueryException.SQL_PARSING_ERROR_CODE);
-      return new 
BrokerResponseNative(QueryException.getException(QueryException.SQL_PARSING_ERROR,
 e.getMessage()));
+      return new 
BrokerResponseNative(QueryException.getException(QueryException.SQL_PARSING_ERROR,
+          ExceptionUtils.consolidateExceptionMessages(e)));
     }
 
     DispatchableSubPlan dispatchableSubPlan = queryPlanResult.getQueryPlan();
diff --git 
a/pinot-common/src/main/java/org/apache/pinot/common/utils/ExceptionUtils.java 
b/pinot-common/src/main/java/org/apache/pinot/common/utils/ExceptionUtils.java
new file mode 100644
index 0000000000..cd12b58489
--- /dev/null
+++ 
b/pinot-common/src/main/java/org/apache/pinot/common/utils/ExceptionUtils.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.utils;
+
+public class ExceptionUtils {
+
+  private ExceptionUtils() {
+  }
+
+  public static String consolidateExceptionMessages(Throwable e) {
+    StringBuilder sb = new StringBuilder();
+    // No more than 10 causes
+    int maxCauses = 10;
+    while (e != null && maxCauses-- > 0) {
+      sb.append(getStackTrace(e, 3));
+      e = e.getCause();
+    }
+    return sb.toString();
+  }
+
+  public static String getStackTrace(Throwable e) {
+    return getStackTrace(e, Integer.MAX_VALUE);
+  }
+
+  public static String getStackTrace(Throwable e, int maxLines) {
+    return getStackTrace(e, maxLines, Integer.MAX_VALUE);
+  }
+
+  public static String getStackTrace(Throwable e, int maxLines, int 
maxLineLength) {
+    StringBuilder sb = new StringBuilder();
+    while (e != null) {
+      sb.append(e.getMessage()).append("\n");
+      for (StackTraceElement ste : e.getStackTrace()) {
+        sb.append(ste.toString()).append("\n");
+        if (maxLines-- <= 0) {
+          return sb.toString();
+        }
+        if (sb.length() > maxLineLength) {
+          return sb.toString();
+        }
+      }
+      e = e.getCause();
+    }
+    return sb.toString();
+  }
+}
diff --git 
a/pinot-query-planner/src/main/java/org/apache/pinot/query/catalog/PinotCatalog.java
 
b/pinot-query-planner/src/main/java/org/apache/pinot/query/catalog/PinotCatalog.java
index 9b6b1c657a..b777c9bc03 100644
--- 
a/pinot-query-planner/src/main/java/org/apache/pinot/query/catalog/PinotCatalog.java
+++ 
b/pinot-query-planner/src/main/java/org/apache/pinot/query/catalog/PinotCatalog.java
@@ -64,10 +64,7 @@ public class PinotCatalog implements Schema {
     String tableName = TableNameBuilder.extractRawTableName(name);
     org.apache.pinot.spi.data.Schema schema = _tableCache.getSchema(tableName);
     if (schema == null) {
-      throw new IllegalArgumentException("Could not find schema for table: '" 
+ tableName
-          + "'. This is likely indicative of some kind of corruption and 
should not happen! "
-          + "If you are running this via the a test environment, check to make 
sure you're "
-          + "specifying the correct tables.");
+      throw new IllegalArgumentException(String.format("Could not find schema 
for table: '%s'", tableName));
     }
     return new PinotTable(schema);
   }
diff --git 
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/exchange/BlockExchange.java
 
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/exchange/BlockExchange.java
index e3f4a48ddf..b7a152df02 100644
--- 
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/exchange/BlockExchange.java
+++ 
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/exchange/BlockExchange.java
@@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Consumer;
 import org.apache.calcite.rel.RelDistribution;
 import org.apache.pinot.common.datablock.DataBlock;
+import org.apache.pinot.common.utils.ExceptionUtils;
 import org.apache.pinot.query.mailbox.SendingMailbox;
 import org.apache.pinot.query.planner.partitioning.KeySelector;
 import org.apache.pinot.query.runtime.blocks.BlockSplitter;
@@ -126,7 +127,8 @@ public abstract class BlockExchange {
       return block;
     } catch (Exception e) {
       TransferableBlock errorBlock = 
TransferableBlockUtils.getErrorTransferableBlock(
-          new RuntimeException("Exception while sending data via exchange for 
opChain: " + _opChainId));
+          new RuntimeException("Exception while sending data via exchange for 
opChain: " + _opChainId + "\n"
+              + ExceptionUtils.consolidateExceptionMessages(e)));
       setErrorBlock(errorBlock);
       return errorBlock;
     }


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

Reply via email to