当前位置: 首页>>代码示例>>Java>>正文


Java ConverterRule类代码示例

本文整理汇总了Java中org.apache.calcite.rel.convert.ConverterRule的典型用法代码示例。如果您正苦于以下问题:Java ConverterRule类的具体用法?Java ConverterRule怎么用?Java ConverterRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConverterRule类属于org.apache.calcite.rel.convert包,在下文中一共展示了ConverterRule类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerConverterRule

import org.apache.calcite.rel.convert.ConverterRule; //导入依赖的package包/类
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);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:ConventionTraitDef.java

示例2: changeConvention

import org.apache.calcite.rel.convert.ConverterRule; //导入依赖的package包/类
/**
 * Tries to convert a relational expression to the target convention of an
 * arc.
 */
private RelNode changeConvention(
    RelNode rel,
    Convention source,
    Convention target,
    final Multimap<Pair<Convention, Convention>, ConverterRule>
        mapArcToConverterRule) {
  assert source == rel.getConvention();

  // Try to apply each converter rule for this arc's source/target calling
  // conventions.
  final Pair<Convention, Convention> key = Pair.of(source, target);
  for (ConverterRule rule : mapArcToConverterRule.get(key)) {
    assert rule.getInTrait() == source;
    assert rule.getOutTrait() == target;
    RelNode converted = rule.convert(rel);
    if (converted != null) {
      return converted;
    }
  }
  return null;
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:ConventionTraitDef.java

示例3: doesConverterApply

import org.apache.calcite.rel.convert.ConverterRule; //导入依赖的package包/类
private boolean doesConverterApply(
    ConverterRule converterRule,
    HepRelVertex vertex) {
  RelTrait outTrait = converterRule.getOutTrait();
  List<HepRelVertex> parents = Graphs.predecessorListOf(graph, vertex);
  for (HepRelVertex parent : parents) {
    RelNode parentRel = parent.getCurrentRel();
    if (parentRel instanceof Converter) {
      // We don't support converter chains.
      continue;
    }
    if (parentRel.getTraitSet().contains(outTrait)) {
      // This parent wants the traits produced by the converter.
      return true;
    }
  }
  return (vertex == root)
      && (requestedRootTraits != null)
      && requestedRootTraits.contains(outTrait);
}
 
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:HepPlanner.java

示例4: removeRule

import org.apache.calcite.rel.convert.ConverterRule; //导入依赖的package包/类
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();
    }
  }

  // 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;
}
 
开发者ID:apache,项目名称:calcite,代码行数:31,代码来源:VolcanoPlanner.java

示例5: matches

import org.apache.calcite.rel.convert.ConverterRule; //导入依赖的package包/类
public boolean matches(RelNode rel) {
  // Don't apply converters to converters that operate
  // on the same RelTraitDef -- otherwise we get
  // an n^2 effect.
  if (rel instanceof Converter) {
    if (((ConverterRule) getRule()).getTraitDef()
        == ((Converter) rel).getTraitDef()) {
      return false;
    }
  }
  return super.matches(rel);
}
 
开发者ID:apache,项目名称:calcite,代码行数:13,代码来源:RelOptRule.java

示例6: convert

import org.apache.calcite.rel.convert.ConverterRule; //导入依赖的package包/类
public RelNode convert(
    RelOptPlanner planner,
    RelNode rel,
    AltTrait toTrait,
    boolean allowInfiniteCostConverters) {
  RelTrait fromTrait = rel.getTraitSet().getTrait(this);

  if (conversionMap.containsKey(fromTrait)) {
    final RelMetadataQuery mq = RelMetadataQuery.instance();
    for (Pair<RelTrait, ConverterRule> traitAndRule
        : conversionMap.get(fromTrait)) {
      RelTrait trait = traitAndRule.left;
      ConverterRule rule = traitAndRule.right;

      if (trait == toTrait) {
        RelNode converted = rule.convert(rel);
        if ((converted != null)
            && (!planner.getCost(converted, mq).isInfinite()
            || allowInfiniteCostConverters)) {
          return converted;
        }
      }
    }
  }

  return null;
}
 
开发者ID:apache,项目名称:calcite,代码行数:28,代码来源:VolcanoPlannerTraitTest.java

示例7: canConvert

import org.apache.calcite.rel.convert.ConverterRule; //导入依赖的package包/类
public boolean canConvert(
    RelOptPlanner planner,
    AltTrait fromTrait,
    AltTrait toTrait) {
  if (conversionMap.containsKey(fromTrait)) {
    for (Pair<RelTrait, ConverterRule> traitAndRule
        : conversionMap.get(fromTrait)) {
      if (traitAndRule.left == toTrait) {
        return true;
      }
    }
  }

  return false;
}
 
开发者ID:apache,项目名称:calcite,代码行数:16,代码来源:VolcanoPlannerTraitTest.java

示例8: registerConverterRule

import org.apache.calcite.rel.convert.ConverterRule; //导入依赖的package包/类
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));
}
 
开发者ID:apache,项目名称:calcite,代码行数:13,代码来源:VolcanoPlannerTraitTest.java

示例9: applyRule

