@Override public void onMatch(RelOptRuleCall call) {
          if (Bug.CALCITE_5294_FIXED) {
            throw new IllegalStateException(
                    "Class JoinLeftEmptyRuleConfig is redundant after fix is merged into Calcite");
          }

          final Join join = call.rel(0);
          final RelNode right = call.rel(2);
          final RelBuilder relBuilder = call.builder();
          if (join.getJoinType().generatesNullsOnLeft()) {
            // If "emp" is empty, "select * from emp right join dept" will have
            // the same number of rows as "dept", and null values for the
            // columns from "emp". The left side of the join can be removed.
            call.transformTo(padWithNulls(relBuilder, right, join.getRowType(), true));
            return;
          }
          call.transformTo(relBuilder.push(join).empty().build());
        }
Improved version of Calcite's {@link PruneEmptyRules.JoinLeftEmptyRuleConfig}.
In case of right outer join if the left branch is empty the join operator can be removed
and take the right branch only.

select * from (select * from emp where 1=0) right join dept
to
select null as emp.col0 ... null as emp.coln, dept.* from dept
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRemoveEmptySingleRules.java