Search in sources :

Example 11 with SetQuery

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);
}
Also used : SetQuery(org.teiid.query.sql.lang.SetQuery) Constant(org.teiid.query.sql.symbol.Constant) Limit(org.teiid.query.sql.lang.Limit) Test(org.junit.Test)

Example 12 with 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;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Query(org.teiid.query.sql.lang.Query) SetQuery(org.teiid.query.sql.lang.SetQuery) Constant(org.teiid.query.sql.symbol.Constant) SymbolMap(org.teiid.query.sql.util.SymbolMap)

Example 13 with SetQuery

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);
    }
}
Also used : SetQuery(org.teiid.query.sql.lang.SetQuery) SetQuery(org.teiid.query.sql.lang.SetQuery) Query(org.teiid.query.sql.lang.Query) Expression(org.teiid.query.sql.symbol.Expression)

Example 14 with SetQuery

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());
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) SetQuery(org.teiid.query.sql.lang.SetQuery) Expression(org.teiid.query.sql.symbol.Expression) ArrayList(java.util.ArrayList)

Example 15 with SetQuery

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();
}
Also used : SetQuery(org.teiid.query.sql.lang.SetQuery) HashMap(java.util.HashMap) RecursiveTableProcessor(org.teiid.query.tempdata.TempTableStore.RecursiveTableProcessor) TableProcessor(org.teiid.query.tempdata.TempTableStore.TableProcessor) WithQueryCommand(org.teiid.query.sql.lang.WithQueryCommand) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) QueryProcessor(org.teiid.query.processor.QueryProcessor) RecursiveTableProcessor(org.teiid.query.tempdata.TempTableStore.RecursiveTableProcessor)

Aggregations

SetQuery (org.teiid.query.sql.lang.SetQuery)24 Test (org.junit.Test)10 Query (org.teiid.query.sql.lang.Query)9 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)9 Select (org.teiid.query.sql.lang.Select)6 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)6 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)6 From (org.teiid.query.sql.lang.From)5 WithQueryCommand (org.teiid.query.sql.lang.WithQueryCommand)5 ArrayList (java.util.ArrayList)4 Expression (org.teiid.query.sql.symbol.Expression)4 List (java.util.List)3 Constant (org.teiid.query.sql.symbol.Constant)3 Insert (org.teiid.query.sql.lang.Insert)2 Limit (org.teiid.query.sql.lang.Limit)2 QueryCommand (org.teiid.query.sql.lang.QueryCommand)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)1