amaliujia commented on a change in pull request #1506: [CALCITE-3411] Incorrect 
code generated for BigDecimal ConstantExpression
URL: https://github.com/apache/calcite/pull/1506#discussion_r334645186
 
 

 ##########
 File path: 
linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantExpression.java
 ##########
 @@ -147,11 +147,15 @@ private static ExpressionWriter write(ExpressionWriter 
writer,
       try {
         final int scale = bigDecimal.scale();
         final long exact = 
bigDecimal.scaleByPowerOfTen(scale).longValueExact();
-        writer.append("new java.math.BigDecimal(").append(exact).append("L");
-        if (scale != 0) {
-          writer.append(", ").append(scale);
+        if (scale == 0) {
+          writer.append("new java.math.BigDecimal(")
+                .append(exact).append("L").append(")");
+        } else {
+          writer.append("java.math.BigDecimal.valueOf(")
+                .append(exact).append("L")
+                .append(", ").append(scale).append(")");
         }
 
 Review comment:
   Maybe just unify this if else and use `java.math.BigDecimal.valueOf` for 
both scale=0 and scale!=0 case?
   
   Per Java doc, `valueOf` is  the preferred way than BigDecimal constructor 
   
   

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