This is an automated email from the ASF dual-hosted git repository.
mbudiu 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 18454caf1d [CALCITE-7435] WINDOW functions should allow ORDER BY
fields of type INTERVAL
18454caf1d is described below
commit 18454caf1d76c787d5547de00744284ddc71cbce
Author: Mihai Budiu <[email protected]>
AuthorDate: Mon Mar 9 14:35:04 2026 -0700
[CALCITE-7435] WINDOW functions should allow ORDER BY fields of type
INTERVAL
Signed-off-by: Mihai Budiu <[email protected]>
---
.../org/apache/calcite/sql/type/SqlTypeFamily.java | 4 ++++
core/src/test/resources/sql/winagg.iq | 24 ++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeFamily.java
b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeFamily.java
index 0e9b14e35c..396932555a 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeFamily.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeFamily.java
@@ -160,6 +160,10 @@ public List<SqlTypeFamily> allowableDifferenceTypes() {
switch (this) {
case NUMERIC:
return ImmutableList.of(NUMERIC);
+ case INTERVAL_DAY_TIME:
+ return ImmutableList.of(INTERVAL_DAY_TIME);
+ case INTERVAL_YEAR_MONTH:
+ return ImmutableList.of(INTERVAL_YEAR_MONTH);
case DATE:
case TIME:
case TIMESTAMP:
diff --git a/core/src/test/resources/sql/winagg.iq
b/core/src/test/resources/sql/winagg.iq
index beb90d9fd4..6a32b3b3f7 100644
--- a/core/src/test/resources/sql/winagg.iq
+++ b/core/src/test/resources/sql/winagg.iq
@@ -18,6 +18,30 @@
!use post
!set outputformat mysql
+# Test case for [CALCITE-7435] WINDOW functions should allow ORDER BY fields
of type INTERVAL
+# This result has been validated on Postgres by slightly changing the query
(subtraction is different in Postgres)
+WITH
+T(ts, l) AS (VALUES(TIMESTAMP '2020-01-01 10:00:00', 10),
+ (TIMESTAMP '2020-02-01 10:00:00', 10),
+ (TIMESTAMP '2019-12-30 20:00:00', 10)),
+IT AS (SELECT(ts - TIMESTAMP '2020-01-01 00:00:00') HOURS AS t, l FROM T)
+SELECT *,
+ COUNT(*) OVER (
+ PARTITION BY l
+ ORDER BY t
+ RANGE BETWEEN INTERVAL 2 DAYS PRECEDING AND INTERVAL 1 DAYS PRECEDING)
AS c
+FROM It;
++------+----+---+
+| T | L | C |
++------+----+---+
+| +10 | 10 | 1 |
+| -28 | 10 | 0 |
+| +754 | 10 | 0 |
++------+----+---+
+(3 rows)
+
+!ok
+
# Multiple window functions sharing a single window
select count(*) over(partition by gender order by ename) as count1,
count(*) over(partition by deptno order by ename) as count2,