Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit d962b78

Browse files
committed
Update to Calcite 1.35
* Implicit Timestamp casts should increase, not reduce precision
1 parent f8f2009 commit d962b78

File tree

4 files changed

+80
-60
lines changed

4 files changed

+80
-60
lines changed

omniscidb/Calcite/java/calcite/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<dependency>
6161
<groupId>org.apache.calcite</groupId>
6262
<artifactId>calcite-core</artifactId>
63-
<version>1.33.0</version>
63+
<version>1.35.0</version>
6464
<exclusions>
6565
<exclusion>
6666
<groupId>org.pentaho</groupId>
@@ -183,7 +183,7 @@
183183
<plugin>
184184
<groupId>org.apache.maven.plugins</groupId>
185185
<artifactId>maven-dependency-plugin</artifactId>
186-
<version>3.5.0</version>
186+
<version>3.6.0</version>
187187
<executions>
188188
<execution>
189189
<!-- Extract parser grammar template from calcite-core and put
@@ -211,7 +211,7 @@
211211
<plugin>
212212
<groupId>org.apache.drill.tools</groupId>
213213
<artifactId>drill-fmpp-maven-plugin</artifactId>
214-
<version>1.21.0</version>
214+
<version>1.21.1</version>
215215
<executions>
216216
<execution>
217217
<configuration>

