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 03ffb28815 [CALCITE-6853] Nested window aggregate throws 
UnsupportedOperationException with the default ValidatorConfig
03ffb28815 is described below

commit 03ffb2881536a8d4ebf99c64f8c9bd14d44190d5
Author: Marty <[email protected]>
AuthorDate: Wed Feb 26 11:39:27 2025 +0800

    [CALCITE-6853] Nested window aggregate throws UnsupportedOperationException 
with the default ValidatorConfig
---
 .../java/org/apache/calcite/sql2rel/SqlToRelConverter.java  |  1 +
 .../java/org/apache/calcite/test/SqlToRelConverterTest.java | 12 ++++++++++++
 .../org/apache/calcite/test/SqlToRelConverterTest.xml       | 13 +++++++++++++
 3 files changed, 26 insertions(+)

diff --git 
a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java 
b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index 9d26e34b18..52a1cfc46d 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -2246,6 +2246,7 @@ private RexNode convertLambda(Blackboard bb, SqlNode 
node) {
 
   private RexNode convertOver(Blackboard bb, SqlNode node) {
     SqlCall call = (SqlCall) node;
+    bb.getValidator().deriveType(bb.scope, call);
     SqlCall aggCall = call.operand(0);
     boolean ignoreNulls = false;
     switch (aggCall.getKind()) {
diff --git 
a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java 
b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
index 2fc58b40da..2fc6ec0d36 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -45,6 +45,7 @@
 import org.apache.calcite.sql.validate.SqlConformance;
 import org.apache.calcite.sql.validate.SqlConformanceEnum;
 import org.apache.calcite.sql.validate.SqlDelegatingConformance;
+import org.apache.calcite.sql.validate.SqlValidatorUtil;
 import org.apache.calcite.test.catalog.MockCatalogReaderExtended;
 import org.apache.calcite.util.Bug;
 import org.apache.calcite.util.TestUtil;
@@ -5388,6 +5389,17 @@ void checkUserDefinedOrderByOver(NullCollation 
nullCollation) {
         .ok();
   }
 
+  @Test void testNestedWindowAggWithIdentifierExpansionDisabled() {
+    String sql = "select sum(sum(sal)) over() from emp";
+    sql(sql)
+        .withFactory(f ->
+            f.withValidator((opTab, catalogReader, typeFactory, config)
+                -> SqlValidatorUtil.newValidator(opTab, catalogReader,
+                typeFactory, config.withIdentifierExpansion(false))))
+        .withTrim(false)
+        .ok();
+  }
+
   /** Test case for
    * <a 
href="https://issues.apache.org/jira/browse/CALCITE-6214";>[CALCITE-6214]
    * Remove DISTINCT in COUNT if field is unique</a>. */
diff --git 
a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml 
b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
index 1e5d15bc5c..78f0f6a769 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -5261,6 +5261,19 @@ LogicalProject(SKILL=[ROW($0)])
   LogicalFilter(condition=[=($0, '')])
     LogicalProject(TYPE=[$0.TYPE])
       LogicalTableScan(table=[[CATALOG, SALES, DEPT_SINGLE]])
+]]>
+    </Resource>
+  </TestCase>
+  <TestCase name="testNestedWindowAggWithIdentifierExpansionDisabled">
+    <Resource name="sql">
+      <![CDATA[select sum(sum(sal)) over() from emp]]>
+    </Resource>
+    <Resource name="plan">
+      <![CDATA[
+LogicalProject(EXPR$0=[CASE(>(COUNT($0) OVER (), 0), SUM($0) OVER (), 
null:INTEGER)])
+  LogicalAggregate(group=[{}], agg#0=[SUM($0)])
+    LogicalProject(SAL=[$5])
+      LogicalTableScan(table=[[CATALOG, SALES, EMP]])
 ]]>
     </Resource>
   </TestCase>

Reply via email to