vlsi commented on a change in pull request #1610: [CALCITE-3525] RexSimplify: 
eliminate redundant rex calls in OR
URL: https://github.com/apache/calcite/pull/1610#discussion_r358731294
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/rex/RexBuilder.java
 ##########
 @@ -1481,11 +1483,13 @@ public RexNode makeLiteral(Object value, RelDataType 
type,
         operands.add(e);
       }
       return new RexLiteral((Comparable) FlatLists.of(operands), type,
-          type.getSqlTypeName());
+          sqlTypeName);
     case ANY:
       return makeLiteral(value, guessType(value), allowCast);
     default:
-      throw Util.unexpected(type.getSqlTypeName());
+      throw new IllegalArgumentException(
+          String.format(Locale.ROOT,
+          "Cannot create literal for type '%s'", sqlTypeName));
 
 Review comment:
   It turns out this `new ..Exception(String.format` is used for the control 
flow.
   In other words, `ReduceExpressions` rule would try to replace literal with 
whatever, thus it would call `.makeLiteral` and it would fail.
   The sad thing is it might do so again and again for the slightly different 
variations of the query.
   
   `String.format` is time-consuming operation, since the current 
implementation (e.g. OpenJDK 8-13) uses regular expressions to parse `%s` and 
so on.
   
   There's on-going effort to indify Formatter-related methods (see 
https://bugs.openjdk.java.net/browse/JDK-8211062 ) , but I would suggest we 
treat all uses of `String.format` as slow calls.
   
   Frankly speaking, I do not like throwing exceptions on a hot paths either, 
but it was something that was existed already.
   
   However, you add `String.format`, and it does not improve readability much, 
so I suggest to stick with default string concatenation because it is still 
very clear

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to