import org.apache.calcite.rel.convert.ConverterRule; //导入依赖的package包/类
private HepRelVertex applyRule(
    RelOptRule rule,
    HepRelVertex vertex,
    boolean forceConversions) {
  if (!belongsToDag(vertex)) {
    return null;
  }
  RelTrait parentTrait = null;
  List<RelNode> parents = null;
  if (rule instanceof ConverterRule) {
    // Guaranteed converter rules require special casing to make sure
    // they only fire where actually needed, otherwise they tend to
    // fire to infinity and beyond.
    ConverterRule converterRule = (ConverterRule) rule;
    if (converterRule.isGuaranteed() || !forceConversions) {
      if (!doesConverterApply(converterRule, vertex)) {
        return null;
      }
      parentTrait = converterRule.getOutTrait();
    }
  } else if (rule instanceof CommonRelSubExprRule) {
    // Only fire CommonRelSubExprRules if the vertex is a common
    // subexpression.
    List<HepRelVertex> parentVertices = getVertexParents(vertex);
    if (parentVertices.size() < 2) {
      return null;
    }
    parents = new ArrayList<>();
    for (HepRelVertex pVertex : parentVertices) {
      parents.add(pVertex.getCurrentRel());
    }
  }

  final List<RelNode> bindings = new ArrayList<>();
  final Map<RelNode, List<RelNode>> nodeChildren = new HashMap<>();
  boolean match =
      matchOperands(
          rule.getOperand(),
          vertex.getCurrentRel(),
          bindings,
          nodeChildren);

  if (!match) {
    return null;
  }

  HepRuleCall call =
      new HepRuleCall(
          this,
          rule.getOperand(),
          bindings.toArray(new RelNode[bindings.size()]),
          nodeChildren,
          parents);

  // Allow the rule to apply its own side-conditions.
  if (!rule.matches(call)) {
    return null;
  }

  fireRule(call);

  if (!call.getResults().isEmpty()) {
    return applyTransformationResults(
        vertex,
        call,
        parentTrait);
  }

  return null;
}
 
开发者ID:apache,项目名称:calcite,代码行数:71,代码来源:HepPlanner.java

示例10: removeTrivialProject

import org.apache.calcite.rel.convert.ConverterRule; //导入依赖的package包/类
private void removeTrivialProject(boolean useRule) {
  VolcanoPlanner planner = new VolcanoPlanner();
  planner.ambitious = true;

  planner.addRelTraitDef(ConventionTraitDef.INSTANCE);

  if (useRule) {
    planner.addRule(ProjectRemoveRule.INSTANCE);
  }

  planner.addRule(new PhysLeafRule());
  planner.addRule(new GoodSingleRule());
  planner.addRule(new PhysProjectRule());

  planner.addRule(
      new ConverterRule(
          RelNode.class,
          PHYS_CALLING_CONVENTION,
          EnumerableConvention.INSTANCE,
          "PhysToIteratorRule") {
        public RelNode convert(RelNode rel) {
          return new PhysToIteratorConverter(
              rel.getCluster(),
              rel);
        }
      });

  RelOptCluster cluster = newCluster(planner);
  PhysLeafRel leafRel =
      new PhysLeafRel(
          cluster,
          "a");
  RexInputRef inputRef = RexInputRef.of(0, leafRel.getRowType());
  RelNode projectRel =
      RelOptUtil.createProject(
          leafRel,
          ImmutableList.of(inputRef),
          ImmutableList.of("this"));
  NoneSingleRel singleRel =
      new NoneSingleRel(
          cluster,
          projectRel);
  RelNode convertedRel =
      planner.changeTraits(
          singleRel,
          cluster.traitSetOf(EnumerableConvention.INSTANCE));
  planner.setRoot(convertedRel);
  RelNode result = planner.chooseDelegate().findBestExp();
  assertTrue(result instanceof PhysToIteratorConverter);
}
 
开发者ID:apache,项目名称:calcite,代码行数:51,代码来源:VolcanoPlannerTest.java

示例11: registerConverterRule

import org.apache.calcite.rel.convert.ConverterRule; //导入依赖的package包/类
/**
 * Provides notification of the registration of a particular
 * {@link ConverterRule} with a {@link RelOptPlanner}. The default
 * implementation does nothing.
 *
 * @param planner       the planner registering the rule
 * @param converterRule the registered converter rule
 */
public void registerConverterRule(
    RelOptPlanner planner,
    ConverterRule converterRule) {
}
 
开发者ID:apache,项目名称:calcite,代码行数:13,代码来源:RelTraitDef.java

示例12: deregisterConverterRule

import org.apache.calcite.rel.convert.ConverterRule; //导入依赖的package包/类
/**
 * Provides notification that a particular {@link ConverterRule} has been
 * de-registered from a {@link RelOptPlanner}. The default implementation
 * does nothing.
 *
 * @param planner       the planner registering the rule
 * @param converterRule the registered converter rule
 */
public void deregisterConverterRule(
    RelOptPlanner planner,
    ConverterRule converterRule) {
}
 
开发者ID:apache,项目名称:calcite,代码行数:13,代码来源:RelTraitDef.java


注:本文中的org.apache.calcite.rel.convert.ConverterRule类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。