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 08:01:09 UTC

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

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



##########
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:
       It seems you're right. BYW, what's the difference between `SqlTypeCoercionRule ` and `SqlTypeAssignmentRule `?

##########
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:
       It seems you're right. BTW, what's the difference between `SqlTypeCoercionRule ` and `SqlTypeAssignmentRule `?




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