use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.
the class TestSetQueryParsing method testUnionWithLimit.
@Test
public void testUnionWithLimit() {
SetQuery setQuery = exampleSetQuery(Operation.UNION);
setQuery.setLimit(new Limit(null, new Constant(1)));
// $NON-NLS-1$
TestParser.helpTest(// $NON-NLS-1$
"SELECT a FROM g UNION select b from h LIMIT 1", // $NON-NLS-1$
"SELECT a FROM g UNION SELECT b FROM h LIMIT 1", setQuery);
}
use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.
the class PartitionAnalyzer method extractPartionInfo.
public static Map<ElementSymbol, List<Set<Constant>>> extractPartionInfo(SetQuery setQuery, List<ElementSymbol> projectedSymbols) {
List<Query> queries = new LinkedList<Query>();
if (!extractQueries(setQuery, queries)) {
return Collections.emptyMap();
}
Map<ElementSymbol, List<Set<Constant>>> partitions = new LinkedHashMap<ElementSymbol, List<Set<Constant>>>();
boolean first = true;
for (Query query : queries) {
Map<ElementSymbol, Set<Constant>> info = extractPartitionInfo(query, projectedSymbols);
partitions.keySet().retainAll(info.keySet());
if (first) {
first = false;
for (Map.Entry<ElementSymbol, Set<Constant>> entry : info.entrySet()) {
ArrayList<Set<Constant>> values = new ArrayList<Set<Constant>>(queries.size());
partitions.put(entry.getKey(), values);
values.add(entry.getValue());
}
continue;
}
Set<ElementSymbol> keys = partitions.keySet();
for (Iterator<ElementSymbol> iter = keys.iterator(); iter.hasNext(); ) {
ElementSymbol elementSymbol = iter.next();
List<Set<Constant>> values = partitions.get(elementSymbol);
Set<Constant> value = info.get(elementSymbol);
for (Set<Constant> set : values) {
if (!Collections.disjoint(set, value)) {
iter.remove();
continue;
}
}
values.add(value);
}
}
return partitions;
}
use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.
the class MetadataValidator method determineDependencies.
private static void determineDependencies(Command command, Column c, int index, LinkedHashSet<AbstractMetadataRecord> columnValues) {
if (command instanceof Query) {
Expression ex = command.getProjectedSymbols().get(index);
collectDependencies(ex, columnValues);
} else if (command instanceof SetQuery) {
determineDependencies(((SetQuery) command).getLeftQuery(), c, index, columnValues);
determineDependencies(((SetQuery) command).getRightQuery(), c, index, columnValues);
}
}
use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.
the class QueryResolver method validateProjectedSymbols.
public static void validateProjectedSymbols(GroupSymbol virtualGroup, QueryMetadataInterface qmi, Command result) throws QueryMetadataException, TeiidComponentException, QueryValidatorException {
// ensure that null types match the view
List<ElementSymbol> symbols = ResolverUtil.resolveElementsInGroup(virtualGroup, qmi);
List<Expression> projectedSymbols = result.getProjectedSymbols();
validateProjectedSymbols(virtualGroup, symbols, projectedSymbols);
// setqueries store the projected types separately
if (result instanceof SetQuery) {
List<Class<?>> types = new ArrayList<Class<?>>();
for (ElementSymbol es : symbols) {
types.add(es.getType());
}
((SetQuery) result).setProjectedTypes(types, qmi.getDesignTimeMetadata());
}
}
use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.
the class RelationalPlan method open.
@Override
public void open() throws TeiidComponentException, TeiidProcessingException {
if (with != null && tempTableStore.getProcessors() == null) {
HashMap<String, TableProcessor> processors = new HashMap<String, TableProcessor>();
tempTableStore.setProcessors(processors);
for (WithQueryCommand withCommand : this.with) {
if (withCommand.isRecursive()) {
SetQuery setQuery = (SetQuery) withCommand.getCommand();
ProcessorPlan initial = setQuery.getLeftQuery().getProcessorPlan();
QueryProcessor withProcessor = new QueryProcessor(initial, getContext().clone(), root.getBufferManager(), root.getDataManager());
processors.put(withCommand.getGroupSymbol().getName(), new RecursiveTableProcessor(withProcessor, withCommand.getColumns(), setQuery.getRightQuery().getProcessorPlan(), setQuery.isAll()));
continue;
}
ProcessorPlan plan = withCommand.getCommand().getProcessorPlan();
QueryProcessor withProcessor = new QueryProcessor(plan, getContext().clone(), root.getBufferManager(), root.getDataManager());
processors.put(withCommand.getGroupSymbol().getName(), new TableProcessor(withProcessor, withCommand.getColumns()));
}
}
this.root.open();
}
Aggregations