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/06/18 09:14:40 UTC

[GitHub] [calcite] wenhuitang commented on a change in pull request #1990: [CALCITE-4026] CassandraFilter has generated wrong condition expression for filter with non string literal

wenhuitang commented on a change in pull request #1990:
URL: https://github.com/apache/calcite/pull/1990#discussion_r442085701



##########
File path: core/src/main/java/org/apache/calcite/util/DateTimeStringUtils.java
##########
@@ -25,6 +29,15 @@
 
   private DateTimeStringUtils() {}
 
+  /** The SimpleDateFormat string for ISO timestamps, "yyyy-MM-dd'T'HH:mm:ss'Z'"*/
+  public static final String TIMESTAMP_FORMAT_STRING1 =
+      "yyyy-MM-dd'T'HH:mm:ss'Z'";
+
+  /** The SimpleDateFormat string for ISO timestamps with precisions, "yyyy-MM-dd'T'HH:mm:ss
+   * .SSS'Z'"*/
+  public static final String TIMESTAMP_FORMAT_STRING2 =
+      "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";

Review comment:
       How about ISO_DATETIME_SECONDS_FORMAT_STRING and ISO_DATETIME_MILLISECONDS_FORMAT_STRING?

##########
File path: cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraFilter.java
##########
@@ -174,14 +180,26 @@ private String translateMatch(RexNode condition) {
       }
     }
 
-    /** Convert the value of a literal to a string.
+    /** Returns the value of the literal.
      *
      * @param literal Literal to translate
-     * @return String representation of the literal
+     * @return The value of the literal in the form of the actual type.
      */
-    private static String literalValue(RexLiteral literal) {
-      Object value = literal.getValue2();
-      return String.valueOf(value);
+    private static Object literalValue(RexLiteral literal) {
+      Comparable value = RexLiteral.value(literal);
+      switch (literal.getTypeName()) {
+      case TIMESTAMP:
+      case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
+        assert value instanceof TimestampString;
+        final SimpleDateFormat dateFormatter =
+            getDateFormatter(TIMESTAMP_FORMAT_STRING2);
+        return dateFormatter.format(literal.getValue2());
+      case DATE:
+        assert value instanceof DateString;
+        return value.toString();
+      default:
+        return literal.getValue3();
+      }

Review comment:
       Comparing with getValue2, getValue3 add the processing for type DECIMAL, not much difference. And IMO, getValue3 covered more situations




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