/** * 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); }
/** 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; }