Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@ private RelNode tryRestructure(RelNode root, RelNode flattened) {
.projectNamed(structuringExps, resultFieldNames, true)
.build();
restructured = RelOptUtil.copyRelHints(flattened, restructured);
// REVIEW jvs 23-Mar-2005: How do we make sure that this
// implementation stays in Java? Fennel can't handle
// structured types.
return restructured;
} else {
return flattened;
Expand Down Expand Up @@ -513,7 +510,10 @@ public void rewriteRel(LogicalCorrelate rel) {
}

public void rewriteRel(Collect rel) {
rewriteGeneric(rel);
// Flattening does not rewrite collection element types
final RelNode newInput =
tryRestructure(rel.getInput(), getNewForOldRel(rel.getInput()));
setNewForOldRel(rel, rel.copy(rel.getTraitSet(), newInput));
}

public void rewriteRel(Uncollect rel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4635,6 +4635,22 @@ void checkCorrelatedMapSubQuery(boolean expand) {
sql(sql).ok();
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-7723">[CALCITE-7723]
* Queries using Collect with ROW results throw AssertionFailure</a>. */
@Test void testArraySubqueryOfNestedRow() {
final String sql = "SELECT ARRAY(SELECT ROW(ROW(1, 2), 3) FROM (VALUES (0)))";
sql(sql).ok();
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-7723">[CALCITE-7723]
* Queries using Collect with ROW results throw AssertionFailure</a>. */
@Test void testMapSubqueryOfNestedRow() {
final String sql = "SELECT MAP(SELECT ROW(1, 2), 'x' FROM (VALUES (0)))";
sql(sql).ok();
}

@Test void testArraySubqueryOrderByProjectedField() {
final String sql = "SELECT ARRAY(SELECT empno FROM emp ORDER BY empno)";
sql(sql).ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,21 @@ LogicalProject(EXPR$0=[$1])
Collect(field=[EXPR$0])
LogicalProject(EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testArraySubqueryOfNestedRow">
<Resource name="sql">
<![CDATA[SELECT ARRAY(SELECT ROW(ROW(1, 2), 3) FROM (VALUES (0)))]]>
</Resource>
<Resource name="plan">
<![CDATA[
LogicalProject(EXPR$0=[$1])
LogicalJoin(condition=[true], joinType=[inner])
LogicalValues(tuples=[[{ 0 }]])
Collect(field=[EXPR$0])
LogicalProject(EXPR$0=[ROW(ROW($0, $1), $2)])
LogicalValues(tuples=[[{ 1, 2, 3 }]])
]]>
</Resource>
</TestCase>
Expand Down Expand Up @@ -5342,6 +5357,21 @@ LogicalProject(DEPTNO=[$7], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testMapSubqueryOfNestedRow">
<Resource name="sql">
<![CDATA[SELECT MAP(SELECT ROW(1, 2), 'x' FROM (VALUES (0)))]]>
</Resource>
<Resource name="plan">
<![CDATA[
LogicalProject(EXPR$0=[$1])
LogicalJoin(condition=[true], joinType=[inner])
LogicalValues(tuples=[[{ 0 }]])
Collect(field=[EXPR$0])
LogicalProject(EXPR$0=[ROW($0, $1)], EXPR$1=[$2])
LogicalValues(tuples=[[{ 1, 2, 'x' }]])
]]>
</Resource>
</TestCase>
Expand Down
Loading