@Test public void testMustPushdownOverMultipleSourcesWithViewDupRemoval() throws Exception { QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata( RealMetadataFactory.example1Cached().getMetadataStore(), "example1", new FunctionTree("foo", new FakeFunctionMetadataSource())); FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); caps.setFunctionSupport("misc.namespace.func", true); capFinder.addCapabilities("pm1", caps); // $NON-NLS-1$ capFinder.addCapabilities("pm2", caps); // $NON-NLS-1$ String sql = "select func(x.e1) from (select distinct x.* from pm1.g1 as x, pm2.g1 as y where x.e2 = y.e2 order by e1 limit 10) as x"; //$NON-NLS-1$ helpPlan( sql, metadata, null, capFinder, new String[] {}, ComparisonMode.FAILED_PLANNING); // $NON-NLS-1$ }
@Test public void testWindowFunctionPushdown2() throws Exception { BasicSourceCapabilities caps = getTypicalCapabilities(); caps.setCapabilitySupport(Capability.ELEMENTARY_OLAP, true); caps.setCapabilitySupport(Capability.WINDOW_FUNCTION_ORDER_BY_AGGREGATES, true); caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true); caps.setSourceProperty(Capability.QUERY_ORDERBY_DEFAULT_NULL_ORDER, NullOrder.UNKNOWN); ProcessorPlan plan = TestOptimizer.helpPlan( "select max(e1) over (order by e1 nulls first) as y from pm1.g1", //$NON-NLS-1$ RealMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(caps), new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ checkNodeTypes( plan, new int[] {1, 1, 1}, new Class<?>[] {AccessNode.class, WindowFunctionProjectNode.class, ProjectNode.class}); caps.setCapabilitySupport(Capability.QUERY_ORDERBY_NULL_ORDERING, true); plan = TestOptimizer.helpPlan( "select max(e1) over (order by e1 nulls first) as y from pm1.g1", //$NON-NLS-1$ RealMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(caps), new String[] { "SELECT MAX(g_0.e1) OVER (ORDER BY g_0.e1 NULLS FIRST) FROM pm1.g1 AS g_0" }, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ checkNodeTypes(plan, FULL_PUSHDOWN); }
@Test public void testWindowFunctionPushdown3() throws Exception { BasicSourceCapabilities caps = getTypicalCapabilities(); caps.setCapabilitySupport(Capability.ELEMENTARY_OLAP, true); caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true); caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_DISTINCT, true); ProcessorPlan plan = TestOptimizer.helpPlan( "select count(distinct e1) over (partition by e2) as y from pm1.g1", //$NON-NLS-1$ RealMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(caps), new String[] {"SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ checkNodeTypes( plan, new int[] {1, 1, 1}, new Class<?>[] {AccessNode.class, WindowFunctionProjectNode.class, ProjectNode.class}); caps.setCapabilitySupport(Capability.WINDOW_FUNCTION_DISTINCT_AGGREGATES, true); plan = TestOptimizer.helpPlan( "select count(distinct e1) over (partition by e2) as y from pm1.g1", //$NON-NLS-1$ RealMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(caps), new String[] { "SELECT COUNT(DISTINCT g_0.e1) OVER (PARTITION BY g_0.e2) FROM pm1.g1 AS g_0" }, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ checkNodeTypes(plan, FULL_PUSHDOWN); }
@Test public void testIsolateReads() throws Exception { GlobalTableStoreImpl gtsi = new GlobalTableStoreImpl( BufferManagerFactory.getStandaloneBufferManager(), RealMetadataFactory.example1Cached().getVdbMetaData(), RealMetadataFactory.example1Cached()); tempStore = gtsi.getTempTableStore(); metadata = new TempMetadataAdapter(RealMetadataFactory.example1Cached(), tempStore.getMetadataStore()); execute( "create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); // $NON-NLS-1$ for (int i = 0; i < 300; i++) { execute( "insert into x (e2, e1) select e2, e1 from pm1.g1", new List[] {Arrays.asList(6)}); // $NON-NLS-1$ } setupTransaction(Connection.TRANSACTION_SERIALIZABLE); execute("select count(e1) from x", new List[] {Arrays.asList(1500)}); gtsi.updateMatViewRow("X", Arrays.asList(2), true); tc = null; // outside of the transaction we can see the row removed execute("select count(e1) from x", new List[] {Arrays.asList(1499)}); // back in the transaction we see the original state setupTransaction(Connection.TRANSACTION_SERIALIZABLE); execute("select count(e1) from x", new List[] {Arrays.asList(1500)}); synch.afterCompletion(Status.STATUS_COMMITTED); }
@Test public void testPartialProjection() throws TeiidComponentException, TeiidProcessingException { String sql = "SELECT user() AS a, " + " AVG(e2) OVER ( ) AS b," + " MAX(e2) OVER ( ) AS b" + " FROM pm1.g1"; HardcodedDataManager dataMgr = new HardcodedDataManager(); dataMgr.addData( "SELECT ROUND(convert((g_0.L_DISCOUNT - AVG(g_0.L_DISCOUNT) OVER ()), FLOAT), 0) FROM TPCR_Oracle_9i.LINEITEM AS g_0", Arrays.asList(2.0f), Arrays.asList(2.0f)); BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities(); bsc.setCapabilitySupport(Capability.ELEMENTARY_OLAP, true); bsc.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true); bsc.setCapabilitySupport(Capability.WINDOW_FUNCTION_ORDER_BY_AGGREGATES, true); ProcessorPlan plan = TestOptimizer.helpPlan( sql, RealMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(bsc), new String[] {"SELECT AVG(g_0.e2) OVER (), g_0.e2 FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ checkNodeTypes( plan, new int[] {1, 1, 1}, new Class<?>[] {AccessNode.class, WindowFunctionProjectNode.class, ProjectNode.class}); List<?>[] expected = new List<?>[] { Arrays.asList(null, BigDecimal.valueOf(1.5), 2), Arrays.asList(null, BigDecimal.valueOf(1.5), 2) }; dataMgr.addData( "SELECT AVG(g_0.e2) OVER (), g_0.e2 FROM pm1.g1 AS g_0", //$NON-NLS-1$ Arrays.asList(1.5, 2), Arrays.asList(1.5, 1)); helpProcess(plan, dataMgr, expected); // should completely eliminate the window function node plan = TestOptimizer.helpPlan( "SELECT uuid() AS a, AVG(e2) OVER ( ) AS b FROM pm1.g1", RealMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(bsc), new String[] {"SELECT AVG(g_0.e2) OVER () FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ checkNodeTypes(plan, new int[] {1, 1}, new Class<?>[] {AccessNode.class, ProjectNode.class}); }
@Test public void testStripAliases1() throws Exception { String sql = "select intkey as a, stringkey as b from BQT1.SmallA ORDER BY a, b"; // $NON-NLS-1$ String expected = "SELECT BQT1.SmallA.IntKey, BQT1.SmallA.StringKey FROM BQT1.SmallA ORDER BY BQT1.SmallA.IntKey, BQT1.SmallA.StringKey"; //$NON-NLS-1$ Command command = helpTest(sql, expected, false, true, RealMetadataFactory.exampleBQTCached()); LanguageBridgeFactory lbf = new LanguageBridgeFactory(RealMetadataFactory.exampleBQTCached()); org.teiid.language.Command c = lbf.translate(command); assertEquals( "SELECT SmallA.IntKey, SmallA.StringKey FROM SmallA ORDER BY SmallA.IntKey, SmallA.StringKey", c.toString()); }
@Test public void testInlineViewOrderBy() throws Exception { String sql = "select intnum from (select intnum from bqt1.smallb) b order by b.intnum"; //$NON-NLS-1$ String expected = "SELECT v_0.c_0 FROM (SELECT g_0.IntNum AS c_0 FROM BQT1.SmallB AS g_0) AS v_0 ORDER BY c_0"; //$NON-NLS-1$ Command command = helpTest(sql, expected, true, false, RealMetadataFactory.exampleBQTCached()); LanguageBridgeFactory lbf = new LanguageBridgeFactory(RealMetadataFactory.exampleBQTCached()); org.teiid.language.Command c = lbf.translate(command); assertEquals( "SELECT v_0.c_0 FROM (SELECT g_0.IntNum AS c_0 FROM SmallB AS g_0) AS v_0 ORDER BY v_0.c_0", c.toString()); }
@Test public void testWindowFunctionPushdown1() throws Exception { BasicSourceCapabilities caps = getTypicalCapabilities(); caps.setCapabilitySupport(Capability.ELEMENTARY_OLAP, true); caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true); ProcessorPlan plan = TestOptimizer.helpPlan( "select max(e1) over (order by e1) as y from pm1.g1", //$NON-NLS-1$ RealMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(caps), new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ checkNodeTypes( plan, new int[] { 1, // Access 0, // DependentAccess 0, // DependentSelect 0, // DependentProject 0, // DupRemove 0, // Grouping 0, // NestedLoopJoinStrategy 0, // MergeJoinStrategy 0, // Null 0, // PlanExecution 1, // Project 0, // Select 0, // Sort 0 // UnionAll }); }
@Test public void testOrderByConstant() throws TeiidComponentException, TeiidProcessingException { String sql = "select 1 as jiraissue_assignee, " + "row_number() over(order by subquerytable.jiraissue_id desc) as calculatedfield1 " + "from pm1.g1 as jiraissue left outer join " + "(select jiraissue_sub.e1 as jiraissue_assignee, jiraissue_sub.e1 as jiraissue_id from pm2.g2 jiraissue_sub " + "where (jiraissue_sub.e4 between null and 2)" + " ) subquerytable on jiraissue.e1 = subquerytable.jiraissue_assignee"; BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities(); bsc.setCapabilitySupport(Capability.ELEMENTARY_OLAP, true); bsc.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true); bsc.setCapabilitySupport(Capability.QUERY_ORDERBY_NULL_ORDERING, true); bsc.setCapabilitySupport(Capability.WINDOW_FUNCTION_ORDER_BY_AGGREGATES, true); ProcessorPlan plan = TestOptimizer.helpPlan( sql, RealMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(bsc), new String[] {"SELECT 1 FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ checkNodeTypes( plan, new int[] {1, 1, 1}, new Class<?>[] {AccessNode.class, WindowFunctionProjectNode.class, ProjectNode.class}); }
@Test public void testDDLMetadata1() throws Exception { String ddl = "CREATE foreign FUNCTION sourceFunc(msg varchar) RETURNS varchar options (nameinsource 'a.sourcefunc') " + "CREATE foreign FUNCTION b.sourceFunc(msg varchar) RETURNS varchar " + "CREATE foreign table X (Y varchar);"; QueryMetadataInterface metadata = RealMetadataFactory.fromDDL(ddl, "x", "phy"); FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); capFinder.addCapabilities("phy", caps); // $NON-NLS-1$ ProcessorPlan plan = helpPlan( "SELECT sourceFunc(g_0.Y), phy.b.sourceFunc(g_0.Y) FROM phy.X AS g_0", metadata, null, capFinder, new String[] {"SELECT sourceFunc(g_0.Y), phy.b.sourceFunc(g_0.Y) FROM phy.X AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ // ensure that the source query contains the function schemas HardcodedDataManager dm = new HardcodedDataManager(metadata); dm.addData("SELECT a.sourcefunc(g_0.Y), b.sourceFunc(g_0.Y) FROM X AS g_0", new List[0]); TestProcessor.helpProcess(plan, dm, new List[0]); }
private ArrayList helpExecute(String ddl, FileConnection connection, String query) throws Exception { ExcelExecutionFactory translator = new ExcelExecutionFactory(); translator.start(); TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "vdb", "excel"); TranslationUtility utility = new TranslationUtility(metadata); Command cmd = utility.parseCommand(query); ExecutionContext context = Mockito.mock(ExecutionContext.class); ResultSetExecution execution = translator.createResultSetExecution( (QueryExpression) cmd, context, utility.createRuntimeMetadata(), connection); execution.execute(); ArrayList results = new ArrayList(); while (true) { List<?> row = execution.next(); if (row == null) { break; } results.add(row); } return results; }
@Test public void testStripAliases() throws Exception { String sql = "select intkey as a, stringkey as b from BQT1.SmallA ORDER BY a, b"; // $NON-NLS-1$ String expected = "SELECT g_0.IntKey, g_0.StringKey FROM BQT1.SmallA AS g_0 ORDER BY g_0.IntKey, g_0.StringKey"; //$NON-NLS-1$ helpTest(sql, expected, true, true, RealMetadataFactory.exampleBQTCached()); }
@Test public void testNestedInlineViewOrderBy() throws Exception { String sql = "select x from (select intnum x from (select intnum from bqt1.smallb) b order by x) y order by x"; //$NON-NLS-1$ String expected = "SELECT v_1.c_0 FROM (SELECT v_0.c_0 FROM (SELECT g_0.IntNum AS c_0 FROM BQT1.SmallB AS g_0) AS v_0) AS v_1 ORDER BY c_0"; //$NON-NLS-1$ helpTest(sql, expected, true, false, RealMetadataFactory.exampleBQTCached()); }
@Test public void testUnrelatedOrderBy() throws Exception { String sql = "SELECT b.IntKey FROM BQT1.SmallA a, BQT1.SmallA b ORDER BY a.StringKey"; //$NON-NLS-1$ String expected = "SELECT g_1.IntKey AS c_0 FROM BQT1.SmallA AS g_0, BQT1.SmallA AS g_1 ORDER BY g_0.StringKey"; //$NON-NLS-1$ helpTest(sql, expected, true, false, RealMetadataFactory.exampleBQTCached()); }
@Test public void testDuplicateShortElementName() throws Exception { String sql = "select pm1.g1.e1, pm1.g2.e1 from pm1.g1, pm1.g2 order by pm1.g1.e1, pm1.g2.e1"; //$NON-NLS-1$ String expected = "SELECT g_0.e1 AS c_0, g_1.e1 AS c_1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 ORDER BY c_0, c_1"; //$NON-NLS-1$ helpTest(sql, expected, true, false, RealMetadataFactory.example1Cached()); }
@Test public void testUnrelatedOrderBy2() throws Exception { String sql = "SELECT b.IntKey FROM (select intkey, stringkey from BQT1.SmallA) a, (select intkey, stringkey from BQT1.SmallA) b ORDER BY a.StringKey || b.intKey"; //$NON-NLS-1$ String expected = "SELECT v_1.c_0 FROM (SELECT g_0.IntKey AS c_0, g_0.StringKey AS c_1 FROM BQT1.SmallA AS g_0) AS v_0, (SELECT g_1.IntKey AS c_0, g_1.StringKey AS c_1 FROM BQT1.SmallA AS g_1) AS v_1 ORDER BY (v_0.c_1 || v_1.c_0)"; //$NON-NLS-1$ helpTest(sql, expected, true, false, RealMetadataFactory.exampleBQTCached()); }
@Test public void testInlineViewWithOnClause() throws Exception { String sql = "select abcd.efg from (select intkey as efg from bqt1.smalla) abcd inner join (select intnum from bqt1.smallb) b on (b.intnum = abcd.efg)"; //$NON-NLS-1$ String expected = "SELECT v_0.c_0 FROM (SELECT g_0.IntKey AS c_0 FROM BQT1.SmallA AS g_0) AS v_0 INNER JOIN (SELECT g_1.IntNum AS c_0 FROM BQT1.SmallB AS g_1) AS v_1 ON v_1.c_0 = v_0.c_0"; //$NON-NLS-1$ helpTest(sql, expected, true, false, RealMetadataFactory.exampleBQTCached()); }
@Test public void testUnionAliasing() throws Exception { String sql = "SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntNum FROM BQT1.SmallA"; //$NON-NLS-1$ String expected = "SELECT BQT1.SmallA.IntKey AS c_0 FROM BQT1.SmallA UNION ALL SELECT BQT1.SmallA.IntNum AS c_0 FROM BQT1.SmallA"; //$NON-NLS-1$ helpTest(sql, expected, false, false, RealMetadataFactory.exampleBQTCached()); }
@Test public void testUnionOrderBy() throws Exception { String sql = "select e1, e2 as c_0 from pm1.g1 union all select 1, e1 from pm1.g2 order by e1"; //$NON-NLS-1$ String expected = "SELECT g_1.e1 AS c_0, convert(g_1.e2, string) AS c_1 FROM pm1.g1 AS g_1 UNION ALL SELECT '1' AS c_0, g_0.e1 AS c_1 FROM pm1.g2 AS g_0 ORDER BY c_0"; //$NON-NLS-1$ helpTest(sql, expected, true, false, RealMetadataFactory.example1Cached()); }
@Test public void testLongOrderByAlias() throws Exception { String sql = "select pm1.g1.e1 || pm1.g1.e2 as asfasdfadfasdfasdfadfasdfadsfasdfasdfasdfasdfasdfadfa, pm1.g1.e2 from pm1.g1 order by asfasdfadfasdfasdfadfasdfadsfasdfasdfasdfasdfasdfadfa"; //$NON-NLS-1$ String expected = "SELECT concat(g_0.e1, convert(g_0.e2, string)) AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0"; //$NON-NLS-1$ helpTest(sql, expected, true, false, RealMetadataFactory.example1Cached()); }
@Test public void testCorrelatedRefernce1() throws Exception { String sql = "select intnum, stringnum from bqt1.smallb where intnum in (select stringnum || b.intnum from (select intnum from bqt1.smalla) b) "; //$NON-NLS-1$ String expected = "SELECT g_0.IntNum, g_0.StringNum FROM BQT1.SmallB AS g_0 WHERE convert(g_0.IntNum, string) IN (SELECT concat(g_0.StringNum, convert(v_0.c_0, string)) FROM (SELECT g_1.IntNum AS c_0 FROM BQT1.SmallA AS g_1) AS v_0)"; //$NON-NLS-1$ helpTest(sql, expected, true, false, RealMetadataFactory.exampleBQTCached()); }
@Test public void testInlineViewWithSubQuery() throws Exception { String sql = "select intnum from (select intnum from bqt1.smallb where intnum in (select intnum a from bqt1.smalla)) b"; //$NON-NLS-1$ String expected = "SELECT v_0.c_0 FROM (SELECT g_0.IntNum AS c_0 FROM BQT1.SmallB AS g_0 WHERE g_0.IntNum IN (SELECT g_1.IntNum FROM BQT1.SmallA AS g_1)) AS v_0"; //$NON-NLS-1$ helpTest(sql, expected, true, false, RealMetadataFactory.exampleBQTCached()); }
static AtomicRequestMessage createNewAtomicRequestMessage(int requestid, int nodeid) throws Exception { RequestMessage rm = new RequestMessage(); DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(EXAMPLE_BQT, RealMetadataFactory.exampleBQTVDB()); workContext.getSession().setSessionId(String.valueOf(1)); workContext.getSession().setUserName("foo"); // $NON-NLS-1$ AtomicRequestMessage request = new AtomicRequestMessage(rm, workContext, nodeid); request.setCommand( helpGetCommand("SELECT BQT1.SmallA.INTKEY FROM BQT1.SmallA", EXAMPLE_BQT)); // $NON-NLS-1$ request.setRequestID(new RequestID(requestid)); request.setConnectorName("testing"); // $NON-NLS-1$ request.setFetchSize(5); request.setCommandContext(new CommandContext()); return request; }
@Test public void testOrderBySymbolName() throws Exception { String sql = "select e1 from pm1.g1 order by e1"; // $NON-NLS-1$ String expected = "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0"; // $NON-NLS-1$ Query command = (Query) helpTest(sql, expected, true, false, RealMetadataFactory.example1Cached()); assertEquals( ((Symbol) command.getOrderBy().getSortKeys().get(0)).getName(), "c_0"); // $NON-NLS-1$ assertEquals( ((Symbol) command.getProjectedSymbols().get(0)).getShortName(), "c_0"); // $NON-NLS-1$ }
@Test public void testDDLMetadata() throws Exception { String ddl = "CREATE VIRTUAL FUNCTION SourceFunc(msg varchar) RETURNS varchar " + "OPTIONS(CATEGORY 'misc', DETERMINISM 'DETERMINISTIC', " + "\"NULL-ON-NULL\" 'true', JAVA_CLASS '" + TestFunctionPushdown.class.getName() + "', JAVA_METHOD 'sourceFunc');" + "CREATE VIEW X (Y varchar) as SELECT e1 from pm1.g1;"; MetadataFactory mf = TestDDLParser.helpParse(ddl, "model"); mf.getSchema().setPhysical(false); MetadataStore ms = mf.asMetadataStore(); ms.merge(RealMetadataFactory.example1Cached().getMetadataStore()); QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(ms, "example1"); FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); caps.setFunctionSupport("model.SourceFunc", true); capFinder.addCapabilities("pm1", caps); // $NON-NLS-1$ helpPlan( "select sourceFunc(y) from x", metadata, null, capFinder, new String[] {"SELECT sourceFunc(g_0.e1) FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ caps.setFunctionSupport("model.SourceFunc", false); helpPlan( "select sourceFunc(y) from x", metadata, null, capFinder, new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ }
@Test(expected = TeiidRuntimeException.class) public void testKeepAliases1() throws Exception { String sql = "select g_1.intkey as a, g_1.stringkey as b from BQT1.SmallA g_1, BQT1.SmallB ORDER BY a, b"; //$NON-NLS-1$ String expected = "SELECT g.IntKey AS c_0, g.StringKey AS c_1 FROM BQT1.SmallA AS g ORDER BY c_0, c_1"; //$NON-NLS-1$ AliasGenerator av = new AliasGenerator(true, false); Map<String, String> aliasMap = new HashMap<String, String>(); aliasMap.put("g_1", "g_1"); av.setAliasMapping(aliasMap); helpTest(sql, expected, RealMetadataFactory.exampleBQTCached(), av); }
@Test public void testMustPushdownOverMultipleSources() throws Exception { QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata( RealMetadataFactory.example1Cached().getMetadataStore(), "example1", new FunctionTree("foo", new FakeFunctionMetadataSource())); FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); caps.setFunctionSupport("misc.namespace.func", true); capFinder.addCapabilities("pm1", caps); // $NON-NLS-1$ capFinder.addCapabilities("pm2", caps); // $NON-NLS-1$ String sql = "select func(x.e1) from pm1.g1 as x, pm2.g1 as y where x.e2 = y.e2"; // $NON-NLS-1$ ProcessorPlan plan = helpPlan( sql, metadata, null, capFinder, new String[] { "SELECT g_0.e2 AS c_0, func(g_0.e1) AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e2 AS c_0 FROM pm2.g1 AS g_0 ORDER BY c_0" }, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ HardcodedDataManager dataManager = new HardcodedDataManager(); dataManager.addData( "SELECT g_0.e2 AS c_0, func(g_0.e1) AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0", new List[] {Arrays.asList(1, "a")}); dataManager.addData( "SELECT g_0.e2 AS c_0 FROM pm2.g1 AS g_0 ORDER BY c_0", new List[] {Arrays.asList(1), Arrays.asList(2)}); TestProcessor.helpProcess(plan, dataManager, new List[] {Arrays.asList("a")}); }
@Test public void testConcat2() throws Exception { QueryMetadataInterface metadata = RealMetadataFactory.example1Cached(); FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); caps.setFunctionSupport(SourceSystemFunctions.CONCAT2, true); capFinder.addCapabilities("pm1", caps); // $NON-NLS-1$ String sql = "select concat2(x.e1, x.e1) from pm1.g1 as x"; // $NON-NLS-1$ helpPlan( sql, metadata, null, capFinder, new String[] {"SELECT concat2(g_0.e1, g_0.e1) FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ // cannot pushdown caps.setFunctionSupport(SourceSystemFunctions.CONCAT2, false); ProcessorPlan plan = helpPlan( sql, metadata, null, capFinder, new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ HardcodedDataManager dataManager = new HardcodedDataManager(); dataManager.addData( "SELECT g_0.e1 FROM pm1.g1 AS g_0", new List[] {Arrays.asList("a"), Arrays.asList((String) null)}); TestProcessor.helpProcess( plan, dataManager, new List[] {Arrays.asList("aa"), Arrays.asList((String) null)}); caps.setFunctionSupport(SourceSystemFunctions.CONCAT, true); caps.setFunctionSupport(SourceSystemFunctions.IFNULL, true); caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true); // will get replaced in the LanguageBridgeFactory helpPlan( sql, metadata, null, capFinder, new String[] {"SELECT concat2(g_0.e1, g_0.e1) FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$ }
public static TransformationMetadata getTransformationMetadata( MetadataFactory mf, ODataExecutionFactory ef) throws Exception { TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata( mf.asMetadataStore(), "trippin", new FunctionTree("foo", new UDFSource(ef.getPushDownFunctions()))); ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore()); if (report.hasItems()) { throw new RuntimeException(report.getFailureMessage()); } return metadata; }
@Test public void testStreaming() throws Exception { WSExecutionFactory ef = new WSExecutionFactory(); MetadataFactory mf = new MetadataFactory( "vdb", 1, "x", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null); ef.getMetadata(mf, null); Procedure p = mf.getSchema().getProcedure(WSExecutionFactory.INVOKE_HTTP); assertEquals(7, p.getParameters().size()); TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb"); RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm); WSConnection mockConnection = Mockito.mock(WSConnection.class); Dispatch<Object> mockDispatch = mockDispatch(); DataSource mock = Mockito.mock(DataSource.class); ByteArrayInputStream baos = new ByteArrayInputStream(new byte[100]); Mockito.stub(mock.getInputStream()).toReturn(baos); Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(mock); Mockito.stub( mockConnection.createDispatch( Mockito.any(String.class), Mockito.any(String.class), Mockito.any(Class.class), Mockito.any(Service.Mode.class))) .toReturn(mockDispatch); CommandBuilder cb = new CommandBuilder(tm); Call call = (Call) cb.getCommand("call invokeHttp('GET', null, null, true)"); BinaryWSProcedureExecution pe = new BinaryWSProcedureExecution( call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection); pe.execute(); List<?> result = pe.getOutputParameterValues(); Blob b = (Blob) result.get(0); assertEquals(100, ObjectConverterUtil.convertToByteArray(b.getBinaryStream()).length); try { ObjectConverterUtil.convertToByteArray(b.getBinaryStream()); fail(); } catch (SQLException e) { // should only be able to read once } }