Java Code Examples for org.apache.calcite.rel.convert.ConverterRule#getInTrait()

The following examples show how to use org.apache.calcite.rel.convert.ConverterRule#getInTrait() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VolcanoPlanner.java    From Bats with Apache License 2.0 6 votes vote down vote up
public boolean removeRule(RelOptRule rule) {
  if (!ruleSet.remove(rule)) {
    // Rule was not present.
    return false;
  }

  // Remove description.
  unmapRuleDescription(rule);

  // Remove operands.
  classOperands.values().removeIf(entry -> entry.getRule().equals(rule));

  // Remove trait mappings. (In particular, entries from conversion
  // 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;
}
 
Example 2
Source File: ConventionTraitDef.java    From Bats with Apache License 2.0 6 votes vote down vote up
public void registerConverterRule(
    RelOptPlanner planner,
    ConverterRule converterRule) {
  if (converterRule.isGuaranteed()) {
    ConversionData conversionData = getConversionData(planner);

    final Convention inConvention =
        (Convention) converterRule.getInTrait();
    final Convention outConvention =
        (Convention) converterRule.getOutTrait();
    conversionData.conversionGraph.addVertex(inConvention);
    conversionData.conversionGraph.addVertex(outConvention);
    conversionData.conversionGraph.addEdge(inConvention, outConvention);

    conversionData.mapArcToConverterRule.put(
        Pair.of(inConvention, outConvention), converterRule);
  }
}
 
Example 3
Source File: VolcanoPlanner.java    From calcite with Apache License 2.0 6 votes vote down vote up
public boolean removeRule(RelOptRule rule) {
  // Remove description.
  if (!super.removeRule(rule)) {
    // Rule was not present.
    return false;
  }

  // Remove operands.
  classOperands.values().removeIf(entry -> entry.getRule().equals(rule));

  // Remove trait mappings. (In particular, entries from conversion
  // 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;
}
 
Example 4
Source File: ConventionTraitDef.java    From calcite with Apache License 2.0 6 votes vote down vote up
public void registerConverterRule(
    RelOptPlanner planner,
    ConverterRule converterRule) {
  if (converterRule.isGuaranteed()) {
    ConversionData conversionData = getConversionData(planner);

    final Convention inConvention =
        (Convention) converterRule.getInTrait();
    final Convention outConvention =
        (Convention) converterRule.getOutTrait();
    conversionData.conversionGraph.addVertex(inConvention);
    conversionData.conversionGraph.addVertex(outConvention);
    conversionData.conversionGraph.addEdge(inConvention, outConvention);

    conversionData.mapArcToConverterRule.put(
        Pair.of(inConvention, outConvention), converterRule);
  }
}
 
Example 5
Source File: VolcanoPlanner.java    From calcite with Apache License 2.0 5 votes vote down vote up
public boolean addRule(RelOptRule rule) {
  if (locked) {
    return false;
  }

  if (!super.addRule(rule)) {
    return false;
  }

  // Each of this rule's operands is an 'entry point' for a rule call.
  // Register each operand against all concrete sub-classes that could match
  // it.
  for (RelOptRuleOperand operand : rule.getOperands()) {
    for (Class<? extends RelNode> subClass
        : subClasses(operand.getMatchedClass())) {
      if (PhysicalNode.class.isAssignableFrom(subClass)
          && rule instanceof TransformationRule) {
        continue;
      }
      classOperands.put(subClass, operand);
    }
  }

  // If this is a converter rule, check that it operates on one of the
  // kinds of trait we are interested in, and if so, register the rule
  // with the trait.
  if (rule instanceof ConverterRule) {
    ConverterRule converterRule = (ConverterRule) rule;

    final RelTrait ruleTrait = converterRule.getInTrait();
    final RelTraitDef ruleTraitDef = ruleTrait.getTraitDef();
    if (traitDefs.contains(ruleTraitDef)) {
      ruleTraitDef.registerConverterRule(this, converterRule);
    }
  }

  return true;
}
 
Example 6
Source File: VolcanoPlannerTraitTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void registerConverterRule(
    RelOptPlanner planner,
    ConverterRule converterRule) {
  if (!converterRule.isGuaranteed()) {
    return;
  }

  RelTrait fromTrait = converterRule.getInTrait();
  RelTrait toTrait = converterRule.getOutTrait();

  conversionMap.put(fromTrait, Pair.of(toTrait, converterRule));
}