use of org.apache.calcite.plan.RelTrait in project calcite by apache.
the class VolcanoPlanner method changeTraitsUsingConverters.
private RelNode changeTraitsUsingConverters(RelNode rel, RelTraitSet toTraits, boolean allowAbstractConverters) {
final RelTraitSet fromTraits = rel.getTraitSet();
assert fromTraits.size() >= toTraits.size();
final boolean allowInfiniteCostConverters = SaffronProperties.INSTANCE.allowInfiniteCostConverters().get();
// Traits may build on top of another...for example a collation trait
// would typically come after a distribution trait since distribution
// destroys collation; so when doing the conversion below we use
// fromTraits as the trait of the just previously converted RelNode.
// Also, toTraits may have fewer traits than fromTraits, excess traits
// will be left as is. Finally, any null entries in toTraits are
// ignored.
RelNode converted = rel;
for (int i = 0; (converted != null) && (i < toTraits.size()); i++) {
RelTrait fromTrait = converted.getTraitSet().getTrait(i);
final RelTraitDef traitDef = fromTrait.getTraitDef();
RelTrait toTrait = toTraits.getTrait(i);
if (toTrait == null) {
continue;
}
assert traitDef == toTrait.getTraitDef();
// if (fromTrait.subsumes(toTrait)) {
if (fromTrait.equals(toTrait)) {
// No need to convert; it's already correct.
continue;
}
rel = traitDef.convert(this, converted, toTrait, allowInfiniteCostConverters);
if (rel != null) {
assert rel.getTraitSet().getTrait(traitDef).satisfies(toTrait);
rel = completeConversion(rel, allowInfiniteCostConverters, toTraits, Expressions.list(traitDef));
if (rel != null) {
register(rel, converted);
}
}
if ((rel == null) && allowAbstractConverters) {
RelTraitSet stepTraits = converted.getTraitSet().replace(toTrait);
rel = getSubset(converted, stepTraits);
}
converted = rel;
}
// make sure final converted traitset subsumes what was required
if (converted != null) {
assert converted.getTraitSet().satisfies(toTraits);
}
return converted;
}
use of org.apache.calcite.plan.RelTrait in project calcite by apache.
the class VolcanoPlanner method removeRule.
public boolean removeRule(RelOptRule rule) {
if (!ruleSet.remove(rule)) {
// Rule was not present.
return false;
}
// Remove description.
unmapRuleDescription(rule);
// Remove operands.
for (Iterator<RelOptRuleOperand> iter = classOperands.values().iterator(); iter.hasNext(); ) {
RelOptRuleOperand entry = iter.next();
if (entry.getRule().equals(rule)) {
iter.remove();
}
}
// graph.)
if (rule instanceof ConverterRule) {
ConverterRule converterRule = (ConverterRule) rule;
final RelTrait ruleTrait = converterRule.getInTrait();
final RelTraitDef ruleTraitDef = ruleTrait.getTraitDef();
if (traitDefs.contains(ruleTraitDef)) {
ruleTraitDef.deregisterConverterRule(this, converterRule);
}
}
return true;
}
use of org.apache.calcite.plan.RelTrait in project calcite by apache.
the class RelSubset method computeDigest.
@Override
protected String computeDigest() {
StringBuilder digest = new StringBuilder("Subset#");
digest.append(set.id);
for (RelTrait trait : traitSet) {
digest.append('.').append(trait);
}
return digest.toString();
}
use of org.apache.calcite.plan.RelTrait in project druid by druid-io.
the class DruidQueryBuilder method getRelTraits.
public RelTrait[] getRelTraits() {
final List<RelFieldCollation> collations = Lists.newArrayList();
if (limitSpec != null) {
for (OrderByColumnSpec orderBy : limitSpec.getColumns()) {
final int i = outputRowSignature.getRowOrder().indexOf(orderBy.getDimension());
final RelFieldCollation.Direction direction = orderBy.getDirection() == OrderByColumnSpec.Direction.ASCENDING ? RelFieldCollation.Direction.ASCENDING : RelFieldCollation.Direction.DESCENDING;
collations.add(new RelFieldCollation(i, direction));
}
}
if (!collations.isEmpty()) {
return new RelTrait[] { RelCollations.of(collations) };
} else {
return new RelTrait[] {};
}
}
use of org.apache.calcite.plan.RelTrait in project calcite by apache.
the class RelSet method addInternal.
/**
* Adds an expression <code>rel</code> to this set, without creating a
* {@link org.apache.calcite.plan.volcano.RelSubset}. (Called only from
* {@link org.apache.calcite.plan.volcano.RelSubset#add}.
*
* @param rel Relational expression
*/
void addInternal(RelNode rel) {
if (!rels.contains(rel)) {
rels.add(rel);
for (RelTrait trait : rel.getTraitSet()) {
assert trait == trait.getTraitDef().canonize(trait);
}
VolcanoPlanner planner = (VolcanoPlanner) rel.getCluster().getPlanner();
if (planner.listener != null) {
postEquivalenceEvent(planner, rel);
}
}
if (this.rel == null) {
this.rel = rel;
} else {
// Row types must be the same, except for field names.
RelOptUtil.verifyTypeEquivalence(this.rel, rel, this);
}
}
Aggregations