mihaibudiu commented on code in PR #4776:
URL: https://github.com/apache/calcite/pull/4776#discussion_r2737904690
##########
core/src/test/java/org/apache/calcite/sql2rel/RelDecorrelatorTest.java:
##########
@@ -1571,6 +1571,51 @@ public static Frameworks.ConfigBuilder config() {
assertThat(after, hasTree(planAfter));
}
+ /** Test case for <a
href="https://issues.apache.org/jira/browse/CALCITE-5390">[CALCITE-5390]
+ * RelDecorrelator throws NullPointerException</a>. */
+ @Test void test5390() {
+ 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 deptno,\n"
+ + " (select min(1) from emp where empno > d.deptno) as i0,\n"
+ + " (select min(0) from emp where deptno = d.deptno and "
+ + "ename = 'SMITH' and d.deptno > 0) as i1\n"
+ + "from dept as d";
+ 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());
+ System.out.println(before.explain());
+
+ // Decorrelate without any rules, just "purely" decorrelation algorithm on
RelDecorrelator
+ final RelNode after =
+ RelDecorrelator.decorrelateQuery(before, builder,
RuleSets.ofList(Collections.emptyList()),
+ RuleSets.ofList(Collections.emptyList()));
+ System.out.println(after.explain());
Review Comment:
are these println supposed to be here?
I think you want to compare some expected strings.
##########
core/src/test/resources/sql/sub-query.iq:
##########
@@ -8664,5 +8664,78 @@ FROM dept;
+--------+--------+
(4 rows)
+!ok
+
+# [CALCITE-5390] RelDecorrelator throws NullPointerException
Review Comment:
It is very useful to provide this link, but please also add a comment that
will stay in the code forever that the results were validated. This is useful
because we have had incorrect results previously.
##########
core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java:
##########
@@ -3766,12 +3801,14 @@ private RexVisitorImpl<Void> rexVisitor(final RelNode
rel) {
* and where to find the output fields and correlation variables
* among its output fields. */
static class Frame {
+ final RelNode oldRel;
Review Comment:
Please document this field using JavaDoc.
--
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]