public void flatten( List<RelNode> rels, int systemFieldCount, int[] start, List<Pair<RelNode, Integer>> relOffsetList) { for (RelNode rel : rels) { if (leaves.contains(rel)) { relOffsetList.add( Pair.of(rel, start[0])); start[0] += rel.getRowType().getFieldCount(); } else { if (rel instanceof JoinRel || rel instanceof AggregateRel) { start[0] += systemFieldCount; } flatten( rel.getInputs(), systemFieldCount, start, relOffsetList); } } }
private static List<RelSubset> inputSubsets(RelNode parent) { //noinspection unchecked return (List<RelSubset>) (List) parent.getInputs(); }
private int countChildren(RelSubset subset) { int count = 0; for (RelNode rel : subset.getRels()) { count += rel.getInputs().size(); } return count; } });
private int countChildren(RelSubset subset) { int count = 0; for (RelNode rel : subset.getRels()) { count += rel.getInputs().size(); } return count; } });
/** * Helper method for computing row count for UNION ALL. * * @param rel node representing UNION ALL * @return estimated row count for rel */ public static double estimateRowCount(RelNode rel) { double dRows = 0; for (RelNode input : rel.getInputs()) { dRows += RelMetadataQuery.getRowCount(input); } return dRows; } }
/** * Helper method for computing row count for UNION ALL. * * @param rel node representing UNION ALL * * @return estimated row count for rel */ public static double estimateRowCount(RelNode rel) { double dRows = 0; for (RelNode input : rel.getInputs()) { dRows += RelMetadataQuery.getRowCount(input); } return dRows; } }
/** * Returns a shallow copy of a relational expression with a particular * input replaced. */ public static RelNode replaceInput( RelNode parent, int ordinal, RelNode newInput) { final List<RelNode> inputs = new ArrayList<RelNode>(parent.getInputs()); if (inputs.get(ordinal) == newInput) { return parent; } inputs.set(ordinal, newInput); return parent.copy(parent.getTraitSet(), inputs); }
public final Object visitChild( RelNode parent, int ordinal, RelNode child) { if (parent != null) { assert child == parent.getInputs().get(ordinal); } createFrame(parent, ordinal, child); return visitChildInternal(child, ordinal, null); }
public final Object visitChild( RelNode parent, int ordinal, RelNode child) { if (parent != null) { assert child == parent.getInputs().get(ordinal); } createFrame(parent, ordinal, child); return visitChildInternal(child, ordinal, null); }
protected RelNode visitChildren(RelNode rel) { for (Ord<RelNode> input : Ord.zip(rel.getInputs())) { rel = visitChild(rel, input.i, input.e); } return rel; }
public RelOptCost getCumulativeCost(RelNode rel) { RelOptCost cost = RelMetadataQuery.getNonCumulativeCost(rel); List<RelNode> inputs = rel.getInputs(); for (int i = 0, n = inputs.size(); i < n; i++) { cost = cost.plus(RelMetadataQuery.getCumulativeCost(inputs.get(i))); } return cost; }
/** Returns the collection of RelNodes one of whose inputs is in this * subset. */ Set<RelNode> getParents() { final Set<RelNode> list = new LinkedHashSet<RelNode>(); for (RelNode parent : set.getParentRels()) { for (RelSubset rel : (List<RelSubset>) (List) parent.getInputs()) { if (rel.set == set && rel.getTraitSet().equals(traitSet)) { list.add(parent); } } } return list; }
public static <T extends RelNode> T addTrait( T rel, RelTrait trait) { //noinspection unchecked return (T) rel.copy( rel.getTraitSet().replace(trait), (List) rel.getInputs()); }
public RelOptCost getCumulativeCost(RelNode rel) { RelOptCost cost = RelMetadataQuery.getNonCumulativeCost(rel); List<RelNode> inputs = rel.getInputs(); for (RelNode input : inputs) { cost = cost.plus(RelMetadataQuery.getCumulativeCost(input)); } return cost; }
public static <T extends RelNode> T addTrait( T rel, RelTrait trait) { //noinspection unchecked return (T) rel.copy( rel.getTraitSet().replace(trait), (List) rel.getInputs()); }
private RelNode buildFinalPlan(HepRelVertex vertex) { RelNode rel = vertex.getCurrentRel(); notifyChosen(rel); // Recursively process children, replacing this rel's inputs // with corresponding child rels. List<RelNode> inputs = rel.getInputs(); for (int i = 0; i < inputs.size(); ++i) { RelNode child = inputs.get(i); if (!(child instanceof HepRelVertex)) { // Already replaced. continue; } child = buildFinalPlan((HepRelVertex) child); rel.replaceInput(i, child); } return rel; }
/** * Visits a particular child of a parent. */ protected RelNode visitChild(RelNode parent, int i, RelNode child) { Stacks.push(stack, parent); try { RelNode child2 = child.accept(this); if (child2 != child) { final List<RelNode> newInputs = new ArrayList<RelNode>(parent.getInputs()); newInputs.set(i, child2); return parent.copy(parent.getTraitSet(), newInputs); } return parent; } finally { Stacks.pop(stack, parent); } }
public RelOptCost getCost(RelNode rel) { assert rel != null : "pre-condition: rel != null"; if (rel instanceof RelSubset) { return ((RelSubset) rel).bestCost; } if (rel.getTraitSet().getTrait(0) == Convention.NONE) { return costFactory.makeInfiniteCost(); } RelOptCost cost = RelMetadataQuery.getNonCumulativeCost(rel); if (!zeroCost.isLt(cost)) { // cost must be positive, so nudge it cost = costFactory.makeTinyCost(); } for (RelNode input : rel.getInputs()) { cost = cost.plus(getCost(input)); } return cost; }