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