omniscidb/Calcite/java/calcite/src/main/codegen/config.fmpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,12 @@ data: {
591591
dropStatementParserMethods: [
592592
]
593593

594+
# List of methods for parsing extensions to "TRUNCATE" calls.
595+
# Each must accept arguments "(SqlParserPos pos)".
596+
# Example: "SqlTruncate".
597+
truncateStatementParserMethods: [
598+
]
599+
594600
# Binary operators tokens
595601
binaryOperatorsTokens: [
596602
]
@@ -612,6 +618,10 @@ data: {
612618
"ddlParser.ftl"
613619
]
614620

621+
# Custom identifier token.
622+
# Example: "< IDENTIFIER: (<LETTER>|<DIGIT>)+ >".
623+
customIdentifierToken: ""
624+
615625
includePosixOperators: false
616626
includeParsingStringLiteralAsArrayLiteral: false
617627
includeCompoundIdentifier: true

omniscidb/Calcite/java/calcite/src/main/java/org/apache/calcite/rel/externalize/MapDRelJsonReader.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,14 @@ private AggregateCall toAggCall(RelInput relInput, Map<String, Object> jsonAggCa
306306
final String name = (String) jsonAggCall.get("name");
307307
return AggregateCall.create(aggregation,
308308
distinct,
309-
false,
310-
false,
309+
/*approximate=*/false,
310+
/*ignoreNulls=*/false,
311311
operands,
312312
filterOperand == null ? -1 : filterOperand,
313-
null,
314-
RelCollations.EMPTY,
313+
/*distinctKeys=*/null,
314+
/*collation=*/RelCollations.EMPTY,
315+
/*groupCount=*/operands.size(),
316+
/*input=*/relInput.getInput(),
315317
type,
316318
name);
317319
}

omniscidb/Tests/ArrowBasedExecuteTest.cpp

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13169,8 +13169,13 @@ TEST_F(Select, TimestampPrecision_HighPrecision) {
1316913169
v<int64_t>(run_simple_agg("select count(*) from test where m_3 = m;", dt)));
1317013170
ASSERT_EQ(0,
1317113171
v<int64_t>(run_simple_agg("select count(*) from test where m_3 < m;", dt)));
13172-
ASSERT_EQ(20,
13172+
// increasing precision should result in 0 rows passing the filter, since the lower
13173+
// precision value is appended with zeros in higher precision
13174+
ASSERT_EQ(0,
1317313175
v<int64_t>(run_simple_agg("select count(*) from test where m = m_3;", dt)));
13176+
ASSERT_EQ(20,
13177+
v<int64_t>(run_simple_agg(
13178+
"select count(*) from test where m = CAST(m_3 AS TIMESTAMP(0));", dt)));
1317413179
ASSERT_EQ(0,
1317513180
v<int64_t>(run_simple_agg("select count(*) from test where m > m_3;", dt)));
1317613181
ASSERT_EQ(20,
@@ -13212,8 +13217,11 @@ TEST_F(Select, TimestampPrecision_HighPrecision) {
1321213217
v<int64_t>(run_simple_agg("select count(*) from test where m > m_6;", dt)));
1321313218
ASSERT_EQ(10,
1321413219
v<int64_t>(run_simple_agg("select count(*) from test where m < m_6;", dt)));
13215-
ASSERT_EQ(10,
13220+
ASSERT_EQ(0,
1321613221
v<int64_t>(run_simple_agg("select count(*) from test where m = m_6;", dt)));
13222+
ASSERT_EQ(10,
13223+
v<int64_t>(run_simple_agg(
13224+
"select count(*) from test where m = CAST(m_6 AS TIMESTAMP(0));", dt)));
1321713225

1321813226
ASSERT_EQ(
1321913227
10, v<int64_t>(run_simple_agg("select count(*) from test where m_9 > m_3;", dt)));
@@ -13238,8 +13246,11 @@ TEST_F(Select, TimestampPrecision_HighPrecision) {
1323813246
v<int64_t>(run_simple_agg("select count(*) from test where m > m_9;", dt)));
1323913247
ASSERT_EQ(10,
1324013248
v<int64_t>(run_simple_agg("select count(*) from test where m < m_9;", dt)));
13241-
ASSERT_EQ(10,
13249+
ASSERT_EQ(0,
1324213250
v<int64_t>(run_simple_agg("select count(*) from test where m = m_9;", dt)));
13251+
ASSERT_EQ(10,
13252+
v<int64_t>(run_simple_agg(
13253+
"select count(*) from test where m = CAST(m_9 AS TIMESTAMP(0));", dt)));
1324313254
ASSERT_EQ(
1324413255
15,
1324513256
v<int64_t>(run_simple_agg(
@@ -13401,21 +13412,18 @@ TEST_F(Select, TimestampPrecision_FunctionCompositions) {
1340113412
ASSERT_EQ(
1340213413
1,
1340313414
v<int64_t>(run_simple_agg(
13404-
"select dateadd('minute',1,dateadd('millisecond',1,cast(m_3 as "
13405-
"timestamp(0)))) = TIMESTAMP(3) '2014-12-13 22:24:15.456' from test limit 1;",
13415+
R"(select dateadd('minute',1,dateadd('millisecond',1,cast(m_3 as timestamp(0)))) = TIMESTAMP(0) '2014-12-13 22:24:15' from test limit 1;)",
1340613416
dt)));
1340713417
ASSERT_EQ(
1340813418
1,
1340913419
v<int64_t>(run_simple_agg(
13410-
"select dateadd('minute',1, dateadd('millisecond',111 , cast(m_6 as "
13411-
"timestamp(0)))) = TIMESTAMP(3) '1999-07-11 14:03:53.985' from test limit 1;",
13420+
R"(select dateadd('minute',1, dateadd('millisecond',111 , cast(m_6 as timestamp(0)))) = TIMESTAMP(3) '1999-07-11 14:03:53' from test limit 1;)",
13421+
dt)));
13422+
ASSERT_EQ(
13423+
1,
13424+
v<int64_t>(run_simple_agg(
13425+
R"(select dateadd('year',1,dateadd('millisecond',220,cast(m_9 as timestamp(0)))) = TIMESTAMP(3) '2007-04-26 03:49:04' from test limit 1;)",
1341213426
dt)));
13413-
ASSERT_EQ(1,
13414-
v<int64_t>(run_simple_agg(
13415-
"select dateadd('year',1,dateadd('millisecond',220,cast(m_9 as "
13416-
"timestamp(0)))) = TIMESTAMP(3) '2007-04-26 03:49:04.827' from test "
13417-
"limit 1;",
13418-
dt)));
1341913427
ASSERT_EQ(
1342013428
1,
1342113429
v<int64_t>(run_simple_agg(
@@ -13531,16 +13539,16 @@ TEST_F(Select, TimestampPrecision_FunctionsWithHighPrecisionsAndDates) {
1353113539
"SELECT count(*) from test where PG_DATE_TRUNC('millisecond', m_9) = "
1353213540
"TIMESTAMP(3) '2006-04-26 03:49:04.607435125';",
1353313541
dt)));
13534-
ASSERT_EQ(10,
13535-
v<int64_t>(run_simple_agg(
13536-
"SELECT count(*) from test where PG_DATE_TRUNC('nanosecond', m_6) = "
13537-
"TIMESTAMP(9) '1999-07-11 14:02:53.874533123';",
13538-
dt)));
13539-
ASSERT_EQ(10,
13540-
v<int64_t>(run_simple_agg(
13541-
"SELECT count(*) from test where PG_DATE_TRUNC('microsecond', m_6) = "
13542-
"TIMESTAMP(9) '1999-07-11 14:02:53.874533123';",
13543-
dt)));
13542+
ASSERT_EQ(
13543+
10,
13544+
v<int64_t>(run_simple_agg(
13545+
R"(SELECT count(*) from test where PG_DATE_TRUNC('nanosecond', m_6) = TIMESTAMP(9) '1999-07-11 14:02:53.874533';)",
13546+
dt)));
13547+
ASSERT_EQ(
13548+
10,
13549+
v<int64_t>(run_simple_agg(
13550+
R"(SELECT count(*) from test where PG_DATE_TRUNC('microsecond', m_6) = TIMESTAMP(9) '1999-07-11 14:02:53.874533';)",
13551+
dt)));
1354413552
ASSERT_EQ(10,
1354513553
v<int64_t>(run_simple_agg(
1354613554
"SELECT count(*) from test where PG_DATE_TRUNC('microsecond', m_6) = "
@@ -13556,37 +13564,38 @@ TEST_F(Select, TimestampPrecision_FunctionsWithHighPrecisionsAndDates) {
1355613564
"SELECT count(*) from test where PG_DATE_TRUNC('millisecond', m_6) = "
1355713565
"TIMESTAMP(3) '1999-07-11 14:02:53.874533123';",
1355813566
dt)));
13559-
ASSERT_EQ(15,
13560-
v<int64_t>(run_simple_agg(
13561-
"SELECT count(*) from test where PG_DATE_TRUNC('nanosecond', m_3) = "
13562-
"TIMESTAMP(9) '2014-12-13 22:23:15.323533123';",
13563-
dt)));
13564-
ASSERT_EQ(15,
13565-
v<int64_t>(run_simple_agg(
13566-
"SELECT count(*) from test where PG_DATE_TRUNC('microsecond', m_3) = "
13567-
"TIMESTAMP(9) '2014-12-13 22:23:15.323533123';",
13568-
dt)));
13569-
ASSERT_EQ(15,
13570-
v<int64_t>(run_simple_agg(
13571-
"SELECT count(*) from test where PG_DATE_TRUNC('microsecond', m_3) = "
13572-
"TIMESTAMP(6) '2014-12-13 22:23:15.323533123';",
13573-
dt)));
13574-
ASSERT_EQ(15,
13575-
v<int64_t>(run_simple_agg(
13576-
"SELECT count(*) from test where PG_DATE_TRUNC('millisecond', m_3) = "
13577-
"TIMESTAMP(6) '2014-12-13 22:23:15.323533123';",
13578-
dt)));
13579-
ASSERT_EQ(15,
13580-
v<int64_t>(run_simple_agg(
13581-
"SELECT count(*) from test where PG_DATE_TRUNC('millisecond', m_3) = "
13582-
"TIMESTAMP(3) '2014-12-13 22:23:15.323533123';",
13583-
dt)));
13567+
// the underling column is millisecond, so the high precision timestamps are no-ops
13568+
// regardless of the date-trunc type.
13569+
ASSERT_EQ(
13570+
15,
13571+
v<int64_t>(run_simple_agg(
13572+
R"(SELECT count(*) from test where PG_DATE_TRUNC('nanosecond', m_3) = TIMESTAMP(9) '2014-12-13 22:23:15.323';)",
13573+
dt)));
13574+
ASSERT_EQ(
13575+
15,
13576+
v<int64_t>(run_simple_agg(
13577+
R"(SELECT count(*) from test where PG_DATE_TRUNC('microsecond', m_3) = TIMESTAMP(9) '2014-12-13 22:23:15.323';)",
13578+
dt)));
13579+
ASSERT_EQ(
13580+
15,
13581+
v<int64_t>(run_simple_agg(
13582+
R"(SELECT count(*) from test where PG_DATE_TRUNC('microsecond', m_3) = TIMESTAMP(6) '2014-12-13 22:23:15.323';)",
13583+
dt)));
13584+
ASSERT_EQ(
13585+
15,
13586+
v<int64_t>(run_simple_agg(
13587+
R"(SELECT count(*) from test where PG_DATE_TRUNC('millisecond', m_3) = TIMESTAMP(6) '2014-12-13 22:23:15.323';)",
13588+
dt)));
13589+
ASSERT_EQ(
13590+
15,
13591+
v<int64_t>(run_simple_agg(
13592+
R"(SELECT count(*) from test where PG_DATE_TRUNC('millisecond', m_3) = TIMESTAMP(3) '2014-12-13 22:23:15.323';)",
13593+
dt)));
1358413594

1358513595
ASSERT_EQ(
1358613596
10,
1358713597
v<int64_t>(run_simple_agg(
13588-
"SELECT count(*) from test where cast(DATEADD('nanosecond', 101, m_9) as "
13589-
"DATE) = cast(TIMESTAMP(9) '2006-04-26 03:49:04.607435226' as DATE);",
13598+
R"(SELECT count(*) from test where cast(DATEADD('nanosecond', 101, m_9) as DATE) = cast(TIMESTAMP(9) '2006-04-26 03:49:04.607435226' as DATE);)",
1359013599
dt)));
1359113600
ASSERT_EQ(
1359213601
10,
@@ -17301,9 +17310,8 @@ TEST_F(Select, Interop) {
1730117310
std::string part2 = ", y ASC, r1 ASC, r2 ASC, r3 ASC;";
1730217311
c(part1 + " NULLS FIRST" + part2, part1 + part2, dt);
1730317312
}
17304-
c("SELECT CAST(('fake_' || SUBSTRING(real_str, 6)) LIKE '%_ba%' AS INT) b from test "
17305-
"ORDER BY b;",
17306-
"SELECT ('fake_' || SUBSTR(real_str, 6)) LIKE '%_ba%' b from test ORDER BY b;",
17313+
c(R"(SELECT ('fake_' || SUBSTRING(real_str, 6)) LIKE '%_ba%' b from test ORDER BY b;)",
17314+
R"(SELECT ('fake_' || SUBSTR(real_str, 6)) LIKE '%_ba%' b from test ORDER BY b;)",
1730717315
dt);
1730817316
}
1730917317
config().exec.enable_interop = false;

0 commit comments

Comments
 (0)