Beispiel #1
0
 public RelTraitSet traitSetOf(RelTrait... traits) {
   RelTraitSet traitSet = emptyTraitSet;
   assert traitSet.size() == planner.getRelTraitDefs().size();
   for (RelTrait trait : traits) {
     traitSet = traitSet.replace(trait);
   }
   return traitSet;
 }
Beispiel #2
0
 public SortRel copy(
     RelTraitSet traitSet,
     RelNode newInput,
     RelCollation newCollation,
     RexNode offset,
     RexNode fetch) {
   assert traitSet.containsIfApplicable(Convention.NONE);
   return new SortRel(getCluster(), traitSet, newInput, newCollation, offset, fetch);
 }
  /**
   * Creates new RelNodes replacing/removing the original project/row scan
   *
   * @param projectedScan new scan that is now projected
   * @param origProject original projection
   * @param needRename true if fields from the row scan need to be renamed
   * @param newProject projection that contains the new projection expressions, in the case where
   *     the original projection cannot be removed because it projects expressions
   * @return new RelNode
   */
  public RelNode createNewRelNode(
      RelNode projectedScan, ProjectRel origProject, boolean needRename, ProjectRel newProject) {
    RelNode scanRel;
    if (needRename) {
      // Replace calling convention with FENNEL_EXEC_CONVENTION
      RelTraitSet traits = RelOptUtil.clone(origProject.getTraits());
      traits.setTrait(CallingConventionTraitDef.instance, FennelRel.FENNEL_EXEC_CONVENTION);
      if (!traits.equals(projectedScan.getTraits())) {
        RelNode mergedProjectedScan = convert(projectedScan, traits);
        RelOptPlanner planner = projectedScan.getCluster().getPlanner();
        // register projectedScan == mergedProjectedScan
        // so mergedProjectedScan will have a set later on
        projectedScan = planner.ensureRegistered(mergedProjectedScan, projectedScan);
      }
      scanRel =
          new FennelRenameRel(
              origProject.getCluster(),
              projectedScan,
              RelOptUtil.getFieldNames(origProject.getRowType()),
              traits);
    } else {
      scanRel = projectedScan;
    }

    if (newProject == null) {
      return scanRel;
    } else {
      // in the case where the projection had expressions, put the
      // new, modified projection on top of the projected row scan
      return (ProjectRel)
          CalcRel.createProject(
              scanRel,
              newProject.getProjectExps(),
              RelOptUtil.getFieldNames(newProject.getRowType()));
    }
  }
Beispiel #4
0
  /**
   * Creates a sorter.
   *
   * @param cluster Cluster this relational expression belongs to
   * @param traits Traits
   * @param child input relational expression
   * @param collation array of sort specifications
   * @param offset Expression for number of rows to discard before returning first row
   * @param fetch Expression for number of rows to fetch
   */
  public SortRel(
      RelOptCluster cluster,
      RelTraitSet traits,
      RelNode child,
      RelCollation collation,
      RexNode offset,
      RexNode fetch) {
    super(cluster, traits, child);
    this.collation = collation;
    this.offset = offset;
    this.fetch = fetch;

    assert traits.containsIfApplicable(collation) : "traits=" + traits + ", collation=" + collation;
    assert !(fetch == null && offset == null && collation.getFieldCollations().isEmpty())
        : "trivial sort";
    ImmutableList.Builder<RexNode> builder = ImmutableList.builder();
    for (RelFieldCollation field : collation.getFieldCollations()) {
      int index = field.getFieldIndex();
      builder.add(cluster.getRexBuilder().makeInputRef(child, index));
    }
    fieldExps = builder.build();
  }
Beispiel #5
0
 public SortRel copy(
     RelTraitSet traitSet, RelNode newInput, List<RelFieldCollation> newCollations) {
   assert traitSet.comprises(Convention.NONE);
   return new SortRel(
       getCluster(), getCluster().traitSetOf(Convention.NONE), newInput, newCollations);
 }
Beispiel #6
0
 public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
   assert traitSet.comprises(Convention.NONE);
   assert inputs.isEmpty();
   return new ValuesRel(getCluster(), rowType, tuples);
 }