use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestAggregateProcessing method testSelectAllWithGrouping.
@Test
public void testSelectAllWithGrouping() {
// $NON-NLS-1$
Command command = helpParse("select * from (select pm1.g1.e1 x, pm2.g2.e1 y from pm1.g1, pm2.g2) z group by x, y");
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
// $NON-NLS-1$
capFinder.addCapabilities("pm1", TestAggregatePushdown.getAggregateCapabilities());
// $NON-NLS-1$
capFinder.addCapabilities("pm2", TestOptimizer.getTypicalCapabilities());
HardcodedDataManager dataManager = new HardcodedDataManager();
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"SELECT g_0.e1 FROM pm1.g1 AS g_0 GROUP BY g_0.e1", new List[] { // $NON-NLS-1$
Arrays.asList("a") });
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"SELECT g_0.e1 FROM pm2.g2 AS g_0", new List[] { // $NON-NLS-1$
Arrays.asList("b") });
ProcessorPlan plan = helpGetPlan(command, RealMetadataFactory.example1Cached(), capFinder);
List[] expected = new List[] { Arrays.asList("a", "b") };
helpProcess(plan, dataManager, expected);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestAggregateProcessing method testUserDefined.
@Test
public void testUserDefined() throws Exception {
MetadataStore ms = RealMetadataFactory.example1Store();
Schema s = ms.getSchemas().get("PM1");
AggregateAttributes aa = addAgg(s, "myagg", SumAll.class, DataTypeManager.DefaultDataTypes.INTEGER).getAggregateAttributes();
addAgg(s, "myagg2", LongSumAll.class, DataTypeManager.DefaultDataTypes.LONG);
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(ms, "test");
Command c = TestResolver.helpResolve("select myagg2(distinct e2) from pm1.g1", metadata);
assertEquals(DataTypeManager.DefaultDataClasses.LONG, c.getProjectedSymbols().get(0).getType());
// must be in agg form
TestValidator.helpValidate("SELECT myagg(e2) from pm1.g1", new String[] {}, metadata);
// run validations over default AggregateAttributes
TestValidator.helpValidate("SELECT myagg(distinct e2) from pm1.g1", new String[] { "myagg(DISTINCT e2)" }, metadata);
TestValidator.helpValidate("SELECT myagg(e2 order by e1) from pm1.g1", new String[] { "myagg(ALL e2 ORDER BY e1)" }, metadata);
TestValidator.helpValidate("SELECT myagg(ALL e2, e2) over () from pm1.g1", new String[] {}, metadata);
aa.setAllowsDistinct(true);
aa.setAllowsOrderBy(true);
TestValidator.helpValidate("SELECT myagg(distinct e2) from pm1.g1", new String[] {}, metadata);
TestValidator.helpValidate("SELECT myagg(e2 order by e1) from pm1.g1", new String[] {}, metadata);
aa.setAnalytic(true);
TestValidator.helpValidate("SELECT myagg(distinct e2) from pm1.g1", new String[] { "myagg(DISTINCT e2)" }, metadata);
TestValidator.helpValidate("SELECT myagg(e2, e2) over () from pm1.g1", new String[] {}, metadata);
aa.setAnalytic(false);
// Create expected results
List[] expected = new List[] { Arrays.asList(6, 6), Arrays.asList(8, 8) };
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
sampleData1(dataManager);
ProcessorPlan plan = helpGetPlan("select myagg(all e2, e2 order by e1), myagg(e2, e2) from pm1.g1 group by e3", metadata);
helpProcess(plan, dataManager, expected);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestAggregateProcessing method testEmptyCountOverJoin.
@Test
public void testEmptyCountOverJoin() {
// $NON-NLS-1$
Command command = helpParse("select count(pm1.g1.e2) from pm1.g1, pm1.g2 where pm1.g1.e1 = pm1.g2.e1");
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities bsc = TestAggregatePushdown.getAggregateCapabilities();
bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, false);
bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, false);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", bsc);
HardcodedDataManager dataManager = new HardcodedDataManager();
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"SELECT g_0.e1 AS c_0, COUNT(g_0.e2) AS c_1 FROM pm1.g1 AS g_0 GROUP BY g_0.e1 ORDER BY c_0", new List[] {// $NON-NLS-1$
});
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"SELECT g_0.e1 AS c_0 FROM pm1.g2 AS g_0 ORDER BY c_0", new List[] {// $NON-NLS-1$
});
ProcessorPlan plan = helpGetPlan(command, RealMetadataFactory.example1Cached(), capFinder);
List[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(0) };
helpProcess(plan, dataManager, expected);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestAggregateProcessing method testAggregatePushdown.
@Test
public void testAggregatePushdown() {
// $NON-NLS-1$
Command command = helpParse("select e1, count(e2), max(e2) from (select e1, e2, e3 from pm1.g1 union all select e1, e2, e3 from pm1.g2 union all select e1, e2, e3 from pm2.g1) z group by e1");
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
// $NON-NLS-1$
capFinder.addCapabilities("pm1", TestAggregatePushdown.getAggregateCapabilities());
// $NON-NLS-1$
capFinder.addCapabilities("pm2", TestOptimizer.getTypicalCapabilities());
HardcodedDataManager dataManager = new HardcodedDataManager();
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"SELECT g_0.e1, COUNT(g_0.e2), MAX(g_0.e2) FROM pm1.g1 AS g_0 GROUP BY g_0.e1", new List[] { // $NON-NLS-1$
Arrays.asList("a", Integer.valueOf(2), Integer.valueOf(1)) });
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"SELECT g_0.e1, COUNT(g_0.e2), MAX(g_0.e2) FROM pm1.g2 AS g_0 GROUP BY g_0.e1", new List[] { // $NON-NLS-1$
Arrays.asList("a", Integer.valueOf(3), Integer.valueOf(2)) });
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"SELECT g_0.e1, g_0.e2 FROM pm2.g1 AS g_0", new List[] { // $NON-NLS-1$
Arrays.asList("a", Integer.valueOf(3)), // $NON-NLS-1$
Arrays.asList("xyz", Integer.valueOf(4)), Arrays.asList(null, Integer.valueOf(5)) });
ProcessorPlan plan = helpGetPlan(command, RealMetadataFactory.example1Cached(), capFinder);
List[] expected = new List[] { Arrays.asList(null, Integer.valueOf(1), Integer.valueOf(5)), // $NON-NLS-1$
Arrays.asList("a", Integer.valueOf(6), Integer.valueOf(3)), // $NON-NLS-1$
Arrays.asList("xyz", Integer.valueOf(1), Integer.valueOf(4)) };
helpProcess(plan, dataManager, expected);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestAggregateProcessing method testUnionAggregatePushdown.
@Test
public void testUnionAggregatePushdown() {
// $NON-NLS-1$
Command command = helpParse("select count(*), max(e3) from (select e1, e2, e3 from pm1.g1 union all (select convert(e2, string) as a, e2, e3 from pm2.g2 order by a limit 10)) x group by e1, e2");
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
// $NON-NLS-1$
capFinder.addCapabilities("pm1", TestAggregatePushdown.getAggregateCapabilities());
BasicSourceCapabilities bac = TestAggregatePushdown.getAggregateCapabilities();
// $NON-NLS-1$
bac.setFunctionSupport("convert", true);
// $NON-NLS-1$
capFinder.addCapabilities("pm2", bac);
HardcodedDataManager dataManager = new HardcodedDataManager();
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"SELECT g_0.e1, g_0.e2, COUNT(*), MAX(g_0.e3) FROM pm1.g1 AS g_0 GROUP BY g_0.e1, g_0.e2", new List[] { // $NON-NLS-1$
Arrays.asList("2", Integer.valueOf(2), Integer.valueOf(2), null), // $NON-NLS-1$
Arrays.asList("1", Integer.valueOf(1), Integer.valueOf(3), Boolean.TRUE) });
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"SELECT v_0.c_0, v_0.c_1, COUNT(*), MAX(v_0.c_2) FROM (SELECT convert(g_0.e2, string) AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2 FROM pm2.g2 AS g_0 ORDER BY c_0 LIMIT 10) AS v_0 GROUP BY v_0.c_0, v_0.c_1", new List[] { // $NON-NLS-1$
Arrays.asList("1", Integer.valueOf(1), Integer.valueOf(4), Boolean.FALSE) });
ProcessorPlan plan = helpGetPlan(command, RealMetadataFactory.example1Cached(), capFinder);
List[] expected = new List[] { Arrays.asList(Integer.valueOf(7), Boolean.TRUE), Arrays.asList(Integer.valueOf(2), null) };
helpProcess(plan, dataManager, expected);
}
Aggregations