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


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -1000,6 +1000,14 @@ void testCastToInterval(CastType castType, 
SqlOperatorFixture f) {
         "cast(-5723 as interval minute(4))",
         "-5723",
         "INTERVAL MINUTE(4) NOT NULL");
+    f.checkScalar(
+        "cast(cast(1 as integer) as interval minute)",
+        "+1",
+        "INTERVAL MINUTE NOT NULL");
+    f.checkScalar(

Review Comment:
   how about other interval types, such as `INTERVAL HOUR`?
   



##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1336,8 +1337,15 @@ protected RexLiteral makeLiteral(
       o = ((TimestampWithTimeZoneString) o).round(p);
       break;
     case DECIMAL:
-      if (o != null && type.getScale() != RelDataType.SCALE_NOT_SPECIFIED) {
-        assert o instanceof BigDecimal;
+      if (o == null) {

Review Comment:
   is this a problem with literals only, or does it happen to non-constant 
expressions too?
   Can you check if there is a Quidem test (in an .iq file) for this?
   If not, can you please add some?



##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1336,8 +1337,15 @@ protected RexLiteral makeLiteral(
       o = ((TimestampWithTimeZoneString) o).round(p);
       break;
     case DECIMAL:
-      if (o != null && type.getScale() != RelDataType.SCALE_NOT_SPECIFIED) {
-        assert o instanceof BigDecimal;
+      if (o == null) {
+        break;
+      }
+      assert o instanceof BigDecimal;
+      if (type instanceof IntervalSqlType) {
+        SqlIntervalQualifier qualifier = ((IntervalSqlType) 
type).getIntervalQualifier();
+        o = ((BigDecimal) o).multiply(qualifier.getUnit().multiplier);

Review Comment:
   multiplier can also be fractional, can you also add a test for some of these 
units, like MILLISECONDS?
   It may be easier to add tests to a quide file than to SqlOperatorTest.



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