Search in sources :

Example 66 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestProcedureProcessor method testFunctionInput.

/**
 * defect 23975
 */
@Test
public void testFunctionInput() throws Exception {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
    // $NON-NLS-1$
    ProcedureParameter p1 = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnSet<Procedure> rs1 = RealMetadataFactory.createResultSet("v1.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN declare string VARIABLES.x = '1'; exec v1.vp2(concat(x, v1.vp1.in)); END");
    // $NON-NLS-1$
    Procedure vt1 = RealMetadataFactory.createVirtualProcedure("vp1", v1, Arrays.asList(p1), n1);
    vt1.setResultSet(rs1);
    // $NON-NLS-1$
    ProcedureParameter p2 = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode n2 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN select v1.vp2.in; end");
    // $NON-NLS-1$
    Procedure vt2 = RealMetadataFactory.createVirtualProcedure("vp2", v1, Arrays.asList(p2), n2);
    // $NON-NLS-1$ //$NON-NLS-2$
    vt2.setResultSet(RealMetadataFactory.createResultSet("v1.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING }));
    // $NON-NLS-1$
    String sql = "exec v1.vp1('1')";
    List[] expected = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "11" }) };
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
    // Construct data manager with data
    // Plan query
    ProcessorPlan plan = getProcedurePlan(sql, metadata);
    // Run query
    helpTestProcess(plan, expected, new FakeDataManager(), metadata);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) ProcedureParameter(org.teiid.metadata.ProcedureParameter) FakeDataManager(org.teiid.query.processor.FakeDataManager) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure) List(java.util.List) ArrayList(java.util.ArrayList) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 67 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager 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 68 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestProcedureProcessor method testDynamicCommandWithIntoExpression.

@Test
public void testDynamicCommandWithIntoExpression() throws Exception {
    // Test INTO clause with expression
    TransformationMetadata metadata = RealMetadataFactory.example1();
    String query = // $NON-NLS-1$ //$NON-NLS-2$
    "CREATE VIRTUAL PROCEDURE BEGIN\n" + "execute string 'SELECT e1 FROM pm1.g1 WHERE e1 = ''First''' as x string into #temp; declare string VARIABLES.RESULT = select x from #temp;select VARIABLES.RESULT; END";
    addProc(metadata, query);
    // $NON-NLS-1$
    String userUpdateStr = "EXEC pm1.sq2()";
    FakeDataManager dataMgr = exampleDataManager(metadata);
    ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
    // Create expected results
    List[] expected = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "First" }) };
    helpTestProcess(plan, expected, dataMgr, metadata);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FakeDataManager(org.teiid.query.processor.FakeDataManager) List(java.util.List) ArrayList(java.util.ArrayList) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 69 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestProcedureProcessor method testDifferentlyScopedTempTables.

@Test
public void testDifferentlyScopedTempTables() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.example1();
    // $NON-NLS-1$
    StringBuffer procedure = new StringBuffer("CREATE VIRTUAL PROCEDURE \n");
    // $NON-NLS-1$
    procedure.append("BEGIN\n");
    // $NON-NLS-1$
    procedure.append("declare integer VARIABLES.e2_total=0;\n");
    // $NON-NLS-1$
    procedure.append("if (e2_total = 0)");
    // $NON-NLS-1$
    procedure.append("BEGIN\n");
    // $NON-NLS-1$
    procedure.append("select e1 into #temp from pm1.g1;\n");
    // $NON-NLS-1$
    procedure.append("VARIABLES.e2_total=select count(*) from #temp;\n");
    // $NON-NLS-1$
    procedure.append("END\n");
    // $NON-NLS-1$
    procedure.append("if (e2_total = 3)");
    // $NON-NLS-1$
    procedure.append("BEGIN\n");
    // $NON-NLS-1$
    procedure.append("select e1 into #temp from pm1.g1;\n");
    // $NON-NLS-1$
    procedure.append("VARIABLES.e2_total=select count(*) from #temp;\n");
    // $NON-NLS-1$
    procedure.append("END\n");
    // $NON-NLS-1$
    procedure.append("SELECT cast(VARIABLES.e2_total as string);\n");
    // $NON-NLS-1$
    procedure.append("END");
    addProc(metadata, procedure.toString());
    // $NON-NLS-1$
    String userUpdateStr = "EXEC pm1.sq2()";
    FakeDataManager dataMgr = exampleDataManager(metadata);
    ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
    // Create expected results
    List[] expected = new List[] { Arrays.asList("3") };
    helpTestProcess(plan, expected, dataMgr, metadata);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FakeDataManager(org.teiid.query.processor.FakeDataManager) List(java.util.List) ArrayList(java.util.ArrayList) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 70 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestProcedureProcessor method testParamsWithResultSetVirtualNotNull.

@Test(expected = QueryProcessingException.class)
public void testParamsWithResultSetVirtualNotNull() throws Exception {
    // $NON-NLS-1$
    String sql = "{? = call TEIIDSP9(51)}";
    TransformationMetadata metadata = RealMetadataFactory.exampleBQTCached();
    ProcessorPlan plan = getProcedurePlan(sql, metadata);
    FakeDataManager dataMgr = new FakeDataManager();
    helpTestProcess(plan, null, dataMgr, metadata);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FakeDataManager(org.teiid.query.processor.FakeDataManager) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Aggregations

FakeDataManager (org.teiid.query.processor.FakeDataManager)112 Test (org.junit.Test)103 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)86 ArrayList (java.util.ArrayList)81 List (java.util.List)81 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)48 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 CommandContext (org.teiid.query.util.CommandContext)8 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)7 FunctionDescriptor (org.teiid.query.function.FunctionDescriptor)6 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 BufferManager (org.teiid.common.buffer.BufferManager)4 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)3 Constant (org.teiid.query.sql.symbol.Constant)3 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)3 Function (org.teiid.query.sql.symbol.Function)3 Evaluator (org.teiid.query.eval.Evaluator)2 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)2