Search in sources :

Example 11 with BatchedUpdateCommand

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());
    }
}
Also used : BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand)

Example 12 with BatchedUpdateCommand

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));
    }
}
Also used : CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) ArrayList(java.util.ArrayList) Evaluator(org.teiid.query.eval.Evaluator) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) RegisterRequestParameter(org.teiid.query.processor.RegisterRequestParameter)

Example 13 with BatchedUpdateCommand

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();
}
Also used : Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage)

Example 14 with BatchedUpdateCommand

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

Example 15 with BatchedUpdateCommand

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());
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) Table(org.teiid.metadata.Table) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Constant(org.teiid.query.sql.symbol.Constant) Schema(org.teiid.metadata.Schema) Insert(org.teiid.query.sql.lang.Insert) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) MetadataStore(org.teiid.metadata.MetadataStore) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

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