You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2019/03/27 11:57:49 UTC

[GitHub] [calcite] zhztheplayer commented on a change in pull request #1057: [CALCITE-2854] code gen error for UNARY_MINUS operator call with deci…

zhztheplayer commented on a change in pull request #1057: [CALCITE-2854] code gen error for UNARY_MINUS operator call with deci…
URL: https://github.com/apache/calcite/pull/1057#discussion_r269524420
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
 ##########
 @@ -2168,7 +2167,14 @@ public Expression implement(
         RexCall call,
         List<Expression> translatedOperands) {
       final Expression operand = translatedOperands.get(0);
-      final UnaryExpression e = Expressions.makeUnary(expressionType, operand);
+
+      final Expression e;
+      if (expressionType == ExpressionType.Negate && operand.type == BigDecimal.class) {
+        e = Expressions.call(BuiltInMethod.UNARY_MINUS.method, operand);
 
 Review comment:
   The class `BinaryImplementor`'s constructor has a parameter `backupMethodName`:
   https://github.com/apache/calcite/blob/280642a02a4bcfd1fb9cbe8c5ab672d3619860e7/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java#L2088-L2093
   
   My suggestion is to change the `UnaryImplementor` to include a similar argument, e.g.
   ```java
   UnaryImplementor(ExpressionType expressionType, String backupMethodName) {
         this.expressionType = expressionType;
         this.backupMethodName = backupMethodName; 
   }
   ```
   
   Then you can specify `BuiltInMethod.UNARY_MINUS.method` as a backup method of the implementor of the operator `UNARY_MINUS`.

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


With regards,
Apache Git Services