Search in sources :

Example 66 with CommandContext

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") });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 67 with CommandContext

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);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) FakeDataManager(org.teiid.query.processor.FakeDataManager) 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 68 with CommandContext

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);
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) CommandContext(org.teiid.query.util.CommandContext) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore)

Example 69 with CommandContext

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") });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 70 with CommandContext

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) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Aggregations

CommandContext (org.teiid.query.util.CommandContext)257 Test (org.junit.Test)179 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)104 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)95 List (java.util.List)90 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)64 ArrayList (java.util.ArrayList)44 Command (org.teiid.query.sql.lang.Command)38 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)37 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)33 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)26 Options (org.teiid.query.util.Options)20 BufferManager (org.teiid.common.buffer.BufferManager)19 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)19 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)18 TeiidProcessingException (org.teiid.core.TeiidProcessingException)14 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)13 BlockedException (org.teiid.common.buffer.BlockedException)11 TeiidComponentException (org.teiid.core.TeiidComponentException)11 Table (org.teiid.metadata.Table)11