zabetak commented on code in PR #4253:
URL: https://github.com/apache/hive/pull/4253#discussion_r1176303967
##########
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:
If split in separate classes we would have to duplicate the following
fragment:
```
@Override
default PruneEmptyRule toRule() {
return new PruneEmptyRule(this) {
@Override
public void onMatch(RelOptRuleCall call) {
if (Bug.CALCITE_5669_FIXED) {
throw new IllegalStateException(
"Class is redundant after fix is merged into Calcite");
}
final Correlate corr = call.rel(0);
final RelNode left = call.rel(1);
final RelNode right = call.rel(2);
final RelNode newRel;
RelBuilder b = call.builder();
```
Don't have a strong opinion on this; let me know what you prefer and will do
the refactoring.
##########
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:
If split in separate classes we would have to duplicate the following
fragment:
```java
@Override
default PruneEmptyRule toRule() {
return new PruneEmptyRule(this) {
@Override
public void onMatch(RelOptRuleCall call) {
if (Bug.CALCITE_5669_FIXED) {
throw new IllegalStateException(
"Class is redundant after fix is merged into Calcite");
}
final Correlate corr = call.rel(0);
final RelNode left = call.rel(1);
final RelNode right = call.rel(2);
final RelNode newRel;
RelBuilder b = call.builder();
```
Don't have a strong opinion on this; let me know what you prefer and will do
the refactoring.
--
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]