use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestProcedureProcessor method testUDFCorrelated.
@Test
public void testUDFCorrelated() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.fromDDL("CREATE VIRTUAL FUNCTION f1(x integer) RETURNS string as return (select e1 from g1 where e2 = x/2);; create foreign table g1 (e1 string, e2 integer);", "x", "y");
ProcessorPlan plan = helpGetPlan("select * from g1, table ( select f1 (g1.e2)) t;", metadata);
CommandContext cc = TestProcessor.createCommandContext();
cc.setMetadata(metadata);
HardcodedDataManager hdm = new HardcodedDataManager();
hdm.addData("SELECT y.g1.e1, y.g1.e2 FROM y.g1", Arrays.asList("a", 1), Arrays.asList("b", 2));
hdm.addData("SELECT y.g1.e2, y.g1.e1 FROM y.g1", Arrays.asList(1, "a"), Arrays.asList(2, "b"));
hdm.setBlockOnce(true);
helpProcess(plan, cc, hdm, new List[] { Arrays.asList("a", 1, null), Arrays.asList("b", 2, "a") });
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestProcedureProcessor method testVirtualProcedure16.
@Test
public void testVirtualProcedure16() throws Exception {
// $NON-NLS-1$
String userUpdateStr = "EXEC pm1.vsp20()";
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
// Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
// Create expected results
List[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "First" }), // $NON-NLS-1$
Arrays.asList(new Object[] { "Second" }), // $NON-NLS-1$
Arrays.asList(new Object[] { "Third" }), // $NON-NLS-1$
Arrays.asList(new Object[] { "Fourth" }) };
// $NON-NLS-1$
CommandContext context = new CommandContext("pID", null, null, null, 1);
context.setMetadata(metadata);
// ensure that the final temp result set will not be deleted prematurely
context.setProcessorBatchSize(1);
TestProcessor.helpProcess(plan, context, dataMgr, expected);
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestProcedureProcessor method helpTestProcess.
public static void helpTestProcess(ProcessorPlan procPlan, List[] expectedResults, ProcessorDataManager dataMgr, QueryMetadataInterface metadata) throws Exception {
// $NON-NLS-1$
CommandContext context = new CommandContext("pID", null, null, null, 1);
if (!(metadata instanceof TempMetadataAdapter)) {
metadata = new TempMetadataAdapter(metadata, new TempMetadataStore());
}
context.setMetadata(metadata);
TestProcessor.helpProcess(procPlan, context, dataMgr, expectedResults);
assertNotNull("Expected processing to fail", expectedResults);
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestProcedureProcessor method testOmitDefault.
@Test
public void testOmitDefault() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.fromDDL("CREATE foreign procedure f1(x string not null options (\"teiid_rel:default_handling\" 'omit')) RETURNS string;", "x", "y");
ProcessorPlan plan = helpGetPlan("exec f1()", metadata);
CommandContext cc = TestProcessor.createCommandContext();
cc.setMetadata(metadata);
HardcodedDataManager hdm = new HardcodedDataManager(metadata);
hdm.addData("EXEC f1()", Arrays.asList("a"));
helpProcess(plan, cc, hdm, new List[] { Arrays.asList("a") });
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestWithClauseProcessing method testNestedInlining.
@Test
public void testNestedInlining() throws Exception {
CommandContext cc = TestProcessor.createCommandContext();
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
TransformationMetadata metadata = RealMetadataFactory.fromDDL("CREATE foreign TABLE test_a(a integer, b integer)", "x", "y");
String sql = "with CTE1 as (WITH alias as (SELECT a from test_a), alias2 as (select t2.a as a1, t1.a from alias t1 join (SELECT 1 as a) t2 on t1.a=t2.a), CTE31 as (select t2.a as a1 from alias2 t2) SELECT CTE31.a1 FROM alias2 join CTE31 on CTE31.a1=alias2.a ), CTE2 as ( WITH alias as (SELECT 1 as a), alias2 as (select t2.a a1, t1.a from alias t1 join (SELECT 1 as a) t2 on t1.a=t2.a), CTE32 as (select t2.a from alias2 t2) SELECT CTE32.a FROM alias2 join CTE32 on CTE32.a=alias2.a ) select * from CTE1 as T1 join CTE2 as T2 on T1.a1=T2.a";
ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(bsc), cc);
HardcodedDataManager hdm = new HardcodedDataManager(metadata);
hdm.addData("WITH alias2 (a1, a) AS (SELECT NULL, g_0.a FROM test_a AS g_0 WHERE g_0.a = 1) SELECT g_1.a AS c_0 FROM alias2 AS g_0, alias2 AS g_1 WHERE g_1.a = g_0.a AND g_1.a = 1 ORDER BY c_0", Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1));
TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList(1, 1), Arrays.asList(1, 1), Arrays.asList(1, 1), Arrays.asList(1, 1) });
}
Aggregations