rubenada commented on code in PR #6720:
URL: https://github.com/apache/hive/pull/6720#discussion_r3881584792
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRemoveEmptySingleRules.java:
##########
@@ -270,85 +114,40 @@ public void onMatch(RelOptRuleCall call) {
.toRule();
public static final RelOptRule UNION_INSTANCE =
- new HiveUnionEmptyPruneRuleConfig()
+ new UnionEmptyPruneRuleConfig()
.withOperandSupplier(b0 ->
b0.operand(HiveUnion.class).unorderedInputs(b1 ->
b1.operand(Values.class)
.predicate(Values::isEmpty).noInputs()))
.withDescription("HivePruneEmptyUnionBranch")
.toRule();
- /**
- * Copy of {@link PruneEmptyRules.UnionEmptyPruneRuleConfig} but this
version expects {@link Union}.
- */
- private static final class HiveUnionEmptyPruneRuleConfig extends
HiveRuleConfig implements PruneEmptyRules.PruneEmptyRule.Config {
- @Override
- public PruneEmptyRules.PruneEmptyRule toRule() {
- return new PruneEmptyRules.PruneEmptyRule(this) {
- @Override public void onMatch(RelOptRuleCall call) {
- if (Bug.CALCITE_5293_FIXED) {
- throw new IllegalStateException(
- "Class HiveUnionEmptyPruneRuleConfig is redundant after
fix is merged into Calcite");
- }
+ private static final class RemoveEmptySingleRuleConfig extends HiveRuleConfig
+ implements RemoveEmptySingleRule.RemoveEmptySingleRuleConfig {
+ }
- final Union union = call.rel(0);
- final List<RelNode> inputs = union.getInputs();
- assert inputs != null;
- final RelBuilder builder = call.builder();
- int nonEmptyInputs = 0;
- for (RelNode input : inputs) {
- if (!isEmpty(input)) {
- builder.push(input);
- nonEmptyInputs++;
- }
- }
- assert nonEmptyInputs < inputs.size()
- : "planner promised us at least one Empty child: "
- + RelOptUtil.toString(union);
- if (nonEmptyInputs == 0) {
- builder.push(union).empty();
- } else {
- builder.union(union.all, nonEmptyInputs);
- builder.convert(union.getRowType(), true);
- }
- call.transformTo(builder.build());
- }
- };
- }
+ private static final class SortFetchZeroRuleConfig extends HiveRuleConfig
+ implements PruneEmptyRules.SortFetchZeroRuleConfig {
}
- private static boolean isEmpty(RelNode node) {
- if (Bug.CALCITE_5293_FIXED) {
- throw new IllegalStateException(
- "Method HiveRemoveEmptySingleRules.isEmpty is redundant after
fix is merged into Calcite");
- }
+ private static final class UnionEmptyPruneRuleConfig extends HiveRuleConfig
+ implements PruneEmptyRules.UnionEmptyPruneRuleConfig {
+ }
- if (node instanceof Values) {
- return ((Values) node).getTuples().isEmpty();
- }
- if (node instanceof HepRelVertex) {
- return isEmpty(((HepRelVertex) node).getCurrentRel());
- }
- // Note: relation input might be a RelSubset, so we just iterate over the
relations
- // in order to check if the subset is equivalent to an empty relation.
- if (!(node instanceof RelSubset)) {
- return false;
- }
- RelSubset subset = (RelSubset) node;
- for (RelNode rel : subset.getRels()) {
- if (isEmpty(rel)) {
- return true;
- }
- }
- return false;
+ private static final class JoinLeftEmptyRuleConfig extends HiveRuleConfig
+ implements PruneEmptyRules.JoinLeftEmptyRuleConfig {
}
Review Comment:
I think it can be done, on it....
BTW, I noticed there's getJoinRightInstance for HiveJoin, HiveSemiJoin and
HiveAntiJoin; but for getJoinLeftInstance there's only HiveJoin, HiveSemiJoin.
Is there a specific reason why HiveAntiJoin is not considered for
JoinLeftEmptyRule?
Was it intentional or just a slip?
If we refactor to use the above suggestion, we will also get
JoinLeftEmptyRule for Anti...
--
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]