use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.
the class RelMdPercentageOriginalRows method getPercentageOriginalRows.
// Catch-all rule when none of the others apply.
public Double getPercentageOriginalRows(RelNode rel, RelMetadataQuery mq) {
if (rel.getInputs().size() > 1) {
// No generic formula available for multiple inputs.
return null;
}
if (rel.getInputs().size() == 0) {
// Assume no filtering happening at leaf.
return 1.0;
}
RelNode child = rel.getInputs().get(0);
Double childPercentage = mq.getPercentageOriginalRows(child);
if (childPercentage == null) {
return null;
}
// Compute product of percentage filtering from this rel (assuming any
// filtering is the effect of single-table filters) with the percentage
// filtering performed by the child.
Double relPercentage = quotientForPercentage(mq.getRowCount(rel), mq.getRowCount(child));
if (relPercentage == null) {
return null;
}
double percent = relPercentage * childPercentage;
// physical rel
if ((percent < 0.0) || (percent > 1.0)) {
return null;
}
return relPercentage * childPercentage;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.
the class RelMdPopulationSize method getPopulationSize.
public Double getPopulationSize(Union rel, RelMetadataQuery mq, ImmutableBitSet groupKey) {
Double population = 0.0;
for (RelNode input : rel.getInputs()) {
Double subPop = mq.getPopulationSize(input, groupKey);
if (subPop == null) {
return null;
}
population += subPop;
}
return population;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.
the class RelMdPredicates method getPredicates.
/**
* Infers predicates for a Union.
*/
public RelOptPredicateList getPredicates(Union union, RelMetadataQuery mq) {
RexBuilder rexBuilder = union.getCluster().getRexBuilder();
Map<String, RexNode> finalPreds = new HashMap<>();
List<RexNode> finalResidualPreds = new ArrayList<>();
for (int i = 0; i < union.getInputs().size(); i++) {
RelNode input = union.getInputs().get(i);
RelOptPredicateList info = mq.getPulledUpPredicates(input);
if (info.pulledUpPredicates.isEmpty()) {
return RelOptPredicateList.EMPTY;
}
Map<String, RexNode> preds = new HashMap<>();
List<RexNode> residualPreds = new ArrayList<>();
for (RexNode pred : info.pulledUpPredicates) {
final String predDigest = pred.toString();
if (i == 0) {
preds.put(predDigest, pred);
continue;
}
if (finalPreds.containsKey(predDigest)) {
preds.put(predDigest, pred);
} else {
residualPreds.add(pred);
}
}
// Add new residual preds
finalResidualPreds.add(RexUtil.composeConjunction(rexBuilder, residualPreds, false));
// Add those that are not part of the final set to residual
for (Entry<String, RexNode> e : finalPreds.entrySet()) {
if (!preds.containsKey(e.getKey())) {
// This node was in previous union inputs, but it is not in this one
for (int j = 0; j < i; j++) {
finalResidualPreds.set(j, RexUtil.composeConjunction(rexBuilder, Lists.newArrayList(finalResidualPreds.get(j), e.getValue()), false));
}
}
}
// Final preds
finalPreds = preds;
}
List<RexNode> preds = new ArrayList<>(finalPreds.values());
final RelOptCluster cluster = union.getCluster();
final RexExecutor executor = Util.first(cluster.getPlanner().getExecutor(), RexUtil.EXECUTOR);
final RelOptPredicateList predicates = RelOptPredicateList.EMPTY;
final RexSimplify simplify = new RexSimplify(rexBuilder, predicates, true, executor);
RexNode disjPred = simplify.simplifyOrs(finalResidualPreds);
if (!disjPred.isAlwaysTrue()) {
preds.add(disjPred);
}
return RelOptPredicateList.of(rexBuilder, preds);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.
the class RelMdPredicates method getPredicates.
/**
* Infers predicates for an Aggregate.
*
* <p>Pulls up predicates that only contains references to columns in the
* GroupSet. For e.g.
*
* <blockquote><pre>
* inputPullUpExprs : { a > 7, b + c < 10, a + e = 9}
* groupSet : { a, b}
* pulledUpExprs : { a > 7}
* </pre></blockquote>
*/
public RelOptPredicateList getPredicates(Aggregate agg, RelMetadataQuery mq) {
final RelNode input = agg.getInput();
final RexBuilder rexBuilder = agg.getCluster().getRexBuilder();
final RelOptPredicateList inputInfo = mq.getPulledUpPredicates(input);
final List<RexNode> aggPullUpPredicates = new ArrayList<>();
ImmutableBitSet groupKeys = agg.getGroupSet();
if (groupKeys.isEmpty()) {
// no rows!) but not on the output (there is one row).
return RelOptPredicateList.EMPTY;
}
Mapping m = Mappings.create(MappingType.PARTIAL_FUNCTION, input.getRowType().getFieldCount(), agg.getRowType().getFieldCount());
int i = 0;
for (int j : groupKeys) {
m.set(j, i++);
}
for (RexNode r : inputInfo.pulledUpPredicates) {
ImmutableBitSet rCols = RelOptUtil.InputFinder.bits(r);
if (groupKeys.contains(rCols)) {
r = r.accept(new RexPermuteInputsShuttle(m, input));
aggPullUpPredicates.add(r);
}
}
return RelOptPredicateList.of(rexBuilder, aggPullUpPredicates);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.
the class RelMdPredicates method getPredicates.
/**
* Infers predicates for a {@link org.apache.calcite.rel.core.Join} (including
* {@link org.apache.calcite.rel.core.SemiJoin}).
*/
public RelOptPredicateList getPredicates(Join join, RelMetadataQuery mq) {
RelOptCluster cluster = join.getCluster();
RexBuilder rexBuilder = cluster.getRexBuilder();
final RexExecutor executor = Util.first(cluster.getPlanner().getExecutor(), RexUtil.EXECUTOR);
final RelNode left = join.getInput(0);
final RelNode right = join.getInput(1);
final RelOptPredicateList leftInfo = mq.getPulledUpPredicates(left);
final RelOptPredicateList rightInfo = mq.getPulledUpPredicates(right);
final RexSimplify simplifier = new RexSimplify(rexBuilder, RelOptPredicateList.EMPTY, true, executor);
JoinConditionBasedPredicateInference joinInference = new JoinConditionBasedPredicateInference(join, RexUtil.composeConjunction(rexBuilder, leftInfo.pulledUpPredicates, false), RexUtil.composeConjunction(rexBuilder, rightInfo.pulledUpPredicates, false), simplifier);
return joinInference.inferPredicates(false);
}
Aggregations