diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveAggregate.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveAggregate.java index 81df3de..27b15df 100644 --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveAggregate.java +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveAggregate.java @@ -39,14 +39,14 @@ public static final HiveAggRelFactory HIVE_AGGR_REL_FACTORY = new HiveAggRelFactory(); // Whether input is already sorted - private boolean bucketedInput; + private Boolean bucketedInput; + public HiveAggregate(RelOptCluster cluster, RelTraitSet traitSet, RelNode child, boolean indicator, ImmutableBitSet groupSet, List groupSets, List aggCalls) throws InvalidRelException { super(cluster, TraitsUtil.getDefaultTraitSet(cluster), child, indicator, groupSet, groupSets, aggCalls); - this.bucketedInput = checkInputCorrectBucketing(child, groupSet); } @Override @@ -72,15 +72,6 @@ public RelOptCost computeSelfCost(RelOptPlanner planner) { return RelMetadataQuery.getNonCumulativeCost(this); } - private static boolean checkInputCorrectBucketing(RelNode child, ImmutableBitSet groupSet) { - return false; - //TODO: Enable this again - /* - return RelMetadataQuery.distribution(child).getKeys(). - containsAll(groupSet.asList()); - */ - } - @Override public double getRows() { return RelMetadataQuery.getDistinctRowCount(this, groupSet, getCluster().getRexBuilder() @@ -88,7 +79,11 @@ public double getRows() { } public boolean isBucketedInput() { - return this.bucketedInput; + if (bucketedInput == null) { + bucketedInput = RelMetadataQuery.distribution(this.getInput()).getKeys(). + containsAll(groupSet.asList()); + } + return bucketedInput; } private static class HiveAggRelFactory implements AggregateFactory { diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveJoin.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveJoin.java index 7feca62..07bd67f 100644 --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveJoin.java +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveJoin.java @@ -66,7 +66,6 @@ public static HiveJoin getJoin(RelOptCluster cluster, RelNode left, RelNode righ Set variablesStopped = Collections.emptySet(); HiveJoin join = new HiveJoin(cluster, null, left, right, condition, joinType, variablesStopped, JoinAlgorithm.NONE, chooseStreamingSide(left,right), null, leftSemiJoin); - join.sortedInputs = checkInputsCorrectOrder(join); return join; } catch (InvalidRelException e) { throw new RuntimeException(e); @@ -120,6 +119,28 @@ public void setJoinCost(RelOptCost joinCost) { } public ImmutableBitSet getSortedInputs() { + if (sortedInputs == null) { + ImmutableBitSet.Builder sortedInputsBuilder = new ImmutableBitSet.Builder(); + JoinPredicateInfo joinPredInfo = HiveCalciteUtil.JoinPredicateInfo. + constructJoinPredicateInfo(this); + List joinKeysInChildren = new ArrayList(); + joinKeysInChildren.add( + ImmutableIntList.copyOf( + joinPredInfo.getProjsFromLeftPartOfJoinKeysInChildSchema())); + joinKeysInChildren.add( + ImmutableIntList.copyOf( + joinPredInfo.getProjsFromRightPartOfJoinKeysInChildSchema())); + + for (int i=0; i joinKeysInChildren = new ArrayList(); - joinKeysInChildren.add( - ImmutableIntList.copyOf( - joinPredInfo.getProjsFromLeftPartOfJoinKeysInChildSchema())); - joinKeysInChildren.add( - ImmutableIntList.copyOf( - joinPredInfo.getProjsFromRightPartOfJoinKeysInChildSchema())); - - for (int i=0; i