public Integer apply(RelFieldCollation input) { return input.getFieldIndex(); } });
/** Returns a string representation of this collation, suitably terse given * that it will appear in plan traces. Examples: * "[]", "[2]", "[0 DESC, 1]", "[0 DESC, 1 ASC NULLS LAST]". */ public String toString() { Iterator<RelFieldCollation> it = fieldCollations.iterator(); if (! it.hasNext()) { return "[]"; } StringBuilder sb = new StringBuilder(); sb.append('['); for (;;) { RelFieldCollation e = it.next(); sb.append(e.getFieldIndex()); if (e.direction != RelFieldCollation.Direction.ASCENDING || e.nullDirection != RelFieldCollation.NullDirection.UNSPECIFIED) { sb.append(' ').append(e.shortString()); } if (!it.hasNext()) { return sb.append(']').toString(); } sb.append(',').append(' '); } }
public Object toJson(RelCollationImpl node) { final List<Object> list = new ArrayList<Object>(); for (RelFieldCollation fieldCollation : node.getFieldCollations()) { final Map<String, Object> map = jsonBuilder.map(); map.put("field", fieldCollation.getFieldIndex()); map.put("direction", fieldCollation.getDirection().name()); map.put("nulls", fieldCollation.nullDirection.name()); list.add(map); } return list; }
/** * Applies a mapping to a field collation. * * <p>If the field is not mapped, returns null. * * @param mapping Mapping * @param fieldCollation Field collation * @return collation with mapping applied */ public static RelFieldCollation apply( Mappings.TargetMapping mapping, RelFieldCollation fieldCollation) { final int target = mapping.getTargetOpt(fieldCollation.getFieldIndex()); if (target < 0) { return null; } return fieldCollation.copy(target); }
/** * Applies a mapping to a field collation. * * <p>If the field is not mapped, returns null. * * @param mapping Mapping * @param fieldCollation Field collation * @return collation with mapping applied */ public static RelFieldCollation apply( Mappings.TargetMapping mapping, RelFieldCollation fieldCollation) { final int target = mapping.getTargetOpt(fieldCollation.getFieldIndex()); if (target < 0) { return null; } return fieldCollation.copy(target); }
: collation.getFieldCollations()) final int source = fieldCollation.getFieldIndex(); final int target = targets[source]; if (target < 0) {
/** * Checks that a collection of collations is valid. * * @param rowType Row type of the relational expression * @param collationList List of collations * @param fail Whether to fail if invalid * @return Whether valid */ public static boolean isValid( RelDataType rowType, List<RelCollation> collationList, boolean fail) { final int fieldCount = rowType.getFieldCount(); for (RelCollation collation : collationList) { for (RelFieldCollation fieldCollation : collation.getFieldCollations()) { final int index = fieldCollation.getFieldIndex(); if (index < 0 || index >= fieldCount) { assert !fail; return false; } } } return true; }
new ArrayList<RelFieldCollation>(0); for (RelFieldCollation fieldCollation : collation.getFieldCollations()) { final int source = fieldCollation.getFieldIndex(); final int target = targets[source]; if (target < 0) {
/** * Checks that a collection of collations is valid. * * @param rowType Row type of the relational expression * @param collationList List of collations * @param fail Whether to fail if invalid * * @return Whether valid */ public static boolean isValid( RelDataType rowType, List<RelCollation> collationList, boolean fail) { final int fieldCount = rowType.getFieldCount(); for (RelCollation collation : collationList) { for ( RelFieldCollation fieldCollation : collation.getFieldCollations()) { final int index = fieldCollation.getFieldIndex(); if ((index < 0) || (index >= fieldCount)) { assert !fail; return false; } } } return true; }
ImmutableList.Builder<RexNode> builder = ImmutableList.builder(); for (RelFieldCollation field : collation.getFieldCollations()) { int index = field.getFieldIndex(); builder.add(cluster.getRexBuilder().makeInputRef(child, index));
ImmutableList.Builder<RexNode> builder = ImmutableList.builder(); for (RelFieldCollation field : collation.getFieldCollations()) { int index = field.getFieldIndex(); builder.add( cluster.getRexBuilder().makeInputRef(
/** Converts a collation to an ORDER BY item. */ public SqlNode toSql(RelFieldCollation collation) { SqlNode node = field(collation.getFieldIndex()); switch (collation.getDirection()) { case DESCENDING: case STRICTLY_DESCENDING: node = SqlStdOperatorTable.DESC.createCall(POS, node); } switch (collation.nullDirection) { case FIRST: node = SqlStdOperatorTable.NULLS_FIRST.createCall(POS, node); break; case LAST: node = SqlStdOperatorTable.NULLS_LAST.createCall(POS, node); break; } return node; } }
/** Converts a collation to an ORDER BY item. */ public SqlNode toSql(RelFieldCollation collation) { SqlNode node = field(collation.getFieldIndex()); switch (collation.getDirection()) { case Descending: case StrictlyDescending: node = SqlStdOperatorTable.descendingOperator.createCall(POS, node); } switch (collation.nullDirection) { case FIRST: node = SqlStdOperatorTable.nullsFirstOperator.createCall(POS, node); break; case LAST: node = SqlStdOperatorTable.nullsLastOperator.createCall(POS, node); break; } return node; } }
public JdbcImplementor.Result implement(JdbcImplementor implementor) { final JdbcImplementor.Result x = implementor.visitChild(0, getChild()); final JdbcImplementor.Builder builder = x.builder(this, JdbcImplementor.Clause.ORDER_BY); List<SqlNode> orderByList = Expressions.list(); for (RelFieldCollation fieldCollation : collation.getFieldCollations()) { if (fieldCollation.nullDirection != RelFieldCollation.NullDirection.UNSPECIFIED && implementor.dialect.getDatabaseProduct() == SqlDialect.DatabaseProduct.MYSQL) { orderByList.add( ISNULL_FUNCTION.createCall(POS, builder.context.field(fieldCollation.getFieldIndex()))); fieldCollation = new RelFieldCollation(fieldCollation.getFieldIndex(), fieldCollation.getDirection()); } orderByList.add(builder.context.toSql(fieldCollation)); } builder.setOrderBy(new SqlNodeList(orderByList, POS)); return builder.result(); } }
public JdbcImplementor.Result implement(JdbcImplementor implementor) { final JdbcImplementor.Result x = implementor.visitChild(0, getChild()); final JdbcImplementor.Builder builder = x.builder(this, JdbcImplementor.Clause.ORDER_BY); List<SqlNode> orderByList = Expressions.list(); for (RelFieldCollation fieldCollation : collation.getFieldCollations()) { if (fieldCollation.nullDirection != RelFieldCollation.NullDirection.UNSPECIFIED && implementor.dialect.getDatabaseProduct() == SqlDialect.DatabaseProduct.MYSQL) { orderByList.add( ISNULL_FUNCTION.createCall(POS, builder.context.field(fieldCollation.getFieldIndex()))); fieldCollation = new RelFieldCollation(fieldCollation.getFieldIndex(), fieldCollation.getDirection()); } orderByList.add(builder.context.toSql(fieldCollation)); } builder.setOrderBy(new SqlNodeList(orderByList, POS)); return builder.result(); } }
inputFieldsUsed.set(field.getFieldIndex());
private Fields createFields() { Fields fields = new Fields(); RelNode child = getChild(); RelDataType inputRowType = child.getRowType(); for( RexNode exp : fieldExps ) { int index = ( (RexInputRef) exp ).getIndex(); RelDataTypeField typeField = inputRowType.getFieldList().get( index ); String name = typeField.getName(); fields = fields.append( new Fields( name ) ); } for( RelFieldCollation fieldCollation : collation.getFieldCollations() ) { String name = inputRowType.getFieldList().get( fieldCollation.getFieldIndex() ).getName(); boolean isDescending = fieldCollation.getDirection() == RelFieldCollation.Direction.Descending; boolean isNullsFirst = fieldCollation.nullDirection == RelFieldCollation.NullDirection.FIRST; Comparator<Comparable> comparator = Functions.<Comparable>nullsComparator( isNullsFirst, isDescending ); if( comparator != null ) fields.setComparator( name, comparator ); } return fields; } }
project.getProjects(), project.getChild().getRowType()); for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) { if (map.getTargetOpt(fc.getFieldIndex()) < 0) { return;
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 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); }