ihuzenko commented on a change in pull request #1975: DRILL-7576: Fail fast for 
operator errors
URL: https://github.com/apache/drill/pull/1975#discussion_r376903426
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/BaseRootExec.java
 ##########
 @@ -184,4 +179,38 @@ public void close() throws Exception {
       }
     }
   }
+
+  /**
+   * Given a list of operators and a stack trace, walks the stack trace and
+   * the operator list to find the leaf-most operator, which is the one
+   * that was active when the exception was thrown. Handle the cases in
+   * which no operator was active, each operator had multiple methods on
+   * the stack, or the exception was thrown in some class called by
+   * the operator.
+   * <p>
+   * Not all operators leave a mark in the trace. In particular if a the
+   * call stack is only through base-class methods, then we have no way to
+   * know the actual class during the call. This is OK because the leaf
+   * methods are just pass-through operations, they are unlikely to fail.
+   *
+   * @param <T> the type of the operator. Parameterized to allow easier
+   * testing
+   * @param dag the list of operators from root-most to leaf-most
+   * @param e the exception thrown somewhere in the operator tree
+   * @return the leaf-most operator, if any
+   */
+  public static <T> T findLeaf(List<T> dag, Throwable e) {
+    StackTraceElement[] trace = e.getStackTrace();
 
 Review comment:
   Minor comment: here we could collect a ```Set``` of class name strings 
ignoring those names which don't start with ```org.apache.drill``` package 
name.   Like: 
   ```java
       Set<String> drillStackTrace = Stream.of(trace)
           .map(StackTraceElement::getClassName)
           .filter(cn -> cn.startsWith(DRILL_PACKAGE_NAME))
           .collect(Collectors.toSet());
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to