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


##########
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:
   The proposed refactoring makes sense and the code is indeed more readable. 
Fixed in 
https://github.com/apache/hive/pull/4253/commits/7cf9e827d7b06b15157825ca65ca40486338841f



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