/** * Compares two RelTraitSet objects to see if they match for the purposes of * firing a rule. A null RelTrait within a RelTraitSet indicates a wildcard: * any RelTrait in the other RelTraitSet will match. If one RelTraitSet is * smaller than the other, comparison stops when the last RelTrait from the * smaller set has been examined and the remaining RelTraits in the larger * set are assumed to match. * * @param that another RelTraitSet * @return true if the RelTraitSets match, false otherwise */ public boolean matches(RelTraitSet that) { final int n = Math.min( this.size(), that.size()); for (int i = 0; i < n; i++) { RelTrait thisTrait = this.traits[i]; RelTrait thatTrait = that.traits[i]; if ((thisTrait == null) || (thatTrait == null)) { continue; } if (thisTrait != thatTrait) { return false; } } return true; }
/** * Compares two RelTraitSet objects to see if they match for the purposes of * firing a rule. A null RelTrait within a RelTraitSet indicates a wildcard: * any RelTrait in the other RelTraitSet will match. If one RelTraitSet is * smaller than the other, comparison stops when the last RelTrait from the * smaller set has been examined and the remaining RelTraits in the larger * set are assumed to match. * * @param that another RelTraitSet * @return true if the RelTraitSets match, false otherwise */ public boolean matches(RelTraitSet that) { final int n = Math.min( this.size(), that.size()); for (int i = 0; i < n; i++) { RelTrait thisTrait = this.traits[i]; RelTrait thatTrait = that.traits[i]; if ((thisTrait == null) || (thatTrait == null)) { continue; } if (thisTrait != thatTrait) { return false; } } return true; }
/** * Creates a cluster. * * <p>For use only from {@link #create} and {@link RelOptQuery}. */ RelOptCluster(RelOptPlanner planner, RelDataTypeFactory typeFactory, RexBuilder rexBuilder, AtomicInteger nextCorrel, Map<String, RelNode> mapCorrelToRel) { this.nextCorrel = nextCorrel; this.mapCorrelToRel = mapCorrelToRel; this.planner = Objects.requireNonNull(planner); this.typeFactory = Objects.requireNonNull(typeFactory); this.rexBuilder = rexBuilder; this.originalExpression = rexBuilder.makeLiteral("?"); // set up a default rel metadata provider, // giving the planner first crack at everything setMetadataProvider(DefaultRelMetadataProvider.INSTANCE); this.emptyTraitSet = planner.emptyTraitSet(); assert emptyTraitSet.size() == planner.getRelTraitDefs().size(); }
/** * Creates a cluster. * * <p>For use only from {@link #create} and {@link RelOptQuery}. */ RelOptCluster(RelOptPlanner planner, RelDataTypeFactory typeFactory, RexBuilder rexBuilder, AtomicInteger nextCorrel, Map<String, RelNode> mapCorrelToRel) { this.nextCorrel = nextCorrel; this.mapCorrelToRel = mapCorrelToRel; this.planner = Objects.requireNonNull(planner); this.typeFactory = Objects.requireNonNull(typeFactory); this.rexBuilder = rexBuilder; this.originalExpression = rexBuilder.makeLiteral("?"); // set up a default rel metadata provider, // giving the planner first crack at everything setMetadataProvider(DefaultRelMetadataProvider.INSTANCE); this.emptyTraitSet = planner.emptyTraitSet(); assert emptyTraitSet.size() == planner.getRelTraitDefs().size(); }
@Override public void write(final Kryo kryo, final Output output, final RelTraitSet traitSet) { final int size = traitSet.size(); kryo.writeObject(output, size); for (int i = 0; i < size; i++) { final RelTrait trait = traitSet.getTrait(i); kryo.writeClassAndObject(output, trait); } kryo.writeObject(output, traitSet.toString()); try { final Object cache = getField(NAME_CACHE).get(traitSet); kryo.writeClassAndObject(output, cache); } catch (final NoSuchFieldException|IllegalAccessException e) { throw new RuntimeException("unable to read TraitSet", e); } }
/** * Converts a relation expression to a given set of traits, if it does not * already have those traits. * * @param rel Relational expression to convert * @param toTraits desired traits * @return a relational expression with the desired traits; never null */ public static RelNode convert(RelNode rel, RelTraitSet toTraits) { RelOptPlanner planner = rel.getCluster().getPlanner(); if (rel.getTraitSet().size() < toTraits.size()) { new RelTraitPropagationVisitor(planner, toTraits).go(rel); } RelTraitSet outTraits = rel.getTraitSet(); for (int i = 0; i < toTraits.size(); i++) { RelTrait toTrait = toTraits.getTrait(i); if (toTrait != null) { outTraits = outTraits.replace(i, toTrait); } } if (rel.getTraitSet().matches(outTraits)) { return rel; } return planner.changeTraits(rel, outTraits); }
/** * Converts a relation expression to a given set of traits, if it does not * already have those traits. * * @param rel Relational expression to convert * @param toTraits desired traits * @return a relational expression with the desired traits; never null */ public static RelNode convert(RelNode rel, RelTraitSet toTraits) { RelOptPlanner planner = rel.getCluster().getPlanner(); if (rel.getTraitSet().size() < toTraits.size()) { new RelTraitPropagationVisitor(planner, toTraits).go(rel); } RelTraitSet outTraits = rel.getTraitSet(); for (int i = 0; i < toTraits.size(); i++) { RelTrait toTrait = toTraits.getTrait(i); if (toTrait != null) { outTraits = outTraits.replace(i, toTrait); } } if (rel.getTraitSet().matches(outTraits)) { return rel; } return planner.changeTraits(rel, outTraits); }