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 48bc0570aaa3..d62d632f40b7 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 @@ -622,11 +622,10 @@ public ExprEval apply(List args, Expr.ObjectBinding bindings) ExprEval exprEval = expr.eval(bindings); ExpressionType exprType = exprEval.type(); - if (isValidType(exprType)) { - outputType = ExpressionTypeConversion.function(outputType, exprType); - } - if (exprEval.value() != null) { + if (isValidType(exprType)) { + outputType = ExpressionTypeConversion.function(outputType, exprType); + } evals.add(exprEval); } } 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 d6143fd1fa15..56b3583031f0 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 @@ -677,6 +677,7 @@ public void testGreatest() assertExpr("greatest()", null); assertExpr("greatest(null, null)", null); assertExpr("greatest(1, null, 'A')", "A"); + assertExpr("greatest(1.0, 1, null)", 1.0); } @Test @@ -703,6 +704,7 @@ public void testLeast() assertExpr("least()", null); assertExpr("least(null, null)", null); assertExpr("least(1, null, 'A')", "1"); + assertExpr("least(1.0, 1, null)", 1.0); } @Test diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/GreatestExpressionTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/GreatestExpressionTest.java index f1a5a869a192..893b54499348 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/GreatestExpressionTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/GreatestExpressionTest.java @@ -214,7 +214,7 @@ public void testDecimal() } @Test - public void testDecimalWithNullShouldReturnString() + public void testDecimalWithNullShouldNotReturnString() { testExpression( Arrays.asList( @@ -227,7 +227,7 @@ public void testDecimalWithNullShouldReturnString() null, 3.4 ), - "3.4" + 3.4 ); } @Test diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/LeastExpressionTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/LeastExpressionTest.java index eaec03c00c87..e2d1bbf306ea 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/LeastExpressionTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/LeastExpressionTest.java @@ -214,7 +214,7 @@ public void testDecimal() } @Test - public void testDecimalWithNullShouldReturnString() + public void testDecimalWithNullShouldNotReturnString() { testExpression( Arrays.asList( @@ -227,7 +227,7 @@ public void testDecimalWithNullShouldReturnString() 3.4, null ), - "1.2" + 1.2 ); }