Java Code Examples for org.apache.calcite.rel.logical.LogicalSort#create()

The following examples show how to use org.apache.calcite.rel.logical.LogicalSort#create() . 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: RelCollationTraitDef.java    From Bats with Apache License 2.0 6 votes vote down vote up
public RelNode convert(
    RelOptPlanner planner,
    RelNode rel,
    RelCollation toCollation,
    boolean allowInfiniteCostConverters) {
  if (toCollation.getFieldCollations().isEmpty()) {
    // An empty sort doesn't make sense.
    return null;
  }

  // Create a logical sort, then ask the planner to convert its remaining
  // traits (e.g. convert it to an EnumerableSortRel if rel is enumerable
  // convention)
  final Sort sort = LogicalSort.create(rel, toCollation, null, null);
  RelNode newRel = planner.register(sort, rel);
  final RelTraitSet newTraitSet = rel.getTraitSet().replace(toCollation);
  if (!newRel.getTraitSet().equals(newTraitSet)) {
    newRel = planner.changeTraits(newRel, newTraitSet);
  }
  return newRel;
}
 
Example 2
Source File: RelStructuredTypeFlattener.java    From Bats with Apache License 2.0 6 votes vote down vote up
public void rewriteRel(Sort rel) {
    RelCollation oldCollation = rel.getCollation();
    final RelNode oldChild = rel.getInput();
    final RelNode newChild = getNewForOldRel(oldChild);
    final Mappings.TargetMapping mapping = getNewForOldInputMapping(oldChild);

    // validate
    for (RelFieldCollation field : oldCollation.getFieldCollations()) {
        int oldInput = field.getFieldIndex();
        RelDataType sortFieldType = oldChild.getRowType().getFieldList().get(oldInput).getType();
        if (sortFieldType.isStruct()) {
            // TODO jvs 10-Feb-2005
            throw Util.needToImplement("sorting on structured types");
        }
    }
    RelCollation newCollation = RexUtil.apply(mapping, oldCollation);
    Sort newRel = LogicalSort.create(newChild, newCollation, rel.offset, rel.fetch);
    setNewForOldRel(rel, newRel);
}
 
Example 3
Source File: RelCollationTraitDef.java    From calcite with Apache License 2.0 6 votes vote down vote up
public RelNode convert(
    RelOptPlanner planner,
    RelNode rel,
    RelCollation toCollation,
    boolean allowInfiniteCostConverters) {
  if (toCollation.getFieldCollations().isEmpty()) {
    // An empty sort doesn't make sense.
    return null;
  }

  // Create a logical sort, then ask the planner to convert its remaining
  // traits (e.g. convert it to an EnumerableSortRel if rel is enumerable
  // convention)
  final Sort sort = LogicalSort.create(rel, toCollation, null, null);
  RelNode newRel = planner.register(sort, rel);
  final RelTraitSet newTraitSet = rel.getTraitSet().replace(toCollation);
  if (!newRel.getTraitSet().equals(newTraitSet)) {
    newRel = planner.changeTraits(newRel, newTraitSet);
  }
  return newRel;
}
 
Example 4
Source File: RelStructuredTypeFlattener.java    From calcite with Apache License 2.0 6 votes vote down vote up
public void rewriteRel(Sort rel) {
  RelCollation oldCollation = rel.getCollation();
  final RelNode oldChild = rel.getInput();
  final RelNode newChild = getNewForOldRel(oldChild);
  final Mappings.TargetMapping mapping =
      getNewForOldInputMapping(oldChild);

  // validate
  for (RelFieldCollation field : oldCollation.getFieldCollations()) {
    int oldInput = field.getFieldIndex();
    RelDataType sortFieldType =
        oldChild.getRowType().getFieldList().get(oldInput).getType();
    if (sortFieldType.isStruct()) {
      // TODO jvs 10-Feb-2005
      throw Util.needToImplement("sorting on structured types");
    }
  }
  RelCollation newCollation = RexUtil.apply(mapping, oldCollation);
  Sort newRel =
      LogicalSort.create(newChild, newCollation, rel.offset, rel.fetch);
  setNewForOldRel(rel, newRel);
}
 
Example 5
Source File: StreamRules.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override public void onMatch(RelOptRuleCall call) {
  final Delta delta = call.rel(0);
  Util.discard(delta);
  final Sort sort = call.rel(1);
  final LogicalDelta newDelta =
      LogicalDelta.create(sort.getInput());
  final LogicalSort newSort =
      LogicalSort.create(newDelta, sort.collation, sort.offset, sort.fetch);
  call.transformTo(newSort);
}
 
Example 6
Source File: StreamRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public void onMatch(RelOptRuleCall call) {
  final Delta delta = call.rel(0);
  Util.discard(delta);
  final Sort sort = call.rel(1);
  final LogicalDelta newDelta =
      LogicalDelta.create(sort.getInput());
  final LogicalSort newSort =
      LogicalSort.create(newDelta, sort.collation, sort.offset, sort.fetch);
  call.transformTo(newSort);
}
 
Example 7
Source File: RelFactories.java    From Bats with Apache License 2.0 4 votes vote down vote up
public RelNode createSort(RelNode input, RelCollation collation,
    RexNode offset, RexNode fetch) {
  return LogicalSort.create(input, collation, offset, fetch);
}
 
Example 8
Source File: DrillReduceExpressionsRule.java    From Bats with Apache License 2.0 4 votes vote down vote up
private static RelNode createEmptyEmptyRelHelper(SingleRel input) {
  return LogicalSort.create(input.getInput(), RelCollations.EMPTY,
      input.getCluster().getRexBuilder().makeExactLiteral(BigDecimal.valueOf(0)),
      input.getCluster().getRexBuilder().makeExactLiteral(BigDecimal.valueOf(0)));
}
 
Example 9
Source File: RelFactories.java    From calcite with Apache License 2.0 4 votes vote down vote up
public RelNode createSort(RelNode input, RelCollation collation,
    RexNode offset, RexNode fetch) {
  return LogicalSort.create(input, collation, offset, fetch);
}