kasakrisz commented on code in PR #2916:
URL: https://github.com/apache/calcite/pull/2916#discussion_r977303067


##########
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:
   Refactored the utility methods to use the Java stream api. I defined stream 
of List<Pair<>> as a return type to ensure the order of expressions.
   If this is not what you mean could you please give some example?
   



-- 
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

Reply via email to