private static JoinType extractJoinType(Join join) { // OUTER AND INNER JOINS JoinType resultJoinType; switch (join.getJoinType()) { case FULL: resultJoinType = JoinType.FULLOUTER; break; case LEFT: resultJoinType = JoinType.LEFTOUTER; break; case RIGHT: resultJoinType = JoinType.RIGHTOUTER; break; default: // TODO: UNIQUE JOIN resultJoinType = JoinType.INNER; break; } return resultJoinType; }
private static JoinType extractJoinType(Join join) { // OUTER AND INNER JOINS JoinType resultJoinType; switch (join.getJoinType()) { case FULL: resultJoinType = JoinType.FULLOUTER; break; case LEFT: resultJoinType = JoinType.LEFTOUTER; break; case RIGHT: resultJoinType = JoinType.RIGHTOUTER; break; default: // TODO: UNIQUE JOIN resultJoinType = JoinType.INNER; break; } return resultJoinType; }
private static double pkSelectivity(Join joinRel, RelMetadataQuery mq, boolean leftChild, RelNode child, double childRowCount) { if ((leftChild && joinRel.getJoinType().generatesNullsOnRight()) || (!leftChild && joinRel.getJoinType().generatesNullsOnLeft())) { return 1.0; } else { HiveTableScan tScan = EstimateUniqueKeys.getTableScan(child, true); if (tScan != null) { double tRowCount = mq.getRowCount(tScan); return childRowCount / tRowCount; } else { return 1.0; } } }
public Double getSelectivity(Join j, RelMetadataQuery mq, RexNode predicate) { if (j.getJoinType().equals(JoinRelType.INNER)) { return computeInnerJoinSelectivity(j, mq, predicate); } else if (j.getJoinType().equals(JoinRelType.LEFT) || j.getJoinType().equals(JoinRelType.RIGHT)) { double left = mq.getRowCount(j.getLeft()); double right = mq.getRowCount(j.getRight()); double product = left * right; double innerJoinSelectivity = computeInnerJoinSelectivity(j, mq, predicate); if (j.getJoinType().equals(JoinRelType.LEFT)) { return Math.max(innerJoinSelectivity, left/product); } return Math.max(innerJoinSelectivity, right/product); } return 1.0; }
private static double pkSelectivity(Join joinRel, RelMetadataQuery mq, boolean leftChild, RelNode child, double childRowCount) { if ((leftChild && joinRel.getJoinType().generatesNullsOnRight()) || (!leftChild && joinRel.getJoinType().generatesNullsOnLeft())) { return 1.0; } else { HiveTableScan tScan = HiveRelMdUniqueKeys.getTableScan(child, true); if (tScan != null) { double tRowCount = mq.getRowCount(tScan); return childRowCount / tRowCount; } else { return 1.0; } } }
public Double getSelectivity(Join j, RelMetadataQuery mq, RexNode predicate) { if (j.getJoinType().equals(JoinRelType.INNER)) { return computeInnerJoinSelectivity(j, mq, predicate); } else if (j.getJoinType().equals(JoinRelType.LEFT) || j.getJoinType().equals(JoinRelType.RIGHT)) { double left = mq.getRowCount(j.getLeft()); double right = mq.getRowCount(j.getRight()); double product = left * right; double innerJoinSelectivity = computeInnerJoinSelectivity(j, mq, predicate); if (j.getJoinType().equals(JoinRelType.LEFT)) { return Math.max(innerJoinSelectivity, left/product); } return Math.max(innerJoinSelectivity, right/product); } return 1.0; }
@Override public Double getDistinctRowCount(Join rel, RelMetadataQuery mq, ImmutableBitSet groupKey, RexNode predicate) { if (rel instanceof HiveJoin) { HiveJoin hjRel = (HiveJoin) rel; //TODO: Improve this if (rel instanceof SemiJoin) { return mq.getDistinctRowCount(hjRel.getLeft(), groupKey, rel.getCluster().getRexBuilder().makeLiteral(true)); } else { return RelMdUtil.getJoinDistinctRowCount(mq, rel, rel.getJoinType(), groupKey, predicate, true); } } return mq.getDistinctRowCount(rel, groupKey, predicate); }
rightFrame.r, decorrelateExpr(rel.getCondition()), rel.getJoinType());
@Override public Double getDistinctRowCount(Join rel, RelMetadataQuery mq, ImmutableBitSet groupKey, RexNode predicate) { if (rel instanceof HiveJoin) { HiveJoin hjRel = (HiveJoin) rel; //TODO: Improve this if (rel instanceof SemiJoin) { return mq.getDistinctRowCount(hjRel.getLeft(), groupKey, rel.getCluster().getRexBuilder().makeLiteral(true)); } else { return RelMdUtil.getJoinDistinctRowCount(mq, rel, rel.getJoinType(), groupKey, predicate, true); } } return mq.getDistinctRowCount(rel, groupKey, predicate); }
final RelDataTypeFactory typeFactory = join.getCluster().getTypeFactory(); final RelNode left = join.getLeft(); final JoinRelType joinType = join.getJoinType();
@Override public void onMatch(RelOptRuleCall call) { final Join join = call.rel(0); final RexBuilder rexBuilder = join.getCluster().getRexBuilder(); final RexNode condition = RexUtil.pullFactors(rexBuilder, join.getCondition()); RexNode newCondition = analyzeRexNode(rexBuilder, condition); // If we could not transform anything, we bail out if (newCondition.toString().equals(condition.toString())) { return; } RelNode newNode = join.copy(join.getTraitSet(), newCondition, join.getLeft(), join.getRight(), join.getJoinType(), join.isSemiJoinDone()); call.transformTo(newNode); } }
@Override public void onMatch(RelOptRuleCall call) { final Join topJoin= call.rel(0); final Join join = call.rel(2); final Aggregate aggregate = call.rel(6); // in presence of grouping sets we can't remove sq_count_check if(aggregate.indicator) { return; } if(isAggregateWithoutGbyKeys(aggregate) || isAggWithConstantGbyKeys(aggregate, call)) { // join(left, join.getRight) RelNode newJoin = HiveJoin.getJoin(topJoin.getCluster(), join.getLeft(), topJoin.getRight(), topJoin.getCondition(), topJoin.getJoinType()); call.transformTo(newJoin); } } }
assert registry != null; if (join.getJoinType() != JoinRelType.INNER) { return; lChild, rChild, join.getJoinType(), join.isSemiJoinDone()); call.getPlanner().onCopy(join, newJoin);
Join swappedJoin = (Join)builder.push(join.getRight()).push(join.getLeft()).join(join.getJoinType(), newJoinCond).build();
if (join.getJoinType() == JoinRelType.LEFT) { type = JoinRelType.RIGHT; } else if (join.getJoinType() == JoinRelType.RIGHT) { type = JoinRelType.LEFT; } else { type = join.getJoinType(); ast = ASTBuilder.join(left.ast, right.ast, join.getJoinType(), cond, semiJoin);
if(join.getJoinType() == JoinRelType.LEFT) { if (join.getJoinType() != JoinRelType.INNER) { return;
lChild, rChild, join.getJoinType(), join.isSemiJoinDone()); call.getPlanner().onCopy(join, newRel);
final MutableRel right = toMutable(join.getRight()); return MutableJoin.of(join.getCluster(), left, right, join.getCondition(), join.getJoinType(), join.getVariablesSet());
lChild, rChild, join.getJoinType(), join.isSemiJoinDone()); call.getPlanner().onCopy(join, newRel);
if (join.getJoinType() == JoinRelType.LEFT) {