Search in sources :

Example 1 with DerivedTable

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

Aggregations

ColumnReference (org.teiid.language.ColumnReference)1 DerivedColumn (org.teiid.language.DerivedColumn)1 DerivedTable (org.teiid.language.DerivedTable)1 Select (org.teiid.language.Select)1 SetQuery (org.teiid.language.SetQuery)1 TableReference (org.teiid.language.TableReference)1