Skip to content

Commit

Permalink
[CALCITE-6703] RelJson cannot handle timestamps prior to 1970-01-25 2…
Browse files Browse the repository at this point in the history
…0:31:23.648
  • Loading branch information
tanclary committed Nov 22, 2024
1 parent d4b7342 commit aea53d9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,15 @@ public RexNode toRex(RelOptCluster cluster, Object o) {
Sarg sarg = sargFromJson((Map) literal, type);
return rexBuilder.makeSearchArgumentLiteral(sarg, type);
}
if (type.getSqlTypeName() == SqlTypeName.SYMBOL) {
SqlTypeName sqlTypeName = type.getSqlTypeName();
if (sqlTypeName == SqlTypeName.SYMBOL) {
literal = RelEnumTypes.toEnum((String) literal);
}
if (sqlTypeName == SqlTypeName.TIMESTAMP || sqlTypeName == SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE) {
if (literal instanceof Integer) {
literal = ((Integer) literal).longValue();
}
}
return rexBuilder.makeLiteral(literal, type);
}
if (map.containsKey("sargLiteral")) {
Expand Down
47 changes: 47 additions & 0 deletions core/src/test/java/org/apache/calcite/plan/RelWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,53 @@ private static Fixture relFn(Function<RelBuilder, RelNode> relFn) {
.assertThatPlan(isLinux(expected));
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-6703">[CALCITE-6703]
* RelJson cannot handle timestamps prior to 1970-01-25 20:31:23.648</a>. */
@Test void testJsonToRexForTimestamp() {
final String timestampRepresentedAsInt = "{\n"

Check failure on line 747 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 17)

[Task :core:checkstyleTest] [Indentation] 'method def' child has incorrect indentation level 6, expected level should be 4.

Check failure on line 747 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Avatica main)

[Task :core:checkstyleTest] [Indentation] 'method def' child has incorrect indentation level 6, expected level should be 4.

Check failure on line 747 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 23)

[Task :core:checkstyleTest] [Indentation] 'method def' child has incorrect indentation level 6, expected level should be 4.

Check failure on line 747 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, oldest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] 'method def' child has incorrect indentation level 6, expected level should be 4.

Check failure on line 747 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 21)

[Task :core:checkstyleTest] [Indentation] 'method def' child has incorrect indentation level 6, expected level should be 4.

Check failure on line 747 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Pacific/Chatham Timezone)

[Task :core:checkstyleTest] [Indentation] 'method def' child has incorrect indentation level 6, expected level should be 4.

Check failure on line 747 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, latest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] 'method def' child has incorrect indentation level 6, expected level should be 4.

Check failure on line 747 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / macOS (JDK 21)

[Task :core:checkstyleTest] [Indentation] 'method def' child has incorrect indentation level 6, expected level should be 4.
+ " \"literal\": 2129400000,\n"

Check failure on line 748 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 17)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 748 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Avatica main)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 748 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 23)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 748 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, oldest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 748 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 21)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 748 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Pacific/Chatham Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 748 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, latest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 748 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / macOS (JDK 21)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.
+ " \"type\": {\n"

Check failure on line 749 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 17)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 749 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Avatica main)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 749 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 23)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 749 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, oldest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 749 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 21)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 749 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Pacific/Chatham Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 749 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, latest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 749 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / macOS (JDK 21)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.
+ " \"type\": \"TIMESTAMP\",\n"

Check failure on line 750 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 17)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 750 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Avatica main)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 750 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 23)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 750 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, oldest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 750 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 21)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 750 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Pacific/Chatham Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 750 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, latest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 750 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / macOS (JDK 21)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.
+ " \"nullable\": false\n"

Check failure on line 751 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 17)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 751 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Avatica main)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 751 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 23)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 751 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, oldest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 751 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 21)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 751 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Pacific/Chatham Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 751 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, latest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 751 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / macOS (JDK 21)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.
+ " }\n"

Check failure on line 752 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 17)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 752 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Avatica main)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 752 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 23)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 752 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, oldest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 752 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 21)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 752 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Pacific/Chatham Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 752 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, latest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 752 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / macOS (JDK 21)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.
+ "}\n";

Check failure on line 753 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 17)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 753 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Avatica main)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 753 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 23)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 753 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, oldest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 753 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 21)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 753 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 11, Pacific/Chatham Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 753 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / Linux (JDK 8, latest Guava, America/New_York Timezone)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.

Check failure on line 753 in core/src/test/java/org/apache/calcite/plan/RelWriterTest.java

View workflow job for this annotation

GitHub Actions / macOS (JDK 21)

[Task :core:checkstyleTest] [Indentation] '+' has incorrect indentation level 8, expected level should be 10.
final String timestampRepresentedAsLong = "{\n"
+ " \"literal\": 3129400000,\n"
+ " \"type\": {\n"
+ " \"type\": \"TIMESTAMP\",\n"
+ " \"nullable\": false\n"
+ " }\n"
+ "}\n";

assertThatReadExpressionResult(timestampRepresentedAsInt, is("1970-01-25 15:30:00"));
assertThatReadExpressionResult(timestampRepresentedAsLong, is("1970-02-06 05:16:40"));
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-6703">[CALCITE-6703]
* RelJson cannot handle timestamps prior to 1970-01-25 20:31:23.648</a>. */
@Test void testJsonToRexForTimestampWithLocalTimeZone() {
final String timestampWithLocalTzRepresentedAsInt = "{\n"
+ " \"literal\": 2129400000,\n"
+ " \"type\": {\n"
+ " \"type\": \"TIMESTAMP_WITH_LOCAL_TIME_ZONE\",\n"
+ " \"nullable\": false\n"
+ " }\n"
+ "}\n";
final String timestampWithLocalTzRepresentedAsLong = "{\n"
+ " \"literal\": 3129400000,\n"
+ " \"type\": {\n"
+ " \"type\": \"TIMESTAMP_WITH_LOCAL_TIME_ZONE\",\n"
+ " \"nullable\": false\n"
+ " }\n"
+ "}\n";

assertThatReadExpressionResult(timestampWithLocalTzRepresentedAsInt, is("1970-01-25 15:30:00:TIMESTAMP_WITH_LOCAL_TIME_ZONE(0)"));
assertThatReadExpressionResult(timestampWithLocalTzRepresentedAsLong, is("1970-02-06 05:16:40:TIMESTAMP_WITH_LOCAL_TIME_ZONE(0)"));
}


@Test void testJsonToRex() {
// Test simple literal without inputs
final String jsonString1 = "{\n"
Expand Down

0 comments on commit aea53d9

Please sign in to comment.