julianhyde commented on code in PR #2916: URL: https://github.com/apache/calcite/pull/2916#discussion_r976851396
########## core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java: ########## @@ -480,9 +486,25 @@ public interface JoinLeftEmptyRuleConfig extends PruneEmptyRule.Config { return new PruneEmptyRule(this) { @Override public void onMatch(RelOptRuleCall call) { Join join = call.rel(0); + Values empty = call.rel(1); + RelNode right = call.rel(2); + RexBuilder rexBuilder = call.builder().getRexBuilder(); if (join.getJoinType().generatesNullsOnLeft()) { // "select * from emp right join dept" is not necessarily empty if // emp is empty + // join can be removed and take the right branch, all columns come from emp are null + List<RexNode> projects = new ArrayList<>( + empty.getRowType().getFieldCount() + right.getRowType().getFieldCount()); + List<String> columnNames = new ArrayList<>( + empty.getRowType().getFieldCount() + right.getRowType().getFieldCount()); + // left + addNullLiterals(rexBuilder, empty, projects, columnNames); + // right + copyProjects(rexBuilder, right.getRowType(), + join.getRowType(), empty.getRowType().getFieldCount(), projects, columnNames); + + RelNode project = call.builder().push(right).project(projects, columnNames).build(); + call.transformTo(project); Review Comment: Can this be written in a functional style? Rather than creating empty lists then filling them, use `map`. `RelBuilder` has plenty of methods that return lists to types, lists of names, etc. -- 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: commits-unsubscr...@calcite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org