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 2020/07/29 07:45:18 UTC

[GitHub] [calcite] danny0405 commented on a change in pull request #2072: [CALCITE-4118] RexSimplify might remove CAST from RexNode incorrectly

danny0405 commented on a change in pull request #2072:
URL: https://github.com/apache/calcite/pull/2072#discussion_r461311453



##########
File path: core/src/main/java/org/apache/calcite/rex/RexSimplify.java
##########
@@ -1917,7 +1918,9 @@ private RexNode simplifyCast(RexCall e) {
       if (RexUtil.isLosslessCast(intExpr.getType(), operand.getType())
           && (e.getType().getSqlTypeName() == operand.getType().getSqlTypeName()
           || e.getType().getSqlTypeName() == SqlTypeName.CHAR
-          || operand.getType().getSqlTypeName() != SqlTypeName.CHAR)) {
+          || operand.getType().getSqlTypeName() != SqlTypeName.CHAR)
+          && SqlTypeAssignmentRule.instance()
+          .canApplyFrom(intExpr.getType().getSqlTypeName(), e.getType().getSqlTypeName())) {
         return rexBuilder.makeCast(e.getType(), intExpr);

Review comment:
       Should be `SqlTypeCoercionRule` ?

##########
File path: core/src/main/java/org/apache/calcite/rex/RexSimplify.java
##########
@@ -1917,7 +1918,9 @@ private RexNode simplifyCast(RexCall e) {
       if (RexUtil.isLosslessCast(intExpr.getType(), operand.getType())
           && (e.getType().getSqlTypeName() == operand.getType().getSqlTypeName()
           || e.getType().getSqlTypeName() == SqlTypeName.CHAR
-          || operand.getType().getSqlTypeName() != SqlTypeName.CHAR)) {
+          || operand.getType().getSqlTypeName() != SqlTypeName.CHAR)
+          && SqlTypeAssignmentRule.instance()
+          .canApplyFrom(intExpr.getType().getSqlTypeName(), e.getType().getSqlTypeName())) {
         return rexBuilder.makeCast(e.getType(), intExpr);

Review comment:
       See the java doc which already gave good explanation.




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