use of org.teiid.query.sql.lang.BatchedUpdateCommand in project teiid by teiid.
the class BatchedUpdateResolver method resolveCommand.
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
BatchedUpdateCommand batchedUpdateCommand = (BatchedUpdateCommand) command;
for (Command subCommand : batchedUpdateCommand.getUpdateCommands()) {
QueryResolver.setChildMetadata(subCommand, command);
QueryResolver.resolveCommand(subCommand, metadata.getMetadata());
}
}
use of org.teiid.query.sql.lang.BatchedUpdateCommand in project teiid by teiid.
the class BatchedUpdateNode method open.
/**
* @see org.teiid.query.processor.relational.RelationalNode#open()
* @since 4.2
*/
public void open() throws TeiidComponentException, TeiidProcessingException {
super.open();
unexecutedCommands = new boolean[updateCommands.size()];
List<Command> commandsToExecute = new ArrayList<Command>(updateCommands.size());
// Find the commands to be executed
for (int i = 0; i < updateCommands.size(); i++) {
Command updateCommand = (Command) updateCommands.get(i).clone();
CommandContext context = this.getContext();
if (this.contexts != null && !this.contexts.isEmpty()) {
context = context.clone();
context.setVariableContext(this.contexts.get(i));
}
boolean needProcessing = false;
if (shouldEvaluate != null && shouldEvaluate.get(i)) {
updateCommand = (Command) updateCommand.clone();
Evaluator eval = getEvaluator(Collections.emptyMap());
eval.initialize(context, getDataManager());
AccessNode.rewriteAndEvaluate(updateCommand, eval, context, context.getMetadata());
}
needProcessing = RelationalNodeUtil.shouldExecute(updateCommand, true);
if (needProcessing) {
commandsToExecute.add(updateCommand);
} else {
unexecutedCommands[i] = true;
}
}
if (!commandsToExecute.isEmpty()) {
BatchedUpdateCommand command = new BatchedUpdateCommand(commandsToExecute);
RowBasedSecurityHelper.checkConstraints(command, getEvaluator(Collections.emptyMap()));
tupleSource = getDataManager().registerRequest(getContext(), command, modelName, new RegisterRequestParameter(null, getID(), -1));
}
}
use of org.teiid.query.sql.lang.BatchedUpdateCommand in project teiid by teiid.
the class TestConnectorWorkItem method helpExecuteUpdate.
private AtomicResultsMessage helpExecuteUpdate(boolean batch, boolean single) throws Exception, Throwable {
// $NON-NLS-1$
Command command = helpGetCommand("update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT);
if (batch) {
command = new BatchedUpdateCommand(Arrays.asList(command, command));
}
AtomicRequestMessage arm = createNewAtomicRequestMessage(1, 1);
arm.setCommand(command);
ConnectorManager connectorManager = TestConnectorManager.getConnectorManager();
((FakeConnector) connectorManager.getExecutionFactory()).setReturnSingleUpdate(single);
ConnectorWorkItem synchConnectorWorkItem = new ConnectorWorkItem(arm, connectorManager);
synchConnectorWorkItem.execute();
return synchConnectorWorkItem.more();
}
use of org.teiid.query.sql.lang.BatchedUpdateCommand in project teiid by teiid.
the class TestInherintlyUpdatableViews method testDeleteUnion.
@Test
public void testDeleteUnion() throws Exception {
// $NON-NLS-1$
String userSql = "delete from vm1.gx where e4 is null";
String viewSql = "select * from pm1.g1 where e3 < 5 union all select * from pm1.g2 where e1 > 1";
String expectedSql = "BatchedUpdate{D,D}";
BatchedUpdateCommand buc = (BatchedUpdateCommand) helpTest(userSql, viewSql, expectedSql, null);
assertEquals("DELETE FROM pm1.g2 WHERE (pm1.g2.e4 IS NULL) AND (e1 > '1')", buc.getUpdateCommands().get(1).toString());
}
use of org.teiid.query.sql.lang.BatchedUpdateCommand in project teiid by teiid.
the class TestInsertProcessing method testSelectIntoWithTypeConversion.
@Test
public void testSelectIntoWithTypeConversion() {
MetadataStore metadataStore = new MetadataStore();
// $NON-NLS-1$
Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
// $NON-NLS-1$
Table pm1g1 = RealMetadataFactory.createPhysicalGroup("g1", pm1);
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.BATCHED_UPDATES, true);
caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new String[] { "e1", "e2", "e3" }, new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.FLOAT, DataTypeManager.DefaultDataTypes.FLOAT });
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
HardcodedDataManager dataManager = new HardcodedDataManager();
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"BatchedUpdate{I}", new List[] { Arrays.asList(new Object[] { new Integer(1) }) });
// $NON-NLS-1$
String sql = "SELECT 1, convert(1, float), convert(1, float) INTO pm1.g1";
Command command = helpParse(sql);
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
List<?>[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1) }) };
helpProcess(plan, dataManager, expected);
BatchedUpdateCommand buc = (BatchedUpdateCommand) dataManager.getCommandHistory().iterator().next();
Insert insert = (Insert) buc.getUpdateCommands().get(0);
Constant value0 = (Constant) insert.getValues().get(0);
Constant value1 = (Constant) insert.getValues().get(1);
assertEquals(DataTypeManager.DefaultDataClasses.BIG_INTEGER, value0.getValue().getClass());
assertEquals(DataTypeManager.DefaultDataClasses.FLOAT, value1.getValue().getClass());
}
Aggregations