private FakeCapabilitiesFinder getWhereAllCapabilities() { FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); caps.setCapabilitySupport(Capability.REQUIRES_CRITERIA, true); capFinder.addCapabilities("pm1", TestOptimizer.getTypicalCapabilities()); //$NON-NLS-1$ capFinder.addCapabilities("pm6", caps); //$NON-NLS-1$ return capFinder; }
@Test public void testIsNull3() throws Exception { TransformationMetadata metadata = RealMetadataFactory.example1Cached(); Object modelID = metadata.getMetadataStore().getSchema("PM1"); FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); helpTestVisitor("pm1.g1.e1 IS NULL", modelID, metadata, capFinder, true, false); }
@Test public void testCompareCriteriaNoCaps() throws Exception { TransformationMetadata metadata = RealMetadataFactory.example1Cached(); Object modelID = metadata.getMetadataStore().getSchema("PM1"); FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); helpTestVisitor("pm1.g1.e1 = 'x'", modelID, metadata, capFinder, true, false); }
private FakeCapabilitiesFinder getFinder(Capability property, boolean supported) { // Set up capabilities FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder(); BasicSourceCapabilities sourceCaps = new BasicSourceCapabilities(); sourceCaps.setCapabilitySupport(property, supported); finder.addCapabilities("pm1", sourceCaps); //$NON-NLS-1$ return finder; }
@Test public void testMatchCriteriaNoCaps() throws Exception { TransformationMetadata metadata = RealMetadataFactory.example1Cached(); Object modelID = metadata.getMetadataStore().getSchema("PM1"); FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); helpTestVisitor("pm1.g1.e1 LIKE 'x'", modelID, metadata, capFinder, true, false); //$NON-NLS-1$ }
@Test public void testOrderByUnrelatedInSubquery() throws Exception { FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = getAggregateCapabilities(); capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$ String sql = "SELECT g1.e1 from pm1.g1 LEFT OUTER JOIN (SELECT g2.e1, AVG(g2.e2) from pm1.g2 GROUP BY g2.e1 ORDER BY AVG(g2.e2) LIMIT 2) j_Sub on g1.e1 = j_Sub.e1"; TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), //$NON-NLS-1$ new String[]{"SELECT g_0.e1 FROM pm1.g1 AS g_0 LEFT OUTER JOIN (SELECT g_1.e1 AS c_0 FROM pm1.g2 AS g_1 GROUP BY g_1.e1 ORDER BY AVG(g_1.e2) LIMIT 2) AS v_0 ON g_0.e1 = v_0.c_0"}, capFinder, ComparisonMode.EXACT_COMMAND_STRING); }
@Test public void testJoinOr() throws Exception { FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = getAggregateCapabilities(); capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$ TestOptimizer.helpPlan("SELECT A.e1 FROM pm1.g1 A, (select e2 from pm2.g1) B WHERE A.e2 = 1 OR B.e2 IS NULL GROUP BY A.e1", RealMetadataFactory.example1Cached(), null, capFinder, //$NON-NLS-1$ new String[]{"SELECT g_0.e2 FROM pm2.g1 AS g_0", "SELECT g_0.e2, g_0.e1 FROM pm1.g1 AS g_0 GROUP BY g_0.e2, g_0.e1"}, ComparisonMode.EXACT_COMMAND_STRING); }
@Test public void testPlannerNoCommandsBatched() throws Exception { String[] sql = {"INSERT INTO pm1.g1 (e1, e2, e3, e4) values ('string1', 1, {b'true'}, 1.0)", //$NON-NLS-1$ "INSERT INTO pm1.g2 (e1, e2, e3, e4) values ('string1', 1, {b'true'}, 1.0)", //$NON-NLS-1$ "DELETE FROM pm1.g1 WHERE e2 > 5000", //$NON-NLS-1$ "UPDATE pm1.g1 set e2 = -1 WHERE e2 = 4999" //$NON-NLS-1$ }; FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder(); finder.addCapabilities("pm1", new FakeCapabilities(false)); //$NON-NLS-1$ boolean[] expectedBatching = {false, false, false, false}; helpTestPlanner(sql, expectedBatching, finder); }
@Test public void testDDLMetadataNameConflict() throws Exception { String ddl = "CREATE foreign FUNCTION \"convert\"(msg integer, type varchar) RETURNS varchar; " + "CREATE foreign table X (Y integer);"; QueryMetadataInterface metadata = RealMetadataFactory.fromDDL(ddl, "x", "phy"); FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); capFinder.addCapabilities("phy", caps); //$NON-NLS-1$ helpPlan("select phy.convert(y, 'z') from x", metadata, null, capFinder, new String[] {"SELECT phy.convert(g_0.Y, 'z') FROM phy.X AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ }
@Test public void testCantPushSort() throws Exception { String sql = "select e3, e2 from test.group order by e3, e2"; //$NON-NLS-1$ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); capFinder.addCapabilities("test", TestOptimizer.getTypicalCapabilities()); //$NON-NLS-1$ TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata(), new String[] {"SELECT g_0.e3, g_0.e2 FROM test.\"group\" AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ }
@Test public void testCantPushDup() throws Exception { String sql = "select distinct e3, e2 from test.group"; //$NON-NLS-1$ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); capFinder.addCapabilities("test", TestOptimizer.getTypicalCapabilities()); //$NON-NLS-1$ TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata(), new String[] {"SELECT g_0.e3, g_0.e2 FROM test.\"group\" AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ }
@Test public void testRaiseNullWithUnionOrderBy() { FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true); QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached(); capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$ capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$ String sql = "select intkey from bqt1.smalla where 1 = 0 union all select intnum from bqt2.smalla order by intkey"; //$NON-NLS-1$ ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, null, capFinder, new String[]{"SELECT intnum AS intkey FROM bqt2.smalla ORDER BY intkey"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); }
@Test public void testSinglePredicatePushedWithUnionAndGrouping() throws Exception { FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = getAggregateCapabilities(); capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$ String sql = "select * from (select intnum as a from bqt1.smalla group by intnum union all select 1 as a) as x where a = 1;"; TestOptimizer.helpPlan(sql, RealMetadataFactory.exampleBQTCached(), //$NON-NLS-1$ new String[]{"SELECT g_0.IntNum FROM BQT1.SmallA AS g_0 WHERE g_0.IntNum = 1 GROUP BY g_0.IntNum"}, capFinder, ComparisonMode.EXACT_COMMAND_STRING); }
@Test public void testCantPushGroupBy() throws Exception { String sql = "select e3, e2 from test.group group by e3, e2"; //$NON-NLS-1$ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, true); capFinder.addCapabilities("test", caps); //$NON-NLS-1$ TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata(), new String[] {"SELECT g_0.e3, g_0.e2 FROM test.\"group\" AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ }
public void helpTestSupportsAggregateFunction(SourceCapabilities caps, AggregateSymbol aggregate, boolean expectedValue) throws QueryMetadataException, TeiidComponentException { // Set up metadata TransformationMetadata metadata = RealMetadataFactory.example1Cached(); Schema modelID = metadata.getMetadataStore().getSchema("PM1"); // Set up capabilities FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder(); finder.addCapabilities("pm1", caps); //$NON-NLS-1$ // Test capabilities util boolean actual = CapabilitiesUtil.supportsAggregateFunction(modelID, aggregate, metadata, finder); assertEquals("Got wrong answer for supports", expectedValue, actual); //$NON-NLS-1$ }
/** * ensure the agg is not decomposed as we do not have rollup compensation */ @Test public void testUnionGroupingWithRollup() throws Exception { FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = getAggregateCapabilities(); caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true); capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ ProcessorPlan plan = TestOptimizer.helpPlan("select count(*) from (select e1, e2, 1 as part from pm1.g1 union all select e1, e2, 2 as part from pm1.g2) z group by rollup(e1)", RealMetadataFactory.example1Cached(), null, capFinder, //$NON-NLS-1$ new String[]{"SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT g_0.e1 FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ }
@Test public void testCantPushSetOp() throws Exception { String sql = "select e3, e2 from test.group union select e0, e1 from test.group2"; //$NON-NLS-1$ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = new BasicSourceCapabilities(); caps.setCapabilitySupport(Capability.QUERY_UNION, true); capFinder.addCapabilities("test", caps); //$NON-NLS-1$ TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata(), new String[] {"SELECT test.\"group\".e3, test.\"group\".e2 FROM test.\"group\"", "SELECT test.group2.e0, test.group2.e1 FROM test.group2"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testSortAliasWithSameName() throws Exception { String sql = "select e1 from (select distinct pm1.g1.e1 as e1 from pm1.g1) x order by e1"; //$NON-NLS-1$ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = new BasicSourceCapabilities(); caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true); capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ RelationalPlan plan = (RelationalPlan)TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ SortNode node = (SortNode)plan.getRootNode(); assertTrue("Alias was not accounted for in sort node", node.getElements().get(0).equals(node.getSortElements().get(0).getSymbol())); //$NON-NLS-1$ }
@Test public void testSimpleMergeUnderUnionWithJoin() { FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = new BasicSourceCapabilities(); caps.setCapabilitySupport(Capability.QUERY_UNION, true); caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true); capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ TestOptimizer.helpPlan("select * from (SELECT x.x, x.e2 FROM (select '1' as x, pm1.g1.e2 from pm1.g1, pm1.g2 where pm1.g1.e1 = pm1.g2.e1 group by pm1.g1.e2, pm1.g1.e3 || '1') x union all select e1, 1 from pm1.g2) as y where x = '1'", //$NON-NLS-1$ RealMetadataFactory.example1Cached(), null, capFinder, new String[] { "SELECT pm1.g2.e1 FROM pm1.g2", "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3 FROM pm1.g1"}, TestOptimizer.SHOULD_SUCCEED); }
@Test public void testNestedTable() throws Exception { FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true); capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$ ProcessorPlan plan = helpPlan("select pm2.g1.e1, x.e1 from pm2.g1, table(select * from pm2.g2 where pm2.g1.e1=pm2.g2.e1) x where pm2.g1.e2 IN (1, 2)", example1(), //$NON-NLS-1$ new String[] { "SELECT g_0.e1 FROM pm2.g2 AS g_0 WHERE g_0.e1 = pm2.g1.e1", "SELECT g_0.e1 FROM pm2.g1 AS g_0 WHERE g_0.e2 IN (1, 2)" }, capFinder, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ checkNodeTypes(plan, new int[] {1}, new Class[] {NestedTableJoinStrategy.class}); }