Search in sources :

Example 1 with SetQuery

use of org.teiid.language.SetQuery 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 SetQuery

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

the class TestSetQueryImpl method testNestedSetQuery.

public void testNestedSetQuery() throws Exception {
    org.teiid.query.sql.lang.SetQuery query = new org.teiid.query.sql.lang.SetQuery(org.teiid.query.sql.lang.SetQuery.Operation.EXCEPT, true, helpExampleSetQuery(), helpExampleSetQuery());
    SetQuery setQuery = TstLanguageBridgeFactory.factory.translate(query);
    assertTrue(setQuery.getLeftQuery() instanceof SetQuery);
    assertTrue(setQuery.getRightQuery() instanceof SetQuery);
}
Also used : SetQuery(org.teiid.language.SetQuery)

Example 3 with SetQuery

use of org.teiid.language.SetQuery 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)

Example 4 with SetQuery

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

the class PhoenixExecutionFactory method translateCommand.

@Override
public List<?> translateCommand(Command command, ExecutionContext context) {
    if (command instanceof SetQuery) {
        SetQuery set = (SetQuery) command;
        if (!set.isAll()) {
            // distinct is not supported, convert to an inline view and add distinct
            Select s = new Select();
            s.setDistinct(true);
            s.setDerivedColumns(new ArrayList<DerivedColumn>());
            s.setOrderBy(set.getOrderBy());
            for (DerivedColumn dc : set.getProjectedQuery().getDerivedColumns()) {
                // it's expected that the columns will be aliases
                Assertion.assertTrue(dc.getAlias() != null);
                ColumnReference cr = new ColumnReference(null, dc.getAlias(), null, dc.getExpression().getType());
                s.getDerivedColumns().add(new DerivedColumn(null, cr));
            }
            set.setOrderBy(null);
            s.setLimit(set.getLimit());
            set.setLimit(null);
            set.setAll(true);
            // $NON-NLS-1$
            s.setFrom(Arrays.asList((TableReference) new DerivedTable(set, "x")));
            return Arrays.asList(s);
        }
    }
    return super.translateCommand(command, context);
}
Also used : TableReference(org.teiid.language.TableReference) SetQuery(org.teiid.language.SetQuery) DerivedTable(org.teiid.language.DerivedTable) Select(org.teiid.language.Select) DerivedColumn(org.teiid.language.DerivedColumn) ColumnReference(org.teiid.language.ColumnReference)

Example 5 with SetQuery

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

the class TestSetQueryImpl method example2.

public static SetQuery example2() throws Exception {
    // $NON-NLS-1$
    NamedTable group = new NamedTable("ted", null, null);
    // $NON-NLS-1$
    ColumnReference element = new ColumnReference(group, "nugent", null, String.class);
    DerivedColumn symbol = new DerivedColumn(null, element);
    List symbols = new ArrayList();
    symbols.add(symbol);
    List items = new ArrayList();
    items.add(group);
    // $NON-NLS-1$
    NamedTable group2 = new NamedTable("dave", null, null);
    // $NON-NLS-1$
    ColumnReference element2 = new ColumnReference(group2, "barry", null, String.class);
    DerivedColumn symbol2 = new DerivedColumn(null, element2);
    List symbols2 = new ArrayList();
    symbols2.add(symbol2);
    List items2 = new ArrayList();
    items2.add(group2);
    Select secondQuery = new Select(symbols2, false, items2, null, null, null, null);
    Select query = new Select(symbols, false, items, null, null, null, null);
    SetQuery setQuery = new SetQuery();
    setQuery.setOperation(SetQuery.Operation.UNION);
    setQuery.setAll(true);
    setQuery.setLeftQuery(query);
    setQuery.setRightQuery(secondQuery);
    return setQuery;
}
Also used : NamedTable(org.teiid.language.NamedTable) SetQuery(org.teiid.language.SetQuery) ArrayList(java.util.ArrayList) Select(org.teiid.language.Select) ArrayList(java.util.ArrayList) List(java.util.List) DerivedColumn(org.teiid.language.DerivedColumn) ColumnReference(org.teiid.language.ColumnReference)

Aggregations

SetQuery (org.teiid.language.SetQuery)5 ArrayList (java.util.ArrayList)3 ColumnReference (org.teiid.language.ColumnReference)3 DerivedColumn (org.teiid.language.DerivedColumn)2 OrderBy (org.teiid.language.OrderBy)2 Select (org.teiid.language.Select)2 List (java.util.List)1 DerivedTable (org.teiid.language.DerivedTable)1 LanguageObject (org.teiid.language.LanguageObject)1 Limit (org.teiid.language.Limit)1 NamedTable (org.teiid.language.NamedTable)1 SortSpecification (org.teiid.language.SortSpecification)1 TableReference (org.teiid.language.TableReference)1 With (org.teiid.language.With)1