You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by li...@apache.org on 2022/08/04 00:51:30 UTC

[calcite] branch main updated: [CALCITE-5178] Single column with ROW type generates wrong plan

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

libenchao 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 35eb99f9d0 [CALCITE-5178] Single column with ROW type generates wrong plan
35eb99f9d0 is described below

commit 35eb99f9d0a3acc42eeb69382948373fc910e18b
Author: Benchao Li <li...@gmail.com>
AuthorDate: Sun Jun 26 22:05:42 2022 +0800

    [CALCITE-5178] Single column with ROW type generates wrong plan
    
    This closes #2843
---
 .../calcite/adapter/enumerable/JavaRowFormat.java     |  6 ++++++
 core/src/test/resources/sql/sub-query.iq              | 19 +++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
index 8b76e592ea..e94869749a 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
@@ -27,6 +27,7 @@ import org.apache.calcite.linq4j.tree.Types;
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.runtime.FlatLists;
 import org.apache.calcite.runtime.Unit;
+import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.util.BuiltInMethod;
 
 import org.checkerframework.checker.nullness.qual.Nullable;
@@ -82,6 +83,11 @@ public enum JavaRowFormat {
         JavaTypeFactory typeFactory,
         RelDataType type) {
       assert type.getFieldCount() == 1;
+      RelDataType field0Type = type.getFieldList().get(0).getType();
+      // nested ROW type is always represented as array.
+      if (field0Type.getSqlTypeName() == SqlTypeName.ROW) {
+        return Object[].class;
+      }
       return typeFactory.getJavaClass(
           type.getFieldList().get(0).getType());
     }
diff --git a/core/src/test/resources/sql/sub-query.iq b/core/src/test/resources/sql/sub-query.iq
index 2d4936b696..35f8e05c76 100644
--- a/core/src/test/resources/sql/sub-query.iq
+++ b/core/src/test/resources/sql/sub-query.iq
@@ -3462,4 +3462,23 @@ where NOT EXISTS (select count(*) from emp e having false);
 EnumerableTableScan(table=[[scott, DEPT]])
 !plan
 
+# Test case about nested row
+select (select (1, 2));
++--------+
+| EXPR$0 |
++--------+
+| {1, 2} |
++--------+
+(1 row)
+
+!ok
+
+EnumerableCalc(expr#0..1=[{inputs}], EXPR$0=[$t1])
+  EnumerableNestedLoopJoin(condition=[true], joinType=[left])
+    EnumerableValues(tuples=[[{ 0 }]])
+    EnumerableAggregate(group=[{}], agg#0=[SINGLE_VALUE($0)])
+      EnumerableCalc(expr#0=[{inputs}], expr#1=[1], expr#2=[2], expr#3=[ROW($t1, $t2)], EXPR$0=[$t3])
+        EnumerableValues(tuples=[[{ 0 }]])
+!plan
+
 # End sub-query.iq