Skip to content
Open
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 @@ -2677,10 +2677,21 @@ private void convertUnnest(Blackboard bb, SqlCall call, @Nullable List<String> f
RelNode uncollect;
try {
if (validator().config().conformance().allowAliasUnnestItems()) {
// Without an AS column list, mirror SqlUnnestOperator#inferReturnType
// so Uncollect's row type stays aligned with the validator.
List<String> itemAliases;
if (fieldNames != null) {
itemAliases = fieldNames;
} else {
itemAliases = new ArrayList<>(nodes.size());
for (int i = 0; i < nodes.size(); i++) {
itemAliases.add(SqlUtil.deriveAliasFromOrdinal(i));
}
}
uncollect = relBuilder
.push(child)
.project(exprs)
.uncollect(requireNonNull(fieldNames, "fieldNames"), operator.withOrdinality)
.uncollect(itemAliases, operator.withOrdinality)
.build();
} else {
// REVIEW danny 2020-04-26: should we unify the normal field aliases and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,26 @@ public static void checkActualAndReferenceFiles() {
sql(sql).withConformance(SqlConformanceEnum.PRESTO).ok();
}

/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-7546">[CALCITE-7546]
* NullPointerException in SqlToRelConverter for UNNEST(array) AS alias under
* conformance with allowAliasUnnestItems=true</a>.
*/
@Test void testAliasUnnestArrayPlanWithoutColumnList() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither of the test cases here matches the one in the issue, but they look close enough.
I hope that you have validated that the test in the issue passes as well.

final String sql = "select d.deptno, e.empno\n"
+ "from dept_nested_expanded as d,\n"
+ " UNNEST(d.employees) as e";
sql(sql).withConformance(SqlConformanceEnum.PRESTO).ok();
}

@Test void testAliasUnnestScalarArrayPlanWithoutColumnList() {
final String sql = "select d.deptno, a\n"
+ "from dept_nested_expanded as d,\n"
+ " UNNEST(d.admins) as a";
sql(sql).withConformance(SqlConformanceEnum.PRESTO).ok();
}

@Test void testArrayOfRecord() {
sql("select employees[1].detail.skills[2+3].desc from dept_nested").ok();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,40 @@ from dept_nested_expanded as d,
UNNEST(d.employees) as t(employee)]]>
</Resource>
</TestCase>
<TestCase name="testAliasUnnestArrayPlanWithoutColumnList">
<Resource name="sql">
<![CDATA[select d.deptno, e.empno
from dept_nested_expanded as d,
UNNEST(d.employees) as e]]>
</Resource>
<Resource name="plan">
<![CDATA[
LogicalProject(DEPTNO=[$0], EMPNO=[$5.EMPNO])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{2}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED_EXPANDED]])
Uncollect
LogicalProject(EMPLOYEES=[$cor0.EMPLOYEES])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testAliasUnnestScalarArrayPlanWithoutColumnList">
<Resource name="sql">
<![CDATA[select d.deptno, a
from dept_nested_expanded as d,
UNNEST(d.admins) as a]]>
</Resource>
<Resource name="plan">
<![CDATA[
LogicalProject(DEPTNO=[$0], A=[$5])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{3}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED_EXPANDED]])
Uncollect
LogicalProject(ADMINS=[$cor0.ADMINS])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testAliasWithinGroupingSets">
<Resource name="sql">
<![CDATA[SELECT empno / 2 AS x
Expand Down
Loading