Search in sources :

Example 1 with BatchedUpdateCommand

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

the class TestDataTierManager method testCheckForUpdatesWithBatched.

@Test
public void testCheckForUpdatesWithBatched() throws Exception {
    helpSetupDataTierManager();
    QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
    AtomicRequestMessage request = helpSetupRequest("delete from bqt1.smalla", 1, metadata);
    Command command = helpGetCommand("insert into bqt1.smalla (stringkey) values ('1')", metadata);
    BatchedUpdateCommand bac = new BatchedUpdateCommand(Arrays.asList(request.getCommand(), command));
    request.setCommand(bac);
    DataTierTupleSource dtts = new DataTierTupleSource(request, workItem, connectorManager.registerRequest(request), dtm, limit);
    pullTuples(dtts, 2);
}
Also used : Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) Test(org.junit.Test)

Example 2 with BatchedUpdateCommand

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

the class TestBatchedUpdatesImpl method helpExample.

public static BatchedUpdateCommand helpExample() {
    List updates = new ArrayList();
    // $NON-NLS-1$
    updates.add(TestInsertImpl.helpExample("a.b"));
    updates.add(TestUpdateImpl.helpExample());
    updates.add(TestDeleteImpl.helpExample());
    return new BatchedUpdateCommand(updates);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand)

Example 3 with BatchedUpdateCommand

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

the class ProjectIntoNode method nextBatchDirect.

/**
 * Get batch from child node
 * Walk through each row of child batch
 *    Bind values to insertCommand
 *    Execute insertCommand
 *    Update insertCount
 * When no more data is available, output batch with single row containing insertCount
 */
public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
    while (phase == REQUEST_CREATION) {
        /* If we don't have a batch to work, get the next
             */
        if (currentBatch == null) {
            if (sourceDone) {
                phase = RESPONSE_PROCESSING;
                break;
            }
            // can throw BlockedException
            currentBatch = getChildren()[0].nextBatch();
            sourceDone = currentBatch.getTerminationFlag();
            this.batchRow = currentBatch.getBeginRow();
            // and for implicit temp tables we need to issue an empty insert
            if (currentBatch.getRowCount() == 0 && (!currentBatch.getTerminationFlag() || mode != Mode.ITERATOR)) {
                currentBatch = null;
                continue;
            }
            if (this.constraint != null) {
                // row based security check
                if (eval == null) {
                    eval = new Evaluator(createLookupMap(this.intoElements), this.getDataManager(), getContext());
                }
                List<List<?>> tuples = this.currentBatch.getTuples();
                for (int i = 0; i < tuples.size(); i++) {
                    if (!eval.evaluate(constraint, tuples.get(i))) {
                        throw new QueryProcessingException(QueryPlugin.Event.TEIID31130, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31130, new Insert(intoGroup, this.intoElements, convertValuesToConstants(tuples.get(i), intoElements))));
                    }
                }
            }
        }
        if (mode != Mode.ITERATOR) {
            // delay the check in the iterator case to accumulate batches
            checkExitConditions();
        }
        int batchSize = currentBatch.getRowCount();
        int requests = 1;
        switch(mode) {
            case ITERATOR:
                if (buffer == null) {
                    buffer = getBufferManager().createTupleBuffer(intoElements, getConnectionID(), TupleSourceType.PROCESSOR);
                }
                if (sourceDone) {
                    // if there is a pending request we can't process the last until it is done
                    checkExitConditions();
                }
                for (List<?> tuple : currentBatch.getTuples()) {
                    buffer.addTuple(tuple);
                }
                try {
                    checkExitConditions();
                } catch (BlockedException e) {
                    // move to the next batch
                    this.batchRow += batchSize;
                    currentBatch = null;
                    continue;
                }
                if (currentBatch.getTerminationFlag() && (buffer.getRowCount() != 0 || intoGroup.isImplicitTempGroupSymbol())) {
                    registerIteratorRequest();
                } else if (buffer.getRowCount() >= buffer.getBatchSize() * 4) {
                    registerIteratorRequest();
                } else {
                    requests = 0;
                }
                break;
            case BATCH:
                // Register batched update command against source
                long endRow = currentBatch.getEndRow();
                List<Command> rows = new ArrayList<Command>((int) (endRow - batchRow));
                for (long rowNum = batchRow; rowNum <= endRow; rowNum++) {
                    Insert insert = new Insert(intoGroup, intoElements, convertValuesToConstants(currentBatch.getTuple(rowNum), intoElements));
                    insert.setSourceHint(sourceHint);
                    insert.setUpsert(upsert);
                    rows.add(insert);
                }
                registerRequest(new BatchedUpdateCommand(rows));
                break;
            case SINGLE:
                batchSize = 1;
                // Register insert command against source
                // Defect 16036 - submit a new INSERT command to the DataManager.
                Insert insert = new Insert(intoGroup, intoElements, convertValuesToConstants(currentBatch.getTuple(batchRow), intoElements));
                insert.setSourceHint(sourceHint);
                insert.setUpsert(upsert);
                registerRequest(insert);
        }
        this.batchRow += batchSize;
        if (batchRow > currentBatch.getEndRow()) {
            currentBatch = null;
        }
        this.requestsRegistered += requests;
    }
    checkExitConditions();
    if (this.buffer != null) {
        this.buffer.remove();
        this.buffer = null;
    }
    // End this node's work
    // report only a max int
    int count = (int) Math.min(Integer.MAX_VALUE, insertCount);
    addBatchRow(Arrays.asList(count));
    terminateBatches();
    return pullBatch();
}
Also used : ArrayList(java.util.ArrayList) Evaluator(org.teiid.query.eval.Evaluator) Insert(org.teiid.query.sql.lang.Insert) BlockedException(org.teiid.common.buffer.BlockedException) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) SourceHint(org.teiid.query.sql.lang.SourceHint) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) ArrayList(java.util.ArrayList) List(java.util.List) QueryProcessingException(org.teiid.api.exception.query.QueryProcessingException)

Example 4 with BatchedUpdateCommand

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

the class TestGroupCollectorVisitor method testBatchedUpdateCommand.

public void testBatchedUpdateCommand() {
    GroupSymbol g1 = exampleGroupSymbol(1);
    GroupSymbol g2 = exampleGroupSymbol(2);
    GroupSymbol g3 = exampleGroupSymbol(3);
    Insert insert = new Insert();
    insert.setGroup(g1);
    Update update = new Update();
    update.setGroup(g2);
    Delete delete = new Delete();
    delete.setGroup(g3);
    List updates = new ArrayList(3);
    updates.add(insert);
    updates.add(update);
    updates.add(delete);
    Set groups = new HashSet();
    groups.add(g1);
    groups.add(g2);
    groups.add(g3);
    helpTestGroups(new BatchedUpdateCommand(updates), true, groups);
}
Also used : Delete(org.teiid.query.sql.lang.Delete) Set(java.util.Set) HashSet(java.util.HashSet) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Insert(org.teiid.query.sql.lang.Insert) Update(org.teiid.query.sql.lang.Update) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) HashSet(java.util.HashSet)

Example 5 with BatchedUpdateCommand

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

the class Request method parseCommand.

private Command parseCommand() throws QueryParserException {
    if (requestMsg.getCommand() != null) {
        return (Command) requestMsg.getCommand();
    }
    String[] commands = requestMsg.getCommands();
    ParseInfo parseInfo = createParseInfo(this.requestMsg, this.workContext.getSession());
    QueryParser queryParser = QueryParser.getQueryParser();
    if (requestMsg.isPreparedStatement() || requestMsg.isCallableStatement() || !requestMsg.isBatchedUpdate()) {
        String commandStr = commands[0];
        if (preParser != null) {
            commandStr = preParser.preParse(commandStr, this.context);
        }
        return queryParser.parseCommand(commandStr, parseInfo);
    }
    List<Command> parsedCommands = new ArrayList<Command>(commands.length);
    for (int i = 0; i < commands.length; i++) {
        String updateCommand = commands[i];
        if (preParser != null) {
            updateCommand = preParser.preParse(updateCommand, this.context);
        }
        parsedCommands.add(queryParser.parseCommand(updateCommand, parseInfo));
    }
    return new BatchedUpdateCommand(parsedCommands);
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) Command(org.teiid.query.sql.lang.Command) QueryCommand(org.teiid.query.sql.lang.QueryCommand) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) ArrayList(java.util.ArrayList) ParseInfo(org.teiid.query.parser.ParseInfo) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand)

Aggregations

BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)17 Command (org.teiid.query.sql.lang.Command)13 List (java.util.List)10 ArrayList (java.util.ArrayList)8 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)5 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)4 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)4 Insert (org.teiid.query.sql.lang.Insert)4 Test (org.junit.Test)3 BlockedException (org.teiid.common.buffer.BlockedException)2 AtomicRequestMessage (org.teiid.dqp.message.AtomicRequestMessage)2 Evaluator (org.teiid.query.eval.Evaluator)2 SourceCapabilities (org.teiid.query.optimizer.capabilities.SourceCapabilities)2 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)2 Constant (org.teiid.query.sql.symbol.Constant)2 VariableContext (org.teiid.query.sql.util.VariableContext)2 CommandContext (org.teiid.query.util.CommandContext)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1