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

cwylie 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 26f9b174dee Handling nil selector column in vector math processors 
(#16128)
26f9b174dee is described below

commit 26f9b174deec71db02fb58f2f04a47bc62e25fbe
Author: Sree Charan Manamala <155449160+sreemanam...@users.noreply.github.com>
AuthorDate: Tue Apr 2 14:36:57 2024 +0530

    Handling nil selector column in vector math processors (#16128)
---
 .../java/org/apache/druid/math/expr/Function.java  |  9 +++++-
 .../math/expr/vector/VectorMathProcessors.java     | 37 ++++++++++------------
 .../druid/math/expr/VectorExprSanityTest.java      |  8 ++++-
 3 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/processing/src/main/java/org/apache/druid/math/expr/Function.java 
b/processing/src/main/java/org/apache/druid/math/expr/Function.java
index e8ff45d90f1..e870541c909 100644
--- a/processing/src/main/java/org/apache/druid/math/expr/Function.java
+++ b/processing/src/main/java/org/apache/druid/math/expr/Function.java
@@ -241,7 +241,14 @@ public interface Function extends NamedFunction
     @Override
     public boolean canVectorize(Expr.InputBindingInspector inspector, 
List<Expr> args)
     {
-      return inspector.areNumeric(args) && inspector.canVectorize(args);
+      // can not vectorize in default mode for 'missing' columns
+      // it creates inconsistencies as we default the output type to STRING, 
making the value null
+      // but the numeric columns expect a non null value
+      final ExpressionType outputType = args.get(0).getOutputType(inspector);
+      if (outputType == null && NullHandling.replaceWithDefault()) {
+        return false;
+      }
+      return (outputType == null || outputType.isNumeric()) && 
inspector.canVectorize(args);
     }
   }
 
diff --git 
a/processing/src/main/java/org/apache/druid/math/expr/vector/VectorMathProcessors.java
 
b/processing/src/main/java/org/apache/druid/math/expr/vector/VectorMathProcessors.java
index b45764e935e..c4240405378 100644
--- 
a/processing/src/main/java/org/apache/druid/math/expr/vector/VectorMathProcessors.java
+++ 
b/processing/src/main/java/org/apache/druid/math/expr/vector/VectorMathProcessors.java
@@ -47,13 +47,12 @@ public class VectorMathProcessors
     final ExpressionType inputType = arg.getOutputType(inspector);
 
     ExprVectorProcessor<?> processor = null;
-    if (inputType != null) {
-      if (inputType.is(ExprType.LONG)) {
-        processor = longOutLongInSupplier.get();
-      } else if (inputType.is(ExprType.DOUBLE)) {
-        processor = doubleOutDoubleInSupplier.get();
-      }
+    if (Types.isNullOr(inputType, ExprType.DOUBLE)) {
+      processor = doubleOutDoubleInSupplier.get();
+    } else if (inputType.is(ExprType.LONG)) {
+      processor = longOutLongInSupplier.get();
     }
+
     if (processor == null) {
       throw Exprs.cannotVectorize();
     }
@@ -75,13 +74,12 @@ public class VectorMathProcessors
     final ExpressionType inputType = arg.getOutputType(inspector);
 
     ExprVectorProcessor<?> processor = null;
-    if (inputType != null) {
-      if (inputType.is(ExprType.LONG)) {
-        processor = doubleOutLongInSupplier.get();
-      } else if (inputType.is(ExprType.DOUBLE)) {
-        processor = doubleOutDoubleInSupplier.get();
-      }
+    if (Types.isNullOr(inputType, ExprType.DOUBLE)) {
+      processor = doubleOutDoubleInSupplier.get();
+    } else if (inputType.is(ExprType.LONG)) {
+      processor = doubleOutLongInSupplier.get();
     }
+
     if (processor == null) {
       throw Exprs.cannotVectorize();
     }
@@ -103,13 +101,12 @@ public class VectorMathProcessors
     final ExpressionType inputType = arg.getOutputType(inspector);
 
     ExprVectorProcessor<?> processor = null;
-    if (inputType != null) {
-      if (inputType.is(ExprType.LONG)) {
-        processor = longOutLongInSupplier.get();
-      } else if (inputType.is(ExprType.DOUBLE)) {
-        processor = longOutDoubleInSupplier.get();
-      }
+    if (Types.isNullOr(inputType, ExprType.DOUBLE)) {
+      processor = longOutDoubleInSupplier.get();
+    } else if (inputType.is(ExprType.LONG)) {
+      processor = longOutLongInSupplier.get();
     }
+
     if (processor == null) {
       throw Exprs.cannotVectorize();
     }
@@ -2035,7 +2032,7 @@ public class VectorMathProcessors
           return Double.doubleToLongBits(input);
         }
       };
-    } else if (Types.is(inputType, ExprType.DOUBLE)) {
+    } else if (Types.isNullOr(inputType, ExprType.DOUBLE)) {
       processor = new LongOutDoubleInFunctionVectorValueProcessor(
           arg.asVectorProcessor(inspector),
           inspector.getMaxVectorSize()
@@ -2074,7 +2071,7 @@ public class VectorMathProcessors
           return Double.longBitsToDouble(input);
         }
       };
-    } else if (Types.is(inputType, ExprType.DOUBLE)) {
+    } else if (Types.isNullOr(inputType, ExprType.DOUBLE)) {
       processor = new DoubleOutDoubleInFunctionVectorValueProcessor(
           arg.asVectorProcessor(inspector),
           inspector.getMaxVectorSize()
diff --git 
a/processing/src/test/java/org/apache/druid/math/expr/VectorExprSanityTest.java 
b/processing/src/test/java/org/apache/druid/math/expr/VectorExprSanityTest.java
index d25220f0929..f96c648c9fa 100644
--- 
a/processing/src/test/java/org/apache/druid/math/expr/VectorExprSanityTest.java
+++ 
b/processing/src/test/java/org/apache/druid/math/expr/VectorExprSanityTest.java
@@ -176,7 +176,13 @@ public class VectorExprSanityTest extends 
InitializedNullHandlingTest
         "bitwiseConvertDoubleToLongBits",
         "bitwiseConvertLongBitsToDouble"
     };
-    final String[] templates = new String[]{"%s(l1)", "%s(d1)", "%s(pi())", 
"%s(null)"};
+    final String[] templates;
+    if (NullHandling.sqlCompatible()) {
+      templates = new String[]{"%s(l1)", "%s(d1)", "%s(pi())", "%s(null)", 
"%s(missing)"};
+    } else {
+      // missing columns are not vectorizable in default value mode
+      templates = new String[]{"%s(l1)", "%s(d1)", "%s(pi())", "%s(null)"};
+    }
     testFunctions(types, templates, functions);
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org
For additional commands, e-mail: commits-h...@druid.apache.org

Reply via email to