danny0405 commented on a change in pull request #1592: [CALCITE-3512] Query 
fails when comparing Time/TimeStamp types
URL: https://github.com/apache/calcite/pull/1592#discussion_r349903249
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
 ##########
 @@ -962,6 +962,63 @@ public static Expression convert(Expression operand, Type 
toType) {
     return convert(operand, fromType, toType);
   }
 
+  /**
+   * In Calcite, {@code java.sql.Date} and {@code java.sql.Time} are
+   * stored as {@code Integer} type, {@code java.sql.Timestamp} is
+   * stored as {@code Long} type.
+   */
+  private static Expression convertToInternalType(Expression operand,
+      Type fromType, Type toType) {
+    if (fromType == java.sql.Date.class) {
+      if (toType == int.class) {
+        return Expressions.call(BuiltInMethod.DATE_TO_INT.method, operand);
+      } else if (toType == Integer.class) {
+        return Expressions.call(BuiltInMethod.DATE_TO_INT_OPTIONAL.method, 
operand);
+      }
+    } else if (fromType == java.sql.Time.class) {
+      if (toType == int.class) {
+        return Expressions.call(BuiltInMethod.TIME_TO_INT.method, operand);
+      } else if (toType == Integer.class) {
+        return Expressions.call(BuiltInMethod.TIME_TO_INT_OPTIONAL.method, 
operand);
+      }
+    } else if (fromType == java.sql.Timestamp.class) {
+      if (toType == long.class) {
+        return Expressions.call(BuiltInMethod.TIMESTAMP_TO_LONG.method, 
operand);
+      } else if (toType == Long.class) {
+        return 
Expressions.call(BuiltInMethod.TIMESTAMP_TO_LONG_OPTIONAL.method, operand);
+      }
+    }
+    return operand;
+  }
+
+  /**
+   * Convert from internal storage types back to {@code java.sql.Date},
+   * {@code java.sql.Time} and {@code java.sql.Timestamp}
+   */
+  private static Expression fromInternalType(Expression operand,
+      Type fromType, Type toType) {
 
 Review comment:
   There is already a method `EnumUtils#fromInternal(Expression, Class)`, can 
we fix that method and just use it ? Or reuse this logic in 
`EnumUtils#fromInternal(Expression, Class)`.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to