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