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