github-advanced-security[bot] commented on code in PR #18549:
URL: https://github.com/apache/druid/pull/18549#discussion_r2361984684


##########
processing/src/test/java/org/apache/druid/math/expr/VectorExprResultConsistencyTest.java:
##########
@@ -604,103 +754,74 @@
    * runs expressions against bindings generated by increasing a counter
    */
   public static void testExpressionSequentialBindings(
-      String expr,
-      Expr parsed,
-      Map<String, ExpressionType> types,
-      int numIterations
+      final String expr,
+      final Expr parsed,
+      final Map<String, ExpressionType> types,
+      final int numIterations
   )
   {
     for (int iter = 0; iter < numIterations; iter++) {
-      NonnullPair<Expr.ObjectBinding[], Expr.VectorInputBinding> bindings = 
makeSequentialBinding(
-          VECTOR_SIZE,
-          types,
-          1 + (iter * VECTOR_SIZE) // the plus 1 is because dividing by zero 
is sad
+      assertEvalsMatch(
+          expr,
+          parsed,
+          makeSequentialBinding(
+              VECTOR_SIZE,
+              types,
+              -2 + (iter * VECTOR_SIZE) // include negative numbers and zero
+          )
       );
-      Assert.assertTrue(StringUtils.format("Cannot vectorize %s", expr), 
parsed.canVectorize(bindings.rhs));
-      ExpressionType outputType = parsed.getOutputType(bindings.rhs);
-      ExprEvalVector<?> vectorEval = 
parsed.asVectorProcessor(bindings.rhs).evalVector(bindings.rhs);
-      // 'null' expressions can have an output type of null, but still 
evaluate in default mode, so skip type checks
-      if (outputType != null) {
-        Assert.assertEquals(expr, outputType, vectorEval.getType());
-      }
-      final Object[] vectorVals = vectorEval.getObjectVector();
-      for (int i = 0; i < VECTOR_SIZE; i++) {
-        ExprEval<?> eval = parsed.eval(bindings.lhs[i]);
-        // 'null' expressions can have an output type of null, but still 
evaluate in default mode, so skip type checks
-        if (outputType != null && !eval.isNumericNull()) {
-          Assert.assertEquals(eval.type(), outputType);
-        }
-        if (outputType != null && outputType.isArray()) {
-          Assert.assertArrayEquals(
-              StringUtils.format("Values do not match for row %s for 
expression %s", i, expr),
-              (Object[]) eval.value(),
-              (Object[]) vectorVals[i]
-          );
-        } else {
-          Assert.assertEquals(
-              StringUtils.format("Values do not match for row %s for 
expression %s", i, expr),
-              eval.value(),
-              vectorVals[i]
-          );
-        }
-      }
     }
   }
 
   public static void testExpressionRandomizedBindings(
-      String expr,
-      Expr parsed,
-      Map<String, ExpressionType> types,
-      int numIterations
+      final String expr,
+      final Expr parsed,
+      final Map<String, ExpressionType> types,
+      final int numIterations
   )
   {
-    Expr.InputBindingInspector inspector = 
InputBindings.inspectorFromTypeMap(types);
-    Expr.VectorInputBindingInspector vectorInputBindingInspector = new 
Expr.VectorInputBindingInspector()
-    {
-      @Override
-      public int getMaxVectorSize()
-      {
-        return VECTOR_SIZE;
-      }
-
-      @Nullable
-      @Override
-      public ExpressionType getType(String name)
-      {
-        return inspector.getType(name);
-      }
-    };
-    Assert.assertTrue(StringUtils.format("Cannot vectorize %s", expr), 
parsed.canVectorize(inspector));
-    ExpressionType outputType = parsed.getOutputType(inspector);
-    final ExprVectorProcessor processor = 
parsed.asVectorProcessor(vectorInputBindingInspector);
-    // 'null' expressions can have an output type of null, but still evaluate 
in default mode, so skip type checks
-    if (outputType != null) {
-      Assert.assertEquals(expr, outputType, processor.getOutputType());
-    }
     for (int iterations = 0; iterations < numIterations; iterations++) {
-      NonnullPair<Expr.ObjectBinding[], Expr.VectorInputBinding> bindings = 
makeRandomizedBindings(VECTOR_SIZE, types);
-      ExprEvalVector<?> vectorEval = processor.evalVector(bindings.rhs);
-      final Object[] vectorVals = vectorEval.getObjectVector();
-      if (outputType != null) {
-        Assert.assertEquals("vector eval type", outputType, 
vectorEval.getType());
-      }
+      assertEvalsMatch(expr, parsed, makeRandomizedBindings(VECTOR_SIZE, 
types));
+    }
+  }
+
+  public static void assertEvalsMatch(
+      String exprString,
+      Expr expr,
+      NonnullPair<Expr.ObjectBinding[], Expr.VectorInputBinding> bindings
+  )
+  {
+    Assert.assertTrue(StringUtils.format("Cannot vectorize[%s]", expr), 
expr.canVectorize(bindings.rhs));
+
+    final ExpressionType outputType = expr.getOutputType(bindings.rhs);
+    final Either<String, Object[]> vectorEval = evalVector(expr, bindings.rhs, 
outputType);
+    final Either<String, Object[]> nonVectorEval = evalNonVector(expr, 
bindings.lhs, outputType);
+
+    Assert.assertEquals(
+        StringUtils.format("Errors do not match for expr[%s], bindings[%s]", 
exprString, bindings.lhs),

Review Comment:
   ## Implicit conversion from array to string
   
   Implicit conversion from Array to String.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/10384)



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to