iwanttobepowerful commented on code in PR #4766:
URL: https://github.com/apache/calcite/pull/4766#discussion_r2782282968
##########
core/src/test/java/org/apache/calcite/sql2rel/RelDecorrelatorTest.java:
##########
@@ -208,6 +208,101 @@ public static Frameworks.ConfigBuilder config() {
assertThat(after, hasTree(planAfter));
}
+ /** Test case for <a
href="https://issues.apache.org/jira/browse/CALCITE-7057">[CALCITE-7057]
+ * NPE when decorrelating query containing nested correlated subqueries</a>.
*/
+ @Test void test7057() {
+ final FrameworkConfig frameworkConfig = config().build();
+ final RelBuilder builder = RelBuilder.create(frameworkConfig);
+ final RelOptCluster cluster = builder.getCluster();
+ final Planner planner = Frameworks.getPlanner(frameworkConfig);
+ final String sql = ""
+ + "select\n"
+ + " (select ename || ' from dept '\n"
+ + " || (select dname from dept where deptno = emp.deptno and emp.empno
= empnos.empno)\n"
+ + " from emp\n"
+ + " ) as ename_from_dept\n"
+ + "from (values (7369), (7499)) as empnos(empno) order by 1";
+ final RelNode originalRel;
+ try {
+ final SqlNode parse = planner.parse(sql);
+ final SqlNode validate = planner.validate(parse);
+ originalRel = planner.rel(validate).rel;
+ } catch (Exception e) {
+ throw TestUtil.rethrow(e);
+ }
+
+ final HepProgram hepProgram = HepProgram.builder()
+ .addRuleCollection(
+ ImmutableList.of(
+ // SubQuery program rules
+ CoreRules.FILTER_SUB_QUERY_TO_CORRELATE,
+ CoreRules.PROJECT_SUB_QUERY_TO_CORRELATE,
+ CoreRules.JOIN_SUB_QUERY_TO_CORRELATE))
+ .build();
+ final Program program =
+ Programs.of(hepProgram, true,
+ requireNonNull(cluster.getMetadataProvider()));
+ final RelNode before =
+ program.run(cluster.getPlanner(), originalRel, cluster.traitSet(),
+ Collections.emptyList(), Collections.emptyList());
+
+ // before fix:
+ //
+ // LogicalSort(sort0=[$0], dir0=[ASC])
+ // LogicalProject(ENAME_FROM_DEPT=[$1])
+ // LogicalCorrelate(correlation=[$cor2], joinType=[left],
requiredColumns=[{0}])
+ // LogicalValues(tuples=[[{ 7369 }, { 7499 }]])
+ // LogicalAggregate(group=[{}], agg#0=[SINGLE_VALUE($0)])
+ // LogicalProject(EXPR$0=[||(||($1, ' from dept '), $8)])
+ // LogicalJoin(condition=[true], joinType=[left],
variablesSet=[[$cor0, $cor2]])
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]