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);
}
Aggregations