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

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


The following commit(s) were added to refs/heads/master by this push:
     new f48263bbb3f Report function name for unknown exceptions during 
execution (#14987)
f48263bbb3f is described below

commit f48263bbb3f1f258cf435b39ddf94a24ed32c741
Author: Zoltan Haindrich <[email protected]>
AuthorDate: Wed Oct 25 22:37:30 2023 +0200

    Report function name for unknown exceptions during execution (#14987)
    
    * provide function name when unknown exceptions are encountered
    
    * fix keywords/etc
    
    * fix keywrod order - regex excercise
    
    * add test
    
    * add check&fix keywords
    
    * decoupledIgnore
    
    * Revert "decoupledIgnore"
    
    This reverts commit e922c820a7d563ca49c9c686644bed967c42cb4b.
    
    * unpatch Function
    
    * move to a different location
    
    * checkstyle
---
 .../org/apache/druid/math/expr/FunctionalExpr.java | 11 ++++++-
 .../org/apache/druid/math/expr/FunctionTest.java   | 36 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git 
a/processing/src/main/java/org/apache/druid/math/expr/FunctionalExpr.java 
b/processing/src/main/java/org/apache/druid/math/expr/FunctionalExpr.java
index b83efb2b2bc..3d5a7f511f9 100644
--- a/processing/src/main/java/org/apache/druid/math/expr/FunctionalExpr.java
+++ b/processing/src/main/java/org/apache/druid/math/expr/FunctionalExpr.java
@@ -21,6 +21,7 @@ package org.apache.druid.math.expr;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
+import org.apache.druid.error.DruidException;
 import org.apache.druid.java.util.common.StringUtils;
 import org.apache.druid.math.expr.vector.ExprVectorProcessor;
 
@@ -186,7 +187,15 @@ class FunctionExpr implements Expr
   @Override
   public ExprEval eval(ObjectBinding bindings)
   {
-    return function.apply(args, bindings);
+    try {
+      return function.apply(args, bindings);
+    }
+    catch (DruidException | ExpressionValidationException e) {
+      throw e;
+    }
+    catch (Exception e) {
+      throw DruidException.defensive().build(e, "Invocation of function '%s' 
encountered exception.", name);
+    }
   }
 
   @Override
diff --git 
a/processing/src/test/java/org/apache/druid/math/expr/FunctionTest.java 
b/processing/src/test/java/org/apache/druid/math/expr/FunctionTest.java
index a093db167bb..d975ec069d5 100644
--- a/processing/src/test/java/org/apache/druid/math/expr/FunctionTest.java
+++ b/processing/src/test/java/org/apache/druid/math/expr/FunctionTest.java
@@ -23,10 +23,12 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.error.DruidException;
 import org.apache.druid.guice.NestedDataModule;
 import org.apache.druid.java.util.common.IAE;
 import org.apache.druid.java.util.common.Pair;
 import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.math.expr.Expr.ObjectBinding;
 import org.apache.druid.segment.column.TypeStrategies;
 import org.apache.druid.segment.column.TypeStrategiesTest;
 import org.apache.druid.segment.column.TypeStrategy;
@@ -38,6 +40,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 
 import javax.annotation.Nullable;
+
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.nio.ByteBuffer;
@@ -46,6 +49,9 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
 public class FunctionTest extends InitializedNullHandlingTest
 {
   private Expr.ObjectBinding bestEffortBindings;
@@ -122,6 +128,36 @@ public class FunctionTest extends 
InitializedNullHandlingTest
     allBindings = new Expr.ObjectBinding[]{bestEffortBindings, typedBindings};
   }
 
+  @Test
+  public void testUnknownErrorsAreWrappedAndReported()
+  {
+    final Expr expr = Parser.parse("abs(x)", ExprMacroTable.nil());
+
+    ObjectBinding bind = new ObjectBinding()
+    {
+
+      @Override
+      public ExpressionType getType(String name)
+      {
+        return ExpressionType.LONG_ARRAY;
+      }
+
+      @Override
+      public Object get(String name)
+      {
+        throw new RuntimeException("nested-exception");
+      }
+    };
+    DruidException e = Assert.assertThrows(DruidException.class,
+        () -> {
+          expr.eval(bind);
+        });
+
+    assertEquals("Invocation of function 'abs' encountered exception.", 
e.getMessage());
+    assertNotNull(e.getCause());
+    assertEquals("nested-exception", e.getCause().getMessage());
+  }
+
   @Test
   public void testCaseSimple()
   {


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

Reply via email to