You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2023/01/25 03:36:04 UTC
[calcite] 01/02: [CALCITE-5491] Allow TIME and DATE to be args for TIMESTAMPDIFF
This is an automated email from the ASF dual-hosted git repository.
jhyde pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
commit c4c0bf344b02cb7065a8d9539b4f6cda9a9e6f50
Author: Sergey Nuyanzin <sn...@gmail.com>
AuthorDate: Mon Jan 23 23:05:53 2023 +0100
[CALCITE-5491] Allow TIME and DATE to be args for TIMESTAMPDIFF
This fixes a regression introduced by [CALCITE-5423].
Close apache/calcite#3041
---
.../apache/calcite/sql/fun/SqlStdOperatorTable.java | 4 ++--
.../org/apache/calcite/test/SqlOperatorTest.java | 21 +++++++++++++++++++--
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java
index 950a103680..e5604775f7 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java
@@ -1903,8 +1903,8 @@ public class SqlStdOperatorTable extends ReflectiveSqlOperatorTable {
/** The <code>TIMESTAMPDIFF</code> function. */
public static final SqlFunction TIMESTAMP_DIFF =
new SqlTimestampDiffFunction("TIMESTAMPDIFF",
- OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.TIMESTAMP,
- SqlTypeFamily.TIMESTAMP));
+ OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.DATETIME,
+ SqlTypeFamily.DATETIME));
/**
* Use of the <code>IN_FENNEL</code> operator forces the argument to be
diff --git a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
index 0a9bf1f46f..a93771e3a0 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
@@ -78,6 +78,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import java.math.BigDecimal;
@@ -8129,8 +8131,11 @@ public class SqlOperatorTest {
isNullValue(), "INTEGER"));
}
- @Test void testTimestampDiff() {
- final SqlOperatorFixture f = fixture();
+ @ValueSource(booleans = {true, false})
+ @ParameterizedTest(name = "CoercionEnabled: {0}")
+ void testTimestampDiff(boolean coercionEnabled) {
+ final SqlOperatorFixture f = fixture()
+ .withValidatorConfig(c -> c.withTypeCoercionEnabled(coercionEnabled));
f.setFor(SqlStdOperatorTable.TIMESTAMP_DIFF, VmName.EXPAND);
HOUR_VARIANTS.forEach(s ->
f.checkScalar("timestampdiff(" + s + ", "
@@ -8211,6 +8216,18 @@ public class SqlOperatorTest {
f.checkScalar("timestampdiff(" + s + ", "
+ "date '2019-09-01', date '2016-08-01')",
"-37", "INTEGER NOT NULL"));
+ MONTH_VARIANTS.forEach(s ->
+ f.checkScalar("timestampdiff(" + s + ", "
+ + "time '12:42:25', time '12:42:25')",
+ "0", "INTEGER NOT NULL"));
+ MONTH_VARIANTS.forEach(s ->
+ f.checkScalar("timestampdiff(" + s + ", "
+ + "time '12:42:25', date '2016-06-14')",
+ "-1502389", "INTEGER NOT NULL"));
+ MONTH_VARIANTS.forEach(s ->
+ f.checkScalar("timestampdiff(" + s + ", "
+ + "date '2016-06-14', time '12:42:25')",
+ "1502389", "INTEGER NOT NULL"));
DAY_VARIANTS.forEach(s ->
f.checkScalar("timestampdiff(" + s + ", "
+ "date '2016-06-15', date '2016-06-14')",