Java Code Examples for org.apache.calcite.rel.core.Sort#getCollation()

The following examples show how to use org.apache.calcite.rel.core.Sort#getCollation() . 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: 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 2
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 3
Source File: SortConvertPrule.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public RelNode convert(RelNode r) {
  Sort rel = (Sort) r;
  RelTraitSet traits = rel.getInput().getTraitSet().replace(Prel.DRILL_PHYSICAL);
  return new SortPrel(rel.getCluster(),
                      traits.plus(rel.getCollation()),
                      convert(rel.getInput(), traits.simplify()),
                      rel.getCollation());
}
 
Example 4
Source File: OLAPSortRule.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public RelNode convert(RelNode rel) {
    final Sort sort = (Sort) rel;
    if (sort.offset != null || sort.fetch != null) {
        return null;
    }
    final RelTraitSet traitSet = sort.getTraitSet().replace(OLAPRel.CONVENTION);
    final RelNode input = sort.getInput();
    return new OLAPSortRel(rel.getCluster(), traitSet, convert(input, input.getTraitSet().replace(OLAPRel.CONVENTION)), sort.getCollation(), sort.offset, sort.fetch);
}
 
Example 5
Source File: SolrRules.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public RelNode convert(RelNode rel) {
  final Sort sort = (Sort) rel;
  final RelTraitSet traitSet = sort.getTraitSet().replace(out).replace(sort.getCollation());
  return new SolrSort(
      rel.getCluster(),
      traitSet,
      convert(sort.getInput(), traitSet.replace(RelCollations.EMPTY)),
      sort.getCollation(),
      sort.offset,
      sort.fetch);
}
 
Example 6
Source File: OLAPSortRule.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public RelNode convert(RelNode rel) {
    final Sort sort = (Sort) rel;
    if (sort.offset != null || sort.fetch != null) {
        return null;
    }
    final RelTraitSet traitSet = sort.getTraitSet().replace(OLAPRel.CONVENTION);
    final RelNode input = sort.getInput();
    return new OLAPSortRel(rel.getCluster(), traitSet, convert(input, input.getTraitSet().replace(OLAPRel.CONVENTION)), sort.getCollation(), sort.offset, sort.fetch);
}
 
Example 7
Source File: GeodeRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public void onMatch(RelOptRuleCall call) {
  final Sort sort = call.rel(0);

  final RelTraitSet traitSet = sort.getTraitSet()
      .replace(GeodeRel.CONVENTION)
      .replace(sort.getCollation());

  GeodeSort geodeSort = new GeodeSort(sort.getCluster(), traitSet,
      convert(sort.getInput(), traitSet.replace(RelCollations.EMPTY)),
      sort.getCollation(), sort.fetch);

  call.transformTo(geodeSort);
}
 
Example 8
Source File: CassandraRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelNode convert(Sort sort, CassandraFilter filter) {
  final RelTraitSet traitSet =
      sort.getTraitSet().replace(CassandraRel.CONVENTION)
          .replace(sort.getCollation());
  return new CassandraSort(sort.getCluster(), traitSet,
      convert(sort.getInput(), traitSet.replace(RelCollations.EMPTY)),
      sort.getCollation());
}
 
Example 9
Source File: ElasticsearchRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public RelNode convert(RelNode relNode) {
  final Sort sort = (Sort) relNode;
  final RelTraitSet traitSet = sort.getTraitSet().replace(out).replace(sort.getCollation());
  return new ElasticsearchSort(relNode.getCluster(), traitSet,
    convert(sort.getInput(), traitSet.replace(RelCollations.EMPTY)), sort.getCollation(),
    sort.offset, sort.fetch);
}
 
Example 10
Source File: MongoRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelNode convert(RelNode rel) {
  final Sort sort = (Sort) rel;
  final RelTraitSet traitSet =
      sort.getTraitSet().replace(out)
          .replace(sort.getCollation());
  return new MongoSort(rel.getCluster(), traitSet,
      convert(sort.getInput(), traitSet.replace(RelCollations.EMPTY)),
      sort.getCollation(), sort.offset, sort.fetch);
}
 
Example 11
Source File: JdbcRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@code Sort} into a {@code JdbcSort}.
 *
 * @param sort Sort operator to convert
 * @param convertInputTraits Whether to convert input to {@code sort}'s
 *                            JDBC convention
 * @return A new JdbcSort
 */
public RelNode convert(Sort sort, boolean convertInputTraits) {
  final RelTraitSet traitSet = sort.getTraitSet().replace(out);

  final RelNode input;
  if (convertInputTraits) {
    final RelTraitSet inputTraitSet = sort.getInput().getTraitSet().replace(out);
    input = convert(sort.getInput(), inputTraitSet);
  } else {
    input = sort.getInput();
  }

  return new JdbcSort(sort.getCluster(), traitSet,
      input, sort.getCollation(), sort.offset, sort.fetch);
}
 
Example 12
Source File: Bindables.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelNode convert(RelNode rel) {
  final Sort sort = (Sort) rel;
  final RelTraitSet traitSet =
      sort.getTraitSet().replace(BindableConvention.INSTANCE);
  final RelNode input = sort.getInput();
  return new BindableSort(rel.getCluster(), traitSet,
      convert(input,
          input.getTraitSet().replace(BindableConvention.INSTANCE)),
      sort.getCollation(), sort.offset, sort.fetch);
}
 
Example 13
Source File: TraitPropagationTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelNode convert(RelNode rel) {
  final Sort sort = (Sort) rel;
  final RelNode input = convert(sort.getInput(),
      rel.getCluster().traitSetOf(PHYSICAL));
  return new PhysSort(
      rel.getCluster(),
      input.getTraitSet().plus(sort.getCollation()),
      convert(input, input.getTraitSet().replace(PHYSICAL)),
      sort.getCollation(),
      null,
      null);
}
 
Example 14
Source File: IndexPlanUtils.java    From Bats with Apache License 2.0 4 votes vote down vote up
public static RelCollation getCollation(Sort sort) {
  return sort.getCollation();
}
 
Example 15
Source File: DremioSqlDialect.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static boolean isCollationEmpty(Sort sort) {
  return sort.getCollation() == null || sort.getCollation() == RelCollations.EMPTY;
}