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

jackie 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 7b06b9f5c3 Issue #12367 (#12922)
7b06b9f5c3 is described below

commit 7b06b9f5c3b945c585eba0fa3a7118845e58802e
Author: Aditya Mahajan <aditya.m.1...@gmail.com>
AuthorDate: Tue Apr 30 01:54:15 2024 +0530

    Issue #12367 (#12922)
---
 .../function/CaseTransformFunctionTest.java        | 31 +++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git 
a/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/CaseTransformFunctionTest.java
 
b/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/CaseTransformFunctionTest.java
index 79a415e5a9..315b53e9e0 100644
--- 
a/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/CaseTransformFunctionTest.java
+++ 
b/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/CaseTransformFunctionTest.java
@@ -36,6 +36,7 @@ import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
 
 
 public class CaseTransformFunctionTest extends BaseTransformFunctionTest {
@@ -106,7 +107,8 @@ public class CaseTransformFunctionTest extends 
BaseTransformFunctionTest {
       testCaseQueries(String.format("%s(%s, %s)", functionType.getName(), 
LONG_SV_COLUMN,
           String.format("%d", _longSVValues[INDEX_TO_COMPARE])), 
getPredicateResults(LONG_SV_COLUMN, functionType));
       testCaseQueries(String.format("%s(%s, %s)", functionType.getName(), 
FLOAT_SV_COLUMN,
-          String.format("%f", _floatSVValues[INDEX_TO_COMPARE])), 
getPredicateResults(FLOAT_SV_COLUMN, functionType));
+              "CAST(" + String.format("%f", _floatSVValues[INDEX_TO_COMPARE]) 
+ " AS FLOAT)"),
+          getPredicateResults(FLOAT_SV_COLUMN, functionType));
       testCaseQueries(String.format("%s(%s, %s)", functionType.getName(), 
DOUBLE_SV_COLUMN,
               String.format("%.20f", _doubleSVValues[INDEX_TO_COMPARE])),
           getPredicateResults(DOUBLE_SV_COLUMN, functionType));
@@ -116,6 +118,33 @@ public class CaseTransformFunctionTest extends 
BaseTransformFunctionTest {
     }
   }
 
+  @Test
+  public void testCaseTransformFunctionWithoutCastForFloatValues() {
+    boolean[] predicateResults = new boolean[1];
+    Arrays.fill(predicateResults, true);
+    int[] expectedValues = new int[1];
+    int index = -1;
+    for (int i = 0; i < NUM_ROWS; i++) {
+      if (Double.compare(_floatSVValues[i], 
Double.parseDouble(String.format("%f", _floatSVValues[i]))) != 0) {
+        index = i;
+        expectedValues[0] = predicateResults[0] ? _intSVValues[i] : 10;
+        break;
+      }
+    }
+
+    if (index != -1) {
+      String predicate = String.format("%s(%s, %s)", 
TransformFunctionType.EQUALS, FLOAT_SV_COLUMN,
+          String.format("%f", _floatSVValues[index]));
+      String expression = String.format("CASE WHEN %s THEN %s ELSE 10 END", 
predicate, INT_SV_COLUMN);
+      ExpressionContext expressionContext = 
RequestContextUtils.getExpression(expression);
+      TransformFunction transformFunction = 
TransformFunctionFactory.get(expressionContext, _dataSourceMap);
+      Assert.assertTrue(transformFunction instanceof CaseTransformFunction);
+      assertEquals(transformFunction.getResultMetadata().getDataType(), 
DataType.INT);
+      int[] intValues = 
transformFunction.transformToIntValuesSV(_projectionBlock);
+      assertNotEquals(intValues[index], expectedValues[0]);
+    }
+  }
+
   @DataProvider
   public static String[] illegalExpressions() {
     //@formatter:off


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

Reply via email to