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; }
/** 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; } }
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; } }
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(); } }
== RelFieldCollation.NullDirection.FIRST), Expressions.constant( collation.getDirection() == RelFieldCollation.Direction.Descending))); == RelFieldCollation.NullDirection.FIRST; final boolean descending = collation.getDirection() == RelFieldCollation.Direction.Descending; body.add(
== RelFieldCollation.NullDirection.FIRST), Expressions.constant( collation.getDirection() == RelFieldCollation.Direction.DESCENDING))); == RelFieldCollation.NullDirection.FIRST; final boolean descending = collation.getDirection() == RelFieldCollation.Direction.DESCENDING; body.add(
== RelFieldCollation.NullDirection.FIRST; final boolean descending = fieldCollation.getDirection() == RelFieldCollation.Direction.DESCENDING; body.add(
== RelFieldCollation.NullDirection.FIRST; final boolean descending = fieldCollation.getDirection() == RelFieldCollation.Direction.Descending; body.add(