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

mihaibudiu 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 82cfd34a56 [CALCITE-7691] The behavior of SESSION table functions is 
unspecified for NULL timestamps
82cfd34a56 is described below

commit 82cfd34a56cf3e6db996039a4e81e80878598a66
Author: krooswu <[email protected]>
AuthorDate: Sat Aug 22 11:41:38 2026 +0800

    [CALCITE-7691] The behavior of SESSION table functions is unspecified for 
NULL timestamps
---
 .../apache/calcite/adapter/enumerable/EnumUtils.java |  3 +++
 core/src/test/resources/sql/stream.iq                | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java
index fd60a29ae7..0aaf1f64fe 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java
@@ -1218,6 +1218,9 @@ private void initialize() {
       Map<@Nullable Object, NavigableMap<Pair<Long, Long>, List<@Nullable 
Object[]>>>
           sessionKeyMap = new HashMap<>();
       for (@Nullable Object[] element : elements) {
+        if (element[indexOfWatermarkedColumn] == null) {
+          continue;
+        }
         // A key column index of -1 means that there is no key; every element
         // then maps to the same (null) key, forming one session timeline.
         Object key = indexOfKeyColumn < 0 ? null : element[indexOfKeyColumn];
diff --git a/core/src/test/resources/sql/stream.iq 
b/core/src/test/resources/sql/stream.iq
index 4328a63cca..2c3e58af1d 100644
--- a/core/src/test/resources/sql/stream.iq
+++ b/core/src/test/resources/sql/stream.iq
@@ -374,3 +374,23 @@ SELECT * FROM TABLE(
 (3 rows)
 
 !ok
+
+# Test case for [CALCITE-7691] SESSION table function should drop rows
+# with a NULL timestamp rather than throwing.
+SELECT * FROM TABLE(
+  SESSION(
+    (SELECT * FROM (VALUES
+      (TIMESTAMP '2020-01-01 10:00:00', 'a'),
+      (CAST(NULL AS TIMESTAMP), 'a'),
+      (TIMESTAMP '2020-01-01 10:05:00', 'a')) AS T(TS, UID)),
+    DESCRIPTOR(TS), DESCRIPTOR(UID), INTERVAL '15' MINUTE))
+ORDER BY TS;
++---------------------+-----+---------------------+---------------------+
+| TS                  | UID | window_start        | window_end          |
++---------------------+-----+---------------------+---------------------+
+| 2020-01-01 10:00:00 | a   | 2020-01-01 10:00:00 | 2020-01-01 10:20:00 |
+| 2020-01-01 10:05:00 | a   | 2020-01-01 10:00:00 | 2020-01-01 10:20:00 |
++---------------------+-----+---------------------+---------------------+
+(2 rows)
+
+!ok

Reply via email to