Search in sources :

Example 61 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestWindowFunctions method testLag.

@Test
public void testLag() throws Exception {
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    String sql = "SELECT e1, LAG(e1, 2, 'd') over (partition by e3 order by e2) from pm1.g1";
    ProcessorPlan plan = TestOptimizer.getPlan(helpGetCommand(sql, RealMetadataFactory.example1Cached(), null), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), null, true, // $NON-NLS-1$
    new CommandContext());
    HardcodedDataManager dataMgr = new HardcodedDataManager();
    dataMgr.addData("SELECT g_0.e1, g_0.e3, g_0.e2 FROM pm1.g1 AS g_0", Arrays.asList("a", true, 1), Arrays.asList("b", true, 2), Arrays.asList("c", true, 0), Arrays.asList("a", false, 1), Arrays.asList("b", false, 2), Arrays.asList("c", false, 0));
    List<?>[] expected = new List<?>[] { Arrays.asList("a", "d"), Arrays.asList("b", "d"), Arrays.asList("c", "a"), Arrays.asList("a", "d"), Arrays.asList("b", "d"), Arrays.asList("c", "a") };
    helpProcess(plan, dataMgr, expected);
    bsc.setCapabilitySupport(Capability.ELEMENTARY_OLAP, true);
    bsc.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
    TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), new String[] { "SELECT g_0.e1, LAG(g_0.e1, 2, 'd') OVER (PARTITION BY g_0.e3 ORDER BY g_0.e2) FROM pm1.g1 AS g_0" }, new DefaultCapabilitiesFinder(bsc), ComparisonMode.EXACT_COMMAND_STRING);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 62 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestWindowFunctions method testFirstLastValue.

@Test
public void testFirstLastValue() throws Exception {
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    String sql = "SELECT FIRST_VALUE(e1) over (order by e2), LAST_VALUE(e2) over (order by e1) from pm1.g1";
    ProcessorPlan plan = TestOptimizer.getPlan(helpGetCommand(sql, RealMetadataFactory.example1Cached(), null), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), null, true, // $NON-NLS-1$
    new CommandContext());
    HardcodedDataManager dataMgr = new HardcodedDataManager();
    dataMgr.addData("SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0", Arrays.asList("a", 1), Arrays.asList("b", 2));
    List<?>[] expected = new List<?>[] { Arrays.asList("a", 1), Arrays.asList("a", 2) };
    helpProcess(plan, dataMgr, expected);
    bsc.setCapabilitySupport(Capability.ELEMENTARY_OLAP, true);
    bsc.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
    TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), new String[] { "SELECT FIRST_VALUE(g_0.e1) OVER (ORDER BY g_0.e2), LAST_VALUE(g_0.e2) OVER (ORDER BY g_0.e1) FROM pm1.g1 AS g_0" }, new DefaultCapabilitiesFinder(bsc), ComparisonMode.EXACT_COMMAND_STRING);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 63 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestWithClauseProcessing method testWithAggregation.

/**
 * Expected to fail as we shouldn't allow a reference to p.e2 in the windowed sum
 * @throws Exception
 */
@Test(expected = QueryValidatorException.class)
public void testWithAggregation() throws Exception {
    String sql = "WITH x as (SELECT e1 FROM pm1.g1) SELECT p.e1, SUM(p.e2) OVER (partition by p.e1) as y FROM pm1.g1 p JOIN x ON x.e1 = p.e1 GROUP BY p.e1";
    CommandContext cc = TestProcessor.createCommandContext();
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 64 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestWithClauseProcessing method testNestedWith1.

@Test
public void testNestedWith1() throws Exception {
    CommandContext cc = TestProcessor.createCommandContext();
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
    String sql = "WITH cte1 as (SELECT 1 as a), cte3 as  /*+ no_inline */ (with cte3_1 as /*+ no_inline */ (select cte1.a from cte1 join pm1.g1 t1 on cte1.a=t1.e2) select * from cte3_1) SELECT * FROM cte3";
    ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
    HardcodedDataManager hdm = new HardcodedDataManager(RealMetadataFactory.example1Cached());
    hdm.addData("WITH cte3_1 (a) AS (SELECT 1 FROM g1 AS g_0 WHERE g_0.e2 = 1), cte3 (a) AS (SELECT g_0.a FROM cte3_1 AS g_0) SELECT g_0.a FROM cte3 AS g_0", Arrays.asList(1));
    TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList(1) });
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 65 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestProcedureProcessor method testUDF.

@Test
public void testUDF() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("CREATE VIRTUAL FUNCTION f1(VARIADIC e1 integer) RETURNS integer as return array_length(e1);", "x", "y");
    ProcessorPlan plan = helpGetPlan("select f1(1, 2, 1)", metadata);
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setMetadata(metadata);
    helpProcess(plan, cc, new HardcodedDataManager(), new List[] { Arrays.asList(3) });
}
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)

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