You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "letian-jiang (via GitHub)" <gi...@apache.org> on 2026/10/17 09:43:47 UTC

[PR] [CALCITE-7864] RANGE window frames should handle NULL ORDER BY keys [calcite]

letian-jiang opened a new pull request, #5337:
URL: https://github.com/apache/calcite/pull/5337

   
   ## Jira Link
   
   [CALCITE-7864](https://issues.apache.org/jira/browse/CALCITE-7864)
   
   ## Changes Proposed
   
   Fix a NullPointerException when evaluating RANGE window frames with offset bounds and NULL ORDER BY keys.
   
   Guard boundary arithmetic for nullable keys and preserve NULL as the boundary search key. Explicitly box the non-NULL result to prevent implicit unboxing in the conditional expression.
   
   For NULL keys, offset lower and upper bounds resolve to the first and last NULL peers, respectively. UNBOUNDED endpoints retain their partition-boundary behavior.
   
   For example:
   
   ```sql
   SELECT k,
          SUM(v) OVER (
            ORDER BY k NULLS LAST
            RANGE BETWEEN 1 PRECEDING AND CURRENT ROW
          ) AS s
   FROM (VALUES (1, 10), (2, 20),
                (CAST(NULL AS INTEGER), 100), (NULL, 200)) AS t(k, v)
   ```
   
   Previously, this query threw a NullPointerException. It now returns `(1, 10), (2, 30), (NULL, 300), (NULL, 300)`, ignoring row order.
   
   Add 28 parameterized regression cases covering INTEGER/BIGINT, NULLS FIRST/LAST, offsets at both frame endpoints, and combinations with CURRENT ROW and UNBOUNDED bounds.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-7864] RANGE window frames should handle NULL ORDER BY keys [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #5337:
URL: https://github.com/apache/calcite/pull/5337#discussion_r4305055763


##########
core/src/test/java/org/apache/calcite/adapter/enumerable/EnumerableWindowTest.java:
##########
@@ -47,6 +52,64 @@
  * Test for {@link org.apache.calcite.adapter.enumerable.EnumerableWindow}.
  */
 public class EnumerableWindowTest {
+  @ParameterizedTest
+  @MethodSource("rangeNullableOrderKeyCases")
+  void testRangeNullableOrderKey(String type, String nulls, String frame,
+      String sum1, String sum2, String sum4, String sumNull) {
+    CalciteAssert.that()
+        .query("select k, sum(v) over (order by k nulls " + nulls
+            + " range between " + frame + ") as s\n"
+            + "from (values (cast(1 as " + type + "), 10), (2, 20), (4, 40),\n"
+            + "  (cast(null as " + type + "), 100), (null, 200)) as t(k, v)")
+        .explainContains("EnumerableWindow")
+        .returnsUnordered("K=1; S=" + sum1,
+            "K=2; S=" + sum2,
+            "K=4; S=" + sum4,
+            "K=null; S=" + sumNull,
+            "K=null; S=" + sumNull);
+  }
+
+  private static List<Arguments> rangeNullableOrderKeyCases() {
+    final List<Arguments> cases = new ArrayList<>();
+    for (String type : new String[] {"integer", "bigint"}) {
+      for (String nulls : new String[] {"first", "last"}) {
+        // Cover PRECEDING and FOLLOWING for both the lower and upper bounds.
+        cases.add(

Review Comment:
   how did you validate these expected results?
   Please add a comment explaining.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-7864] RANGE window frames should handle NULL ORDER BY keys [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu merged PR #5337:
URL: https://github.com/apache/calcite/pull/5337


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-7864] RANGE window frames should handle NULL ORDER BY keys [calcite]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #5337:
URL: https://github.com/apache/calcite/pull/5337#issuecomment-6232630187

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5337) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5337&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5337&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=5337&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=5337&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=5337&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5337)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-7864] RANGE window frames should handle NULL ORDER BY keys [calcite]

Posted by "letian-jiang (via GitHub)" <gi...@apache.org>.
letian-jiang commented on PR #5337:
URL: https://github.com/apache/calcite/pull/5337#issuecomment-6246022964

   Thanks for the review! I’ve squashed the commits into a single commit: c1916ebcc.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-7864] RANGE window frames should handle NULL ORDER BY keys [calcite]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #5337:
URL: https://github.com/apache/calcite/pull/5337#issuecomment-6246222880

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5337) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5337&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5337&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=5337&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=5337&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=5337&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5337)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-7864] RANGE window frames should handle NULL ORDER BY keys [calcite]

Posted by "letian-jiang (via GitHub)" <gi...@apache.org>.
letian-jiang commented on code in PR #5337:
URL: https://github.com/apache/calcite/pull/5337#discussion_r4305108418


##########
core/src/test/java/org/apache/calcite/adapter/enumerable/EnumerableWindowTest.java:
##########
@@ -47,6 +52,64 @@
  * Test for {@link org.apache.calcite.adapter.enumerable.EnumerableWindow}.
  */
 public class EnumerableWindowTest {
+  @ParameterizedTest
+  @MethodSource("rangeNullableOrderKeyCases")
+  void testRangeNullableOrderKey(String type, String nulls, String frame,
+      String sum1, String sum2, String sum4, String sumNull) {
+    CalciteAssert.that()
+        .query("select k, sum(v) over (order by k nulls " + nulls
+            + " range between " + frame + ") as s\n"
+            + "from (values (cast(1 as " + type + "), 10), (2, 20), (4, 40),\n"
+            + "  (cast(null as " + type + "), 100), (null, 200)) as t(k, v)")
+        .explainContains("EnumerableWindow")
+        .returnsUnordered("K=1; S=" + sum1,
+            "K=2; S=" + sum2,
+            "K=4; S=" + sum4,
+            "K=null; S=" + sumNull,
+            "K=null; S=" + sumNull);
+  }
+
+  private static List<Arguments> rangeNullableOrderKeyCases() {
+    final List<Arguments> cases = new ArrayList<>();
+    for (String type : new String[] {"integer", "bigint"}) {
+      for (String nulls : new String[] {"first", "last"}) {
+        // Cover PRECEDING and FOLLOWING for both the lower and upper bounds.
+        cases.add(

Review Comment:
   Thanks for the review. I ran all 28 SQL cases against PostgreSQL 14.24 and confirmed that all 140 result rows match the expected results, ignoring row order while preserving duplicate NULL-key rows. I also added a comment documenting the verification method and PostgreSQL version in d6df043c8.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-7864] RANGE window frames should handle NULL ORDER BY keys [calcite]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #5337:
URL: https://github.com/apache/calcite/pull/5337#issuecomment-6243880017

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5337) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5337&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5337&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=5337&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=5337&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=5337&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5337)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org