use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.
the class TestProcedureProcessor method testDeclareWithQueryAssignment.
/**
* Test the procedure <code>DECLARE</code> statement using a query as the assignment value
*
* <p>The use of a query as the assignment value to a <code>DECLARE</code>
* statement should execute without error as long as the query
* is valid and fully resolvable.</p>
*
* <p>This test is related to JBEDSP-818 in which the query in the
* <code>LOOP</code> statement would fail due to a query being used as the
* assigned value in the <code>DECLARE</code> statement.</p>
* @throws Exception
*/
@Test
public void testDeclareWithQueryAssignment() throws Exception {
// procedure comes from test case IT236455 / JBEDSP-818
// $NON-NLS-1$
String procedure = "CREATE VIRTUAL PROCEDURE \n";
// $NON-NLS-1$
procedure += "BEGIN\n";
// $NON-NLS-1$
procedure += " DECLARE integer VARIABLES.var1 = 0;\n";
// $NON-NLS-1$
procedure += " /* the following DECLARE with ASSIGNMENT to a query should work ";
// $NON-NLS-1$
procedure += " but in IT236455 it results in the assignment inside the LOOP ";
// $NON-NLS-1$
procedure += " to fail */ ";
// $NON-NLS-1$
procedure += " DECLARE integer VARIABLES.NLEVELS = SELECT COUNT(*) FROM (\n";
// $NON-NLS-1$
procedure += " SELECT 'Col1' AS ACol1, 'Col2' AS ACol2, convert(3, integer) AS ACol3\n";
// $NON-NLS-1$
procedure += " ) AS Src;\n";
// $NON-NLS-1$
procedure += " LOOP ON (\n";
// $NON-NLS-1$
procedure += " SELECT StaticTable.BCol1, StaticTable.BCol2, StaticTable.BCol3 FROM (\n";
// $NON-NLS-1$
procedure += " SELECT 'Col 1' AS BCol1, 'Col 2' AS BCol2, convert(3, integer) AS BCol3\n";
// $NON-NLS-1$
procedure += " ) AS StaticTable\n";
// $NON-NLS-1$
procedure += " ) AS L1\n";
// $NON-NLS-1$
procedure += " BEGIN\n";
// $NON-NLS-1$
procedure += " /* In IT236455 the following would fail as the results from ";
// $NON-NLS-1$
procedure += " the LOOP (L1) are not in scope when the assignment is being ";
// $NON-NLS-1$
procedure += " performed due to the query earlier being part of a DECLARE ";
// $NON-NLS-1$
procedure += " statement. */ ";
// $NON-NLS-1$
procedure += " VARIABLES.var1 = L1.BCol3;\n";
// $NON-NLS-1$
procedure += " END\n";
// $NON-NLS-1$
procedure += " SELECT cast(VARIABLES.Var1 as string) AS e1;\n";
// $NON-NLS-1$
procedure += "END\n";
QueryMetadataInterface metadata = createProcedureMetadata(procedure);
// $NON-NLS-1$
String userQuery = "SELECT e1 FROM (EXEC pm1.sq1()) as proc";
FakeDataManager dataMgr = exampleDataManager(metadata);
ProcessorPlan plan = getProcedurePlan(userQuery, metadata);
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 testDynamicCommandWithVariable.
@Test
public void testDynamicCommandWithVariable() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.example1();
addProc(metadata, "sq2", // $NON-NLS-1$ //$NON-NLS-2$
"CREATE VIRTUAL PROCEDURE BEGIN\n" + "declare string VARIABLES.x; VARIABLES.x = pm1.sq2.in; execute string 'SELECT e1, e2 FROM pm1.g1 WHERE e1=VARIABLES.x'; END", new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER }, new String[] { "in" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
// $NON-NLS-1$
String userUpdateStr = "EXEC pm1.sq2('First')";
FakeDataManager dataMgr = exampleDataManager(metadata);
ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
// Create expected results
List[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "First", Integer.valueOf(5) }) };
helpTestProcess(plan, expected, dataMgr, metadata);
}
use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.
the class TestProcedureProcessor method exampleDataManager.
private FakeDataManager exampleDataManager(QueryMetadataInterface metadata) throws TeiidException {
FakeDataManager dataMgr = new FakeDataManager();
dataMgr.registerTuples(metadata, "pm1.g1", new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "First", Integer.valueOf(5), new Boolean(true), new Double(1.003) }), // $NON-NLS-1$
Arrays.asList(new Object[] { "Second", Integer.valueOf(15), new Boolean(true), new Double(2.003) }), // $NON-NLS-1$
Arrays.asList(new Object[] { "Third", Integer.valueOf(51), new Boolean(true), new Double(3.003) }) });
dataMgr.registerTuples(metadata, "pm1.g2", new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "First", Integer.valueOf(5), new Boolean(true), new Double(1.003) }), // $NON-NLS-1$
Arrays.asList(new Object[] { "Second", Integer.valueOf(15), new Boolean(true), new Double(2.003) }), // $NON-NLS-1$
Arrays.asList(new Object[] { "Third", Integer.valueOf(51), new Boolean(true), new Double(3.003) }) });
return dataMgr;
}
use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.
the class TestProcedureProcessor method testDynamicCommandWithSingleSelect.
@Test
public void testDynamicCommandWithSingleSelect() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.example1();
addProc(metadata, // $NON-NLS-1$ //$NON-NLS-2$
"CREATE VIRTUAL PROCEDURE BEGIN\n" + "execute string 'SELECT 26'; END");
// $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[] { "26" }) };
helpTestProcess(plan, expected, dataMgr, metadata);
}
use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.
the class TestProcedureProcessor method testSubqueryArguments.
@Test
public void testSubqueryArguments() {
// $NON-NLS-1$
String sql = "select * from (EXEC pm1.sq3b((select min(e1) from pm1.g1), (select max(e2) from pm1.g1))) as x";
ProcessorPlan plan = helpGetPlan(sql, RealMetadataFactory.example1Cached());
FakeDataManager fdm = new FakeDataManager();
fdm.setBlockOnce();
sampleData1(fdm);
helpProcess(plan, fdm, new List[] { Arrays.asList("a", 0), Arrays.asList("a", 3), Arrays.asList("a", 0), Arrays.asList("a", 3) });
}
Aggregations