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..bea5eec 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 @@ -38,15 +38,13 @@ public static final HiveAggRelFactory HIVE_AGGR_REL_FACTORY = new HiveAggRelFactory(); - // Whether input is already sorted - 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 +70,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 +77,8 @@ public double getRows() { } public boolean isBucketedInput() { - return this.bucketedInput; + return RelMetadataQuery.distribution(this.getInput()).getKeys(). + containsAll(groupSet.asList()); } 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..96e5cc5 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 @@ -57,16 +57,14 @@ private JoinAlgorithm joinAlgorithm; private MapJoinStreamingRelation mapJoinStreamingSide; private RelOptCost joinCost; - // Whether inputs are already sorted - private ImmutableBitSet sortedInputs; + public static HiveJoin getJoin(RelOptCluster cluster, RelNode left, RelNode right, RexNode condition, JoinRelType joinType, boolean leftSemiJoin) { try { 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); + JoinAlgorithm.NONE, chooseStreamingSide(left,right), leftSemiJoin); return join; } catch (InvalidRelException e) { throw new RuntimeException(e); @@ -76,12 +74,11 @@ public static HiveJoin getJoin(RelOptCluster cluster, RelNode left, RelNode righ protected HiveJoin(RelOptCluster cluster, RelTraitSet traits, RelNode left, RelNode right, RexNode condition, JoinRelType joinType, Set variablesStopped, JoinAlgorithm joinAlgo, MapJoinStreamingRelation streamingSideForMapJoin, - ImmutableBitSet sortedInputs, boolean leftSemiJoin) throws InvalidRelException { + boolean leftSemiJoin) throws InvalidRelException { super(cluster, TraitsUtil.getDefaultTraitSet(cluster), left, right, condition, joinType, variablesStopped); this.joinAlgorithm = joinAlgo; this.mapJoinStreamingSide = streamingSideForMapJoin; - this.sortedInputs = sortedInputs; this.leftSemiJoin = leftSemiJoin; } @@ -95,7 +92,7 @@ public final HiveJoin copy(RelTraitSet traitSet, RexNode conditionExpr, RelNode try { Set variablesStopped = Collections.emptySet(); return new HiveJoin(getCluster(), traitSet, left, right, conditionExpr, joinType, - variablesStopped, joinAlgorithm, mapJoinStreamingSide, sortedInputs, leftSemiJoin); + variablesStopped, joinAlgorithm, mapJoinStreamingSide, leftSemiJoin); } catch (InvalidRelException e) { // Semantic error not possible. Must be a bug. Convert to // internal error. @@ -120,7 +117,26 @@ public void setJoinCost(RelOptCost joinCost) { } public ImmutableBitSet getSortedInputs() { - return sortedInputs; + 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