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); }
public void onMatch(RelOptRuleCall call) { ProjectRel project = call.rel(0); SortRel sort = call.rel(1); if (sort.getClass() != SortRel.class) { return; } RelNode newProject = project.copy( project.getTraitSet(), ImmutableList.of(sort.getChild())); final SortRel newSort = sort.copy( sort.getTraitSet(), newProject, sort.getCollation(), sort.offset, sort.fetch); call.transformTo(newSort); } }
public SortRel copy( RelTraitSet traitSet, RelNode newInput, RelCollation newCollation) { return copy(traitSet, newInput, newCollation, offset, fetch); }
RelNode oldChildRel = rel.getChild(); newChildRel.getRowType().getFieldCount()); RelCollation oldCollation = rel.getCollation(); RelCollation newCollation = RexUtil.apply(mapping, oldCollation); new SortRel( rel.getCluster(), rel.getCluster().traitSetOf(Convention.NONE).plus(newCollation), newChildRel, newCollation,
public RelNode convert(RelNode rel) { final SortRel sort = (SortRel) rel; if (sort.offset != null || sort.fetch != null) { // Cannot implement "OFFSET n FETCH n" currently. return null; } final RelTraitSet traitSet = sort.getTraitSet().replace(out); return new JdbcSortRel(rel.getCluster(), traitSet, convert(sort.getChild(), traitSet), sort.getCollation()); } }
public Double getSelectivity(SortRel rel, RexNode predicate) { return RelMetadataQuery.getSelectivity( rel.getChild(), predicate); }
final RelOptCluster cluster = project.getCluster(); if (sort.getConvention() != project.getConvention()) { return; RelOptUtil.permutation( project.getProjects(), project.getChild().getRowType()); for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) { if (map.getTargetOpt(fc.getFieldIndex()) < 0) { return; RexUtil.apply(map, sort.getCollation())); final SortRel newSort = sort.copy( sort.getTraitSet().replace(newCollation), project.getChild(), newCollation, RelNode newProject = project.copy( sort.getTraitSet(), ImmutableList.<RelNode>of(newSort));
new SortRel( cluster, cluster.traitSetOf(Convention.NONE, collation),
@Override public List<RelCollation> getCollationList() { // TODO: include each prefix of the collation, e.g [[x, y], [x], []] return Collections.singletonList(getCollation()); }
builder.add( cluster.getRexBuilder().makeInputRef( getRowType().getFieldList().get(index).getType(), index));
@Override public RelOptCost computeSelfCost( RelOptPlanner planner ) { return super.computeSelfCost( planner ).multiplyBy( .1 ); }
public void rewriteRel(SortRel rel) { RelCollation oldCollation = rel.getCollation(); final RelNode oldChild = rel.getChild(); 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"); } } SortRel newRel = new SortRel( rel.getCluster(), rel.getCluster().traitSetOf(Convention.NONE), newChild, RexUtil.apply(mapping, oldCollation)); setNewForOldRel(rel, newRel); }
public RelNode convert(RelNode rel) { final SortRel sort = (SortRel) rel; if (sort.offset != null || sort.fetch != null) { // Cannot implement "OFFSET n FETCH n" currently. return null; } final RelTraitSet traitSet = sort.getTraitSet().replace(out); return new JdbcSortRel(rel.getCluster(), traitSet, convert(sort.getChild(), traitSet), sort.getCollation()); } }
public Set<RelColumnOrigin> getColumnOrigins( SortRel rel, int iOutputColumn) { return invokeGetColumnOrigins( rel.getChild(), iOutputColumn); }
new SortRel( cluster, cluster.traitSetOf(Convention.NONE, collation),
@Override public List<RelCollation> getCollationList() { // TODO: include each prefix of the collation, e.g [[x, y], [x], []] return Collections.singletonList(getCollation()); }
@Override public RelOptCost computeSelfCost(RelOptPlanner planner) { // Higher cost if rows are wider discourages pushing a project through a // sort. double rowCount = RelMetadataQuery.getRowCount(this); double bytesPerRow = getRowType().getFieldCount() * 4; return planner.getCostFactory().makeCost( Util.nLogN(rowCount) * bytesPerRow, rowCount, 0); }
@Override public void onMatch( RelOptRuleCall call ) { SortRel rel = call.rel( 0 ); // Cascading sort does not implement limits if( rel.offset != null || rel.fetch != null ) return; RelTraitSet newTraits = rel.getTraitSet().plus( Cascading.CONVENTION ); call.transformTo( new CascadingSortRel( rel.getCluster(), newTraits, convert( rel.getChild(), newTraits ), rel.getCollation(), rel.offset, rel.fetch ) ); } }
public void rewriteRel(SortRel rel) { RelCollation oldCollation = rel.getCollation(); final RelNode oldChild = rel.getChild(); 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); SortRel newRel = new SortRel( rel.getCluster(), rel.getCluster().traitSetOf(Convention.NONE).plus(newCollation), newChild, newCollation, rel.offset, rel.fetch); setNewForOldRel(rel, newRel); }
@Override public void onMatch(RelOptRuleCall call) { if (!call.getPlanner().getRelTraitDefs() .contains(RelCollationTraitDef.INSTANCE)) { // Collation is not an active trait. return; } final SortRel sort = call.rel(0); if (sort.offset != null || sort.fetch != null) { // Don't remove sort if would also remove OFFSET or LIMIT. return; } final RelCollation collation = sort.getCollation(); final RelTraitSet traits = sort.getTraitSet().replace(collation); call.transformTo(convert(sort.getChild(), traits)); } }