Search in sources :

Example 51 with TempMetadataStore

use of org.teiid.query.metadata.TempMetadataStore 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 TempMetadataStore

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

the class TestResolver method testSelectIntoWithNullLiteral.

@Test
public void testSelectIntoWithNullLiteral() {
    // $NON-NLS-1$
    String sql = "select null as x into #temp from pm1.g1";
    Query query = (Query) helpResolve(sql);
    TempMetadataStore store = query.getTemporaryMetadata();
    // $NON-NLS-1$
    TempMetadataID id = store.getTempElementID("#temp.x");
    assertEquals(DataTypeManager.DefaultDataClasses.STRING, id.getType());
}
Also used : XMLQuery(org.teiid.query.sql.symbol.XMLQuery) TempMetadataID(org.teiid.query.metadata.TempMetadataID) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) Test(org.junit.Test)

Aggregations

TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)52 TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)45 Test (org.junit.Test)33 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)32 Ignore (org.junit.Ignore)21 TempMetadataID (org.teiid.query.metadata.TempMetadataID)6 CommandContext (org.teiid.query.util.CommandContext)6 List (java.util.List)5 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)5 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)5 Command (org.teiid.query.sql.lang.Command)5 GroupContext (org.teiid.query.sql.lang.GroupContext)5 Expression (org.teiid.query.sql.symbol.Expression)5 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)4 ArrayList (java.util.ArrayList)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)3 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)3 LinkedList (java.util.LinkedList)2