/** * Computes the selectivity of a semijoin filter if it is applied on a fact * table. The computation is based on the selectivity of the dimension * table/columns and the number of distinct values in the fact table * columns. * * @param rel semijoin rel * @return calculated selectivity */ public static double computeSemiJoinSelectivity(RelMetadataQuery mq, SemiJoin rel) { return computeSemiJoinSelectivity(mq, rel.getLeft(), rel.getRight(), rel.getLeftKeys(), rel.getRightKeys()); }
/** * Creates a RexNode that stores a selectivity value corresponding to the * selectivity of a semijoin. This can be added to a filter to simulate the * effect of the semijoin during costing, but should never appear in a real * plan since it has no physical implementation. * * @param rel the semijoin of interest * @return constructed rexnode */ public static RexNode makeSemiJoinSelectivityRexNode(RelMetadataQuery mq, SemiJoin rel) { RexBuilder rexBuilder = rel.getCluster().getRexBuilder(); double selectivity = computeSemiJoinSelectivity(mq, rel.getLeft(), rel.getRight(), rel); return rexBuilder.makeCall(ARTIFICIAL_SELECTIVITY_FUNC, rexBuilder.makeApproxLiteral(new BigDecimal(selectivity))); }
/** * Computes the selectivity of a semijoin filter if it is applied on a fact * table. The computation is based on the selectivity of the dimension * table/columns and the number of distinct values in the fact table * columns. * * @param rel semijoin rel * @return calculated selectivity */ public static double computeSemiJoinSelectivity(RelMetadataQuery mq, SemiJoin rel) { return computeSemiJoinSelectivity(mq, rel.getLeft(), rel.getRight(), rel.getLeftKeys(), rel.getRightKeys()); }
/** * Creates a RexNode that stores a selectivity value corresponding to the * selectivity of a semijoin. This can be added to a filter to simulate the * effect of the semijoin during costing, but should never appear in a real * plan since it has no physical implementation. * * @param rel the semijoin of interest * @return constructed rexnode */ public static RexNode makeSemiJoinSelectivityRexNode(RelMetadataQuery mq, SemiJoin rel) { RexBuilder rexBuilder = rel.getCluster().getRexBuilder(); double selectivity = computeSemiJoinSelectivity(mq, rel.getLeft(), rel.getRight(), rel); return rexBuilder.makeCall(ARTIFICIAL_SELECTIVITY_FUNC, rexBuilder.makeApproxLiteral(new BigDecimal(selectivity))); }
public void onMatch(RelOptRuleCall call) { SemiJoin semiJoin = call.rel(0); LogicalFilter filter = call.rel(1); RelNode newSemiJoin = SemiJoin.create(filter.getInput(), semiJoin.getRight(), semiJoin.getCondition(), semiJoin.getLeftKeys(), semiJoin.getRightKeys()); final RelFactories.FilterFactory factory = RelFactories.DEFAULT_FILTER_FACTORY; RelNode newFilter = factory.createFilter(newSemiJoin, filter.getCondition()); call.transformTo(newFilter); } }
OpAttr dispatch(RelNode rn) throws SemanticException { if (rn instanceof HiveTableScan) { return visit((HiveTableScan) rn); } else if (rn instanceof HiveProject) { return visit((HiveProject) rn); } else if (rn instanceof MultiJoin) { return visit((MultiJoin) rn); } else if (rn instanceof HiveJoin) { return visit((HiveJoin) rn); } else if (rn instanceof SemiJoin) { SemiJoin sj = (SemiJoin) rn; HiveJoin hj = HiveJoin.getJoin(sj.getCluster(), sj.getLeft(), sj.getRight(), sj.getCondition(), sj.getJoinType(), true); return visit(hj); } else if (rn instanceof HiveFilter) { return visit((HiveFilter) rn); } else if (rn instanceof HiveSort) { return visit((HiveSort) rn); } else if (rn instanceof HiveUnion) { return visit((HiveUnion) rn); } else if (rn instanceof HiveSortExchange) { return visit((HiveSortExchange) rn); } else if (rn instanceof HiveAggregate) { return visit((HiveAggregate) rn); } LOG.error(rn.getClass().getCanonicalName() + "operator translation not supported" + " yet in return path."); return null; }
public void onMatch(RelOptRuleCall call) { SemiJoin semiJoin = call.rel(0); LogicalFilter filter = call.rel(1); RelNode newSemiJoin = SemiJoin.create(filter.getInput(), semiJoin.getRight(), semiJoin.getCondition(), semiJoin.getLeftKeys(), semiJoin.getRightKeys()); final RelFactories.FilterFactory factory = RelFactories.DEFAULT_FILTER_FACTORY; RelNode newFilter = factory.createFilter(newSemiJoin, filter.getCondition()); call.transformTo(newFilter); } }
RelNode rightChild = semiJoin.getRight();
public void onMatch(RelOptRuleCall call) { SemiJoin semiJoin = call.rel(0); LogicalProject project = call.rel(1); // Convert the LHS semi-join keys to reference the child projection // expression; all projection expressions must be RexInputRefs, // otherwise, we wouldn't have created this semi-join. final List<Integer> newLeftKeys = new ArrayList<>(); final List<Integer> leftKeys = semiJoin.getLeftKeys(); final List<RexNode> projExprs = project.getProjects(); for (int leftKey : leftKeys) { RexInputRef inputRef = (RexInputRef) projExprs.get(leftKey); newLeftKeys.add(inputRef.getIndex()); } // convert the semijoin condition to reflect the LHS with the project // pulled up RexNode newCondition = adjustCondition(project, semiJoin); SemiJoin newSemiJoin = SemiJoin.create(project.getInput(), semiJoin.getRight(), newCondition, ImmutableIntList.copyOf(newLeftKeys), semiJoin.getRightKeys()); // Create the new projection. Note that the projection expressions // are the same as the original because they only reference the LHS // of the semijoin and the semijoin only projects out the LHS final RelBuilder relBuilder = call.builder(); relBuilder.push(newSemiJoin); relBuilder.project(projExprs, project.getRowType().getFieldNames()); call.transformTo(relBuilder.build()); }
RelNode rightChild = semiJoin.getRight();
public void onMatch(RelOptRuleCall call) { SemiJoin semiJoin = call.rel(0); LogicalProject project = call.rel(1); // Convert the LHS semi-join keys to reference the child projection // expression; all projection expressions must be RexInputRefs, // otherwise, we wouldn't have created this semi-join. final List<Integer> newLeftKeys = new ArrayList<>(); final List<Integer> leftKeys = semiJoin.getLeftKeys(); final List<RexNode> projExprs = project.getProjects(); for (int leftKey : leftKeys) { RexInputRef inputRef = (RexInputRef) projExprs.get(leftKey); newLeftKeys.add(inputRef.getIndex()); } // convert the semijoin condition to reflect the LHS with the project // pulled up RexNode newCondition = adjustCondition(project, semiJoin); SemiJoin newSemiJoin = SemiJoin.create(project.getInput(), semiJoin.getRight(), newCondition, ImmutableIntList.copyOf(newLeftKeys), semiJoin.getRightKeys()); // Create the new projection. Note that the projection expressions // are the same as the original because they only reference the LHS // of the semijoin and the semijoin only projects out the LHS final RelBuilder relBuilder = call.builder(); relBuilder.push(newSemiJoin); relBuilder.project(projExprs, project.getRowType().getFieldNames()); call.transformTo(relBuilder.build()); }
RelNode rightChild = semiJoin.getRight();
public void onMatch(RelOptRuleCall call) { SemiJoin semiJoin = call.rel(0); LogicalProject project = call.rel(1); // Convert the LHS semi-join keys to reference the child projection // expression; all projection expressions must be RexInputRefs, // otherwise, we wouldn't have created this semi-join. final List<Integer> newLeftKeys = new ArrayList<>(); final List<Integer> leftKeys = semiJoin.getLeftKeys(); final List<RexNode> projExprs = project.getProjects(); for (int leftKey : leftKeys) { RexInputRef inputRef = (RexInputRef) projExprs.get(leftKey); newLeftKeys.add(inputRef.getIndex()); } // convert the semijoin condition to reflect the LHS with the project // pulled up RexNode newCondition = adjustCondition(project, semiJoin); SemiJoin newSemiJoin = SemiJoin.create(project.getInput(), semiJoin.getRight(), newCondition, ImmutableIntList.copyOf(newLeftKeys), semiJoin.getRightKeys(), semiJoin.isAnti); // Create the new projection. Note that the projection expressions // are the same as the original because they only reference the LHS // of the semijoin and the semijoin only projects out the LHS final RelBuilder relBuilder = call.builder(); relBuilder.push(newSemiJoin); relBuilder.project(projExprs, project.getRowType().getFieldNames()); call.transformTo(relBuilder.build()); }
int nFieldsZ = semiJoin.getRight().getRowType().getFieldList().size(); int nTotalFields = nFieldsX + nFieldsY + nFieldsZ; List<RelDataTypeField> fields = new ArrayList<>(); fields.add(joinFields.get(i)); joinFields = semiJoin.getRight().getRowType().getFieldList(); for (int i = 0; i < nFieldsZ; i++) { fields.add(joinFields.get(i)); semiJoin.getRight(), newSemiJoinFilter, ImmutableIntList.copyOf(newLeftKeys),
int nFieldsZ = semiJoin.getRight().getRowType().getFieldList().size(); int nTotalFields = nFieldsX + nFieldsY + nFieldsZ; List<RelDataTypeField> fields = new ArrayList<>(); fields.add(joinFields.get(i)); joinFields = semiJoin.getRight().getRowType().getFieldList(); for (int i = 0; i < nFieldsZ; i++) { fields.add(joinFields.get(i)); semiJoin.getRight(), newSemiJoinFilter, ImmutableIntList.copyOf(newLeftKeys),
int nFieldsZ = semiJoin.getRight().getRowType().getFieldList().size(); int nTotalFields = nFieldsX + nFieldsY + nFieldsZ; List<RelDataTypeField> fields = new ArrayList<RelDataTypeField>(); fields.add(joinFields.get(i)); joinFields = semiJoin.getRight().getRowType().getFieldList(); for (int i = 0; i < nFieldsZ; i++) { fields.add(joinFields.get(i)); semiJoin.getRight(), newSemiJoinFilter, ImmutableIntList.copyOf(newLeftKeys),
final SemiJoin semiJoin = (SemiJoin) rel; final MutableRel left = toMutable(semiJoin.getLeft()); final MutableRel right = toMutable(semiJoin.getRight()); return MutableSemiJoin.of(semiJoin.getRowType(), left, right, semiJoin.getCondition(), semiJoin.getLeftKeys(), semiJoin.getRightKeys());
final SemiJoin semiJoin = (SemiJoin) rel; final MutableRel left = toMutable(semiJoin.getLeft()); final MutableRel right = toMutable(semiJoin.getRight()); return MutableSemiJoin.of(semiJoin.getRowType(), left, right, semiJoin.getCondition(), semiJoin.getLeftKeys(), semiJoin.getRightKeys());