Search in sources :

Example 51 with TempMetadataAdapter

use of org.teiid.query.metadata.TempMetadataAdapter in project teiid by teiid.

the class TestProcedureProcessor method testBeginAtomic.

@Test
public void testBeginAtomic() throws Exception {
    String proc = // $NON-NLS-1$
    "CREATE VIRTUAL PROCEDURE " + // $NON-NLS-1$
    "BEGIN ATOMIC" + // $NON-NLS-1$
    " select e1, e2, e3, e4 into #t1 from pm1.g1;\n" + // $NON-NLS-1$
    " update #t1 set e1 = 1 where e4 < 2;\n" + // $NON-NLS-1$
    " delete from #t1 where e4 > 2;\n" + // $NON-NLS-1$
    " select e2/\"in\" from #t1;\n" + // $NON-NLS-1$
    "END";
    TransformationMetadata tm = RealMetadataFactory.example1();
    addProc(tm, "sq1", proc, new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER }, new String[] { "in" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
    FakeDataManager dataMgr = exampleDataManager(tm);
    // $NON-NLS-1$
    CommandContext context = new CommandContext("pID", null, null, null, 1);
    QueryMetadataInterface metadata = new TempMetadataAdapter(tm, new TempMetadataStore());
    context.setMetadata(metadata);
    TransactionContext tc = new TransactionContext();
    TransactionService ts = Mockito.mock(TransactionService.class);
    context.setTransactionService(ts);
    context.setTransactionContext(tc);
    // $NON-NLS-1$
    String userQuery = "EXEC pm1.sq1(1)";
    ProcessorPlan plan = getProcedurePlan(userQuery, tm, TestOptimizer.getGenericFinder());
    List[] expected = new List[] { Arrays.asList(5) };
    TestProcessor.helpProcess(plan, context, dataMgr, expected);
    Mockito.verify(ts, Mockito.times(3)).begin(tc);
    Mockito.verify(ts, Mockito.times(3)).commit(tc);
    tc = new TransactionContext();
    ts = Mockito.mock(TransactionService.class);
    context.setTransactionService(ts);
    context.setTransactionContext(tc);
    // $NON-NLS-1$
    userQuery = "EXEC pm1.sq1(0)";
    plan = getProcedurePlan(userQuery, tm, TestOptimizer.getGenericFinder());
    expected = null;
    try {
        TestProcessor.helpProcess(plan, context, dataMgr, expected);
        fail();
    } catch (TeiidProcessingException e) {
    }
    Mockito.verify(ts).begin(tc);
    Mockito.verify(ts, Mockito.times(2)).resume(tc);
    Mockito.verify(ts, Mockito.times(0)).commit(tc);
    Mockito.verify(ts).rollback(tc);
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) TransactionService(org.teiid.dqp.service.TransactionService) FakeDataManager(org.teiid.query.processor.FakeDataManager) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TransactionContext(org.teiid.dqp.service.TransactionContext) List(java.util.List) ArrayList(java.util.ArrayList) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) Test(org.junit.Test)

Example 52 with TempMetadataAdapter

use of org.teiid.query.metadata.TempMetadataAdapter in project teiid by teiid.

the class TestTempTables method testIsolateReads.

@Test
public void testIsolateReads() throws Exception {
    GlobalTableStoreImpl gtsi = new GlobalTableStoreImpl(BufferManagerFactory.getStandaloneBufferManager(), RealMetadataFactory.example1Cached().getVdbMetaData(), RealMetadataFactory.example1Cached());
    tempStore = gtsi.getTempTableStore();
    metadata = new TempMetadataAdapter(RealMetadataFactory.example1Cached(), tempStore.getMetadataStore());
    // $NON-NLS-1$
    execute("create local temporary table x (e1 string, e2 integer)", new List[] { Arrays.asList(0) });
    for (int i = 0; i < 300; i++) {
        // $NON-NLS-1$
        execute("insert into x (e2, e1) select e2, e1 from pm1.g1", new List[] { Arrays.asList(6) });
    }
    setupTransaction(Connection.TRANSACTION_SERIALIZABLE);
    execute("select count(e1) from x", new List[] { Arrays.asList(1500) });
    gtsi.updateMatViewRow("X", Arrays.asList(2l), true);
    tc = null;
    // outside of the transaction we can see the row removed
    execute("select count(e1) from x", new List[] { Arrays.asList(1499) });
    // back in the transaction we see the original state
    setupTransaction(Connection.TRANSACTION_SERIALIZABLE);
    execute("select count(e1) from x", new List[] { Arrays.asList(1500) });
    synch.afterCompletion(Status.STATUS_COMMITTED);
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) GlobalTableStoreImpl(org.teiid.query.tempdata.GlobalTableStoreImpl) Test(org.junit.Test)

Example 53 with TempMetadataAdapter

use of org.teiid.query.metadata.TempMetadataAdapter in project teiid by teiid.

the class TestProcedureResolving method resolveProcedure.

private Command resolveProcedure(String userUpdateStr, QueryMetadataInterface metadata) throws QueryParserException, QueryResolverException, TeiidComponentException, QueryMetadataException {
    ProcedureContainer userCommand = (ProcedureContainer) QueryParser.getQueryParser().parseCommand(userUpdateStr);
    QueryResolver.resolveCommand(userCommand, metadata);
    metadata = new TempMetadataAdapter(metadata, userCommand.getTemporaryMetadata());
    return QueryResolver.expandCommand(userCommand, metadata, null);
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) ProcedureContainer(org.teiid.query.sql.lang.ProcedureContainer)

Aggregations

TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)53 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)45 Test (org.junit.Test)32 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)32 Ignore (org.junit.Ignore)21 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)9 CommandContext (org.teiid.query.util.CommandContext)6 List (java.util.List)4 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)4 TempMetadataID (org.teiid.query.metadata.TempMetadataID)4 Command (org.teiid.query.sql.lang.Command)4 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)4 TeiidComponentException (org.teiid.core.TeiidComponentException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)3 TempCapabilitiesFinder (org.teiid.query.metadata.TempCapabilitiesFinder)3 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)3 GroupContext (org.teiid.query.sql.lang.GroupContext)3 TempTableStore (org.teiid.query.tempdata.TempTableStore)3 ArrayList (java.util.ArrayList)2