You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/04/12 09:44:22 UTC

[GitHub] [druid] chenyuzhi459 commented on a change in pull request #11088: add round test

chenyuzhi459 commented on a change in pull request #11088:
URL: https://github.com/apache/druid/pull/11088#discussion_r611481236



##########
File path: core/src/test/java/org/apache/druid/math/expr/FunctionTest.java
##########
@@ -407,12 +407,40 @@ public void testRoundWithExtremeNumbers()
     assertExpr("round(CAST(minLong, 'DOUBLE') - 1, -2)", BigDecimal.valueOf(((double) Long.MIN_VALUE) - 1).setScale(-2, RoundingMode.HALF_UP).doubleValue());
   }
 
+  @Test
+  public void testRoundWithNullValue()
+  {
+    Set<Pair<String, String>> invalidArguments = ImmutableSet.of(
+        Pair.of("null", "STRING"),
+        Pair.of("x", "STRING")
+    );
+    for (Pair<String, String> argAndType : invalidArguments) {
+      if (NullHandling.sqlCompatible()) {
+        assertExpr(String.format(Locale.ENGLISH, "round(%s)", argAndType.lhs), null);

Review comment:
       Thanks for your tips .Actually, I think it can be more flexable to handle null value. If we  handle it like:
   
         if (NullHandling.sqlCompatible() && value1.isNumericNull()) {
           return ExprEval.of(null);
         }
         if (value1.type() != ExprType.LONG && value1.type() != ExprType.DOUBLE) {
           throw new IAE(
               "The first argument to the function[%s] should be integer or double type but got the type: %s",
               name(),
               value1.type()
           );
         }
   
   It is not compatible for usage  `round(null,  1)` , which  should assign a default  value for null.  I am trying to be compatible for usages like `round(null)` and `round(null, 1)`




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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