Search in sources :

Example 16 with SetQuery

use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.

the class RelationalPlan method reset.

/**
 * @see org.teiid.query.processor.ProcessorPlan#reset()
 */
public void reset() {
    super.reset();
    this.root.reset();
    if (this.with != null) {
        for (WithQueryCommand withCommand : this.with) {
            if (withCommand.isRecursive()) {
                SetQuery setQuery = (SetQuery) withCommand.getCommand();
                setQuery.getLeftQuery().getProcessorPlan().reset();
                setQuery.getLeftQuery().getProcessorPlan().reset();
            } else {
                withCommand.getCommand().getProcessorPlan().reset();
            }
        }
    }
}
Also used : SetQuery(org.teiid.query.sql.lang.SetQuery) WithQueryCommand(org.teiid.query.sql.lang.WithQueryCommand)

Example 17 with SetQuery

use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.

the class SetQueryResolver method resolveCommand.

/**
 * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean)
 */
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
    SetQuery setQuery = (SetQuery) command;
    SimpleQueryResolver.resolveWith(metadata, setQuery);
    QueryCommand firstCommand = setQuery.getLeftQuery();
    QueryResolver.setChildMetadata(firstCommand, setQuery);
    QueryResolver.resolveCommand(firstCommand, metadata.getMetadata(), false);
    QueryCommand rightCommand = setQuery.getRightQuery();
    QueryResolver.setChildMetadata(rightCommand, setQuery);
    QueryResolver.resolveCommand(rightCommand, metadata.getMetadata(), false);
    resolveSetQuery(metadata, resolveNullLiterals, setQuery, firstCommand, rightCommand);
}
Also used : SetQuery(org.teiid.query.sql.lang.SetQuery) QueryCommand(org.teiid.query.sql.lang.QueryCommand)

Example 18 with SetQuery

use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.

the class RelationalPlan method clone.

public RelationalPlan clone() {
    RelationalPlan plan = new RelationalPlan((RelationalNode) root.clone());
    plan.setOutputElements(outputCols);
    if (with != null) {
        List<WithQueryCommand> newWith = LanguageObject.Util.deepClone(this.with, WithQueryCommand.class);
        for (WithQueryCommand withQueryCommand : newWith) {
            if (withQueryCommand.isRecursive()) {
                SetQuery setQuery = (SetQuery) withQueryCommand.getCommand();
                setQuery.getLeftQuery().setProcessorPlan(setQuery.getLeftQuery().getProcessorPlan().clone());
                setQuery.getRightQuery().setProcessorPlan(setQuery.getRightQuery().getProcessorPlan().clone());
            } else {
                withQueryCommand.getCommand().setProcessorPlan(withQueryCommand.getCommand().getProcessorPlan().clone());
            }
        }
        plan.setWith(newWith);
    }
    return plan;
}
Also used : SetQuery(org.teiid.query.sql.lang.SetQuery) WithQueryCommand(org.teiid.query.sql.lang.WithQueryCommand)

Example 19 with SetQuery

use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.

the class UpdateValidator method validate.

public void validate(Command command, List<ElementSymbol> viewSymbols) throws QueryMetadataException, TeiidComponentException {
    if (this.updateInfo.deleteType != UpdateType.INHERENT && this.updateInfo.updateType != UpdateType.INHERENT && this.updateInfo.insertType != UpdateType.INHERENT) {
        return;
    }
    if (command instanceof SetQuery) {
        SetQuery setQuery = (SetQuery) command;
        if (setQuery.getLimit() != null) {
            // $NON-NLS-1$
            handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0013"), true, true, true);
            return;
        }
        LinkedList<Query> queries = new LinkedList<Query>();
        if (!PartitionAnalyzer.extractQueries((SetQuery) command, queries)) {
            // $NON-NLS-1$
            handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0001"), true, true, true);
            return;
        }
        Map<ElementSymbol, List<Set<Constant>>> partitions = PartitionAnalyzer.extractPartionInfo((SetQuery) command, viewSymbols);
        this.updateInfo.partitionInfo = partitions;
        if (partitions.isEmpty()) {
            // $NON-NLS-1$
            handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0018"), false, true, false);
        }
        boolean first = true;
        for (Query query : queries) {
            UpdateInfo ui = this.updateInfo;
            if (!first) {
                this.updateInfo = new UpdateInfo();
                this.updateInfo.deleteType = ui.deleteType;
                this.updateInfo.insertType = ui.insertType;
                this.updateInfo.updateType = ui.updateType;
            }
            internalValidate(query, viewSymbols);
            // accumulate the errors on the first branch - will be checked at resolve time
            if (this.updateInfo.getDeleteValidationError() != null) {
                ui.setDeleteValidationError(this.updateInfo.getDeleteValidationError());
            }
            if (this.updateInfo.getUpdateValidationError() != null) {
                ui.setUpdateValidationError(this.updateInfo.getUpdateValidationError());
            }
            if (this.updateInfo.getInsertValidationError() != null) {
                ui.setInsertValidationError(this.updateInfo.getInsertValidationError());
            }
            if (!first) {
                ui.unionBranches.add(this.updateInfo);
                this.updateInfo = ui;
            } else {
                first = false;
            }
        }
        return;
    }
    internalValidate(command, viewSymbols);
    if (this.updateInfo.deleteType != UpdateType.INHERENT) {
        this.deleteReport.getItems().clear();
        this.updateInfo.deleteValidationError = null;
    }
    if (this.updateInfo.updateType != UpdateType.INHERENT) {
        this.updateReport.getItems().clear();
        this.updateInfo.updateValidationError = null;
    }
    if (this.updateInfo.insertType != UpdateType.INHERENT) {
        this.insertReport.getItems().clear();
        this.updateInfo.insertValidationError = null;
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) SetQuery(org.teiid.query.sql.lang.SetQuery) SetQuery(org.teiid.query.sql.lang.SetQuery) Query(org.teiid.query.sql.lang.Query) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 20 with SetQuery

use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.

the class TestLimitParsing method testSetQueryLimit.

@Test
public void testSetQueryLimit() {
    Query query = new Query();
    Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
    // $NON-NLS-1$
    From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a"))));
    query.setSelect(select);
    query.setFrom(from);
    SetQuery setQuery = new SetQuery(Operation.UNION, true, query, query);
    setQuery.setLimit(new Limit(new Reference(0), new Reference(1)));
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTest("Select * from a union all Select * from a limit ?,?", "SELECT * FROM a UNION ALL SELECT * FROM a LIMIT ?, ?", setQuery);
}
Also used : MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) SetQuery(org.teiid.query.sql.lang.SetQuery) Query(org.teiid.query.sql.lang.Query) SetQuery(org.teiid.query.sql.lang.SetQuery) UnaryFromClause(org.teiid.query.sql.lang.UnaryFromClause) Reference(org.teiid.query.sql.symbol.Reference) Select(org.teiid.query.sql.lang.Select) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) From(org.teiid.query.sql.lang.From) Limit(org.teiid.query.sql.lang.Limit) Test(org.junit.Test)

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