Skip to content

Commit

Permalink
[CALCITE-5178] Single column with ROW type generates wrong plan
Browse files Browse the repository at this point in the history
This closes apache#2843
  • Loading branch information
libenchao committed Aug 4, 2022
1 parent ec903d6 commit 35eb99f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -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());
}
Expand Down
19 changes: 19 additions & 0 deletions core/src/test/resources/sql/sub-query.iq
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 35eb99f

Please sign in to comment.