mihaibudiu commented on code in PR #4411:
URL: https://github.com/apache/calcite/pull/4411#discussion_r2151030003


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -941,14 +942,30 @@ boolean canRemoveCastFromLiteral(RelDataType toType,
   private RexNode makeCastExactToBoolean(RelDataType toType, RexNode exp) {
     return makeCall(toType,
         SqlStdOperatorTable.NOT_EQUALS,
-        ImmutableList.of(exp, makeZeroLiteral(exp.getType())));
+        ImmutableList.of(exp, makeZeroValue(exp.getType())));
+  }
+
+  /** Some data types do not have literals; this creates an expression that
+   * evaluates to a zero of the specified type.
+   *
+   * @param type A numeric type.
+   * @return     An expression that evaluates to 0 of the specified type.
+   */
+  public RexNode makeZeroValue(RelDataType type) {
+    if (SqlTypeUtil.hasLiterals(type)) {
+      return makeZeroLiteral(type);
+    } else {
+      // This is e.g., an unsigned type
+      RelDataType i = typeFactory.createSqlType(SqlTypeName.INTEGER);
+      return makeAbstractCast(type, makeZeroValue(i));

Review Comment:
   thanks. I will push some more changes, writing tests, finding missing stuff.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to