Search in sources :

Example 1 with OrderBy

use of org.teiid.language.OrderBy in project teiid by teiid.

the class TestSetQueryImpl method example3.

public static SetQuery example3() throws Exception {
    SetQuery union = example2();
    List<SortSpecification> items = new ArrayList<SortSpecification>();
    // $NON-NLS-1$
    items.add(new SortSpecification(Ordering.ASC, new ColumnReference(null, "nugent", null, DataTypeManager.DefaultDataClasses.STRING)));
    OrderBy orderBy = new OrderBy(items);
    union.setOrderBy(orderBy);
    return union;
}
Also used : OrderBy(org.teiid.language.OrderBy) SetQuery(org.teiid.language.SetQuery) SortSpecification(org.teiid.language.SortSpecification) ArrayList(java.util.ArrayList) ColumnReference(org.teiid.language.ColumnReference)

Example 2 with OrderBy

use of org.teiid.language.OrderBy in project teiid by teiid.

the class BaseSybaseExecutionFactory method translateCommand.

/**
 * SetQueries don't have a concept of TOP, an inline view is needed.
 */
@Override
public List<?> translateCommand(Command command, ExecutionContext context) {
    if (!(command instanceof SetQuery)) {
        return null;
    }
    SetQuery queryCommand = (SetQuery) command;
    if (queryCommand.getLimit() == null) {
        return null;
    }
    Limit limit = queryCommand.getLimit();
    OrderBy orderBy = queryCommand.getOrderBy();
    queryCommand.setLimit(null);
    queryCommand.setOrderBy(null);
    List<Object> parts = new ArrayList<Object>(6);
    if (queryCommand.getWith() != null) {
        With with = queryCommand.getWith();
        queryCommand.setWith(null);
        parts.add(with);
    }
    // $NON-NLS-1$
    parts.add("SELECT ");
    parts.addAll(translateLimit(limit, context));
    // $NON-NLS-1$
    parts.add(" * FROM (");
    parts.add(queryCommand);
    // $NON-NLS-1$
    parts.add(") AS X");
    if (orderBy != null) {
        // $NON-NLS-1$
        parts.add(" ");
        parts.add(orderBy);
    }
    return parts;
}
Also used : OrderBy(org.teiid.language.OrderBy) SetQuery(org.teiid.language.SetQuery) ArrayList(java.util.ArrayList) LanguageObject(org.teiid.language.LanguageObject) Limit(org.teiid.language.Limit) With(org.teiid.language.With)

Aggregations

ArrayList (java.util.ArrayList)2 OrderBy (org.teiid.language.OrderBy)2 SetQuery (org.teiid.language.SetQuery)2 ColumnReference (org.teiid.language.ColumnReference)1 LanguageObject (org.teiid.language.LanguageObject)1 Limit (org.teiid.language.Limit)1 SortSpecification (org.teiid.language.SortSpecification)1 With (org.teiid.language.With)1