kasakrisz commented on code in PR #4253:
URL: https://github.com/apache/hive/pull/4253#discussion_r1176385809


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRemoveEmptySingleRules.java:
##########
@@ -192,6 +178,79 @@ public interface JoinRightEmptyRuleConfig extends 
PruneEmptyRule.Config {
     }
   }
 
+  private static RelNode padWithNulls(RelBuilder builder, RelNode input, 
RelDataType resultType,
+      boolean leftPadding) {
+    int padding = resultType.getFieldCount() - 
input.getRowType().getFieldCount();
+    List<RexNode> nullLiterals = Collections.nCopies(padding, 
builder.literal(null));
+    builder.push(input);
+    if (leftPadding) {
+      builder.project(concat(nullLiterals, builder.fields()));
+    } else {
+      builder.project(concat(builder.fields(), nullLiterals));
+    }
+    return builder.convert(resultType, true).build();
+  }
+
+  public static final RelOptRule CORRELATE_RIGHT_INSTANCE = 
RelRule.Config.EMPTY
+      .withOperandSupplier(b0 ->
+          b0.operand(Correlate.class).inputs(
+              b1 -> b1.operand(RelNode.class).anyInputs(),
+              b2 -> 
b2.operand(Values.class).predicate(Values::isEmpty).noInputs()))
+      .withDescription("PruneEmptyCorrelate(right)")
+      .withRelBuilderFactory(HiveRelFactories.HIVE_BUILDER)
+      .as(CorrelateEmptyRuleConfig.class)
+      .toRule();
+  public static final RelOptRule CORRELATE_LEFT_INSTANCE = RelRule.Config.EMPTY
+      .withOperandSupplier(b0 ->
+          b0.operand(Correlate.class).inputs(
+              b1 -> 
b1.operand(Values.class).predicate(Values::isEmpty).noInputs(),
+              b2 -> b2.operand(RelNode.class).anyInputs()))
+      .withDescription("PruneEmptyCorrelate(left)")
+      .withRelBuilderFactory(HiveRelFactories.HIVE_BUILDER)
+      .as(CorrelateEmptyRuleConfig.class)
+      .toRule();
+  
+  /** Configuration for rule that prunes a correlate if one of its inputs is 
empty. */
+  public interface CorrelateEmptyRuleConfig extends PruneEmptyRule.Config {

Review Comment:
   When the `Values` is on the left side you only need the `Correlate`. The 
also `if` goes away at Calcite upgrade.
   ```
   onMatch(RelOptRuleCall call) {
     final Correlate corr = call.rel(0);
     RelBuilder b = call.builder();
     call.transformTo(b.push(corr).empty().build());
   }
   ```
   I leave this up to you. :)



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to