You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by xu...@apache.org on 2026/09/12 01:09:53 UTC

(calcite) branch main updated: Add test case for [CALCITE-6578] RelToSql throws exception when unparse TIMESTAMPDIFF function

This is an automated email from the ASF dual-hosted git repository.

xuzifu666 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
     new 3ed656c7c2 Add test case for [CALCITE-6578] RelToSql throws exception when unparse TIMESTAMPDIFF function
3ed656c7c2 is described below

commit 3ed656c7c257e397980b511c573a69c5d7fdc082
Author: Yu Xu <12...@qq.com>
AuthorDate: Thu Aug 13 23:04:34 2026 +0800

    Add test case for [CALCITE-6578] RelToSql throws exception when unparse TIMESTAMPDIFF function
---
 .../calcite/rel/rel2sql/RelToSqlConverterTest.java   | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index f0103c90a7..877a1e99ee 100644
--- a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -13427,4 +13427,24 @@ generated, isLinux("SELECT \"$cor0\".\"id\"\n"
                 + "FROM \"SCOTT\".\"EMP\"\n"
                 + "WHERE \"DEPTNO\" = \"t1\".\"DEPTNO\")");
   }
+
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-6578">[CALCITE-6578]
+   * RelToSql throws exception when unparse TIMESTAMPDIFF function</a>. */
+  @Test public void testTimestampDiff() {
+    String query = "SELECT {fn TIMESTAMPDIFF(SQL_TSI_YEAR,"
+        + "TIMESTAMP '2016-01-01 00:00:00', TIMESTAMP '2017-01-01 00:00:00')}";
+    String expected = "SELECT CAST((TIMESTAMP '2017-01-01 00:00:00' -"
+        + " TIMESTAMP '2016-01-01 00:00:00') AS INTEGER)\n"
+        + "FROM (VALUES (0)) AS \"t\" (\"ZERO\")";
+    sql(query).ok(expected);
+  }
+
+  /** Test case for TIMESTAMPDIFF with DATE arguments. */
+  @Test void testTimestampdiff() {
+    String query = "select TIMESTAMPDIFF(day,date '2029-05-06',date '2029-05-07')";
+    String expected = "SELECT CAST((DATE '2029-05-07' - DATE '2029-05-06') AS INTEGER)\n"
+        + "FROM (VALUES (0)) AS \"t\" (\"ZERO\")";
+    sql(query).ok(expected);
+  }
 }