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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations