@Before public void setup() { context = new CommandContext(); context.setDQPWorkContext(new DQPWorkContext()); context.setSession(context.getDQPWorkContext().getSession()); }
@Test public void testInsertWithQueryExpression() throws TeiidException { String sql = "INSERT /*+ sh:'append' */ into pm1.g1 (e1) select e1 from pm2.g1"; //$NON-NLS-1$ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); CommandContext context = new CommandContext(); context.setDQPWorkContext(new DQPWorkContext()); context.getDQPWorkContext().getSession().setVdb(RealMetadataFactory.example1VDB()); ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(caps), context); HardcodedDataManager manager = manager("append", null); manager.addData("SELECT /*+sh:'append' */ g_0.e1 FROM pm2.g1 AS g_0", Arrays.asList("a")); manager.addData("INSERT /*+sh:'append' */ INTO pm1.g1 (e1) VALUES ('a')", Arrays.asList(1)); helpProcess(plan, manager, new List[] {Arrays.asList(1)}); }
private static CommandContext createContext() { CommandContext context = createCommandContext(); DQPWorkContext workContext = new DQPWorkContext(); HashMap<String, DataPolicy> policies = new HashMap<String, DataPolicy>(); DataPolicyMetadata policy = new DataPolicyMetadata(); PermissionMetaData pmd = new PermissionMetaData(); pmd.setResourceName("pm1.sp1.e1"); pmd.setMask("case when e2 > 1 then null else e1 end"); PermissionMetaData pmd1 = new PermissionMetaData(); pmd1.setResourceName("pm1.g1.e2"); pmd1.setMask("case when e1 = 'a' then null else e2 end"); policy.addPermission(pmd, pmd1); policy.setName("some-role"); policies.put("some-role", policy); workContext.setPolicies(policies); context.setDQPWorkContext(workContext); return context; }
context.setDQPWorkContext(workContext);
@Test public void testKeepAliases() throws Exception { String sql = "SELECT /*+ sh KEEP ALIASES bar:'leading(g)' */ e1 from pm1.g1 g order by e1 limit 1"; //$NON-NLS-1$ CommandContext cc = TestProcessor.createCommandContext(); cc.setDQPWorkContext(new DQPWorkContext()); cc.getDQPWorkContext().getSession().setVdb(RealMetadataFactory.example1VDB()); ProcessorPlan plan = TestOptimizer.getPlan(TestOptimizer.helpGetCommand(sql, RealMetadataFactory.example1Cached()), RealMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder(), null, true, cc); TestOptimizer.checkAtomicQueries(new String[] {"SELECT /*+sh KEEP ALIASES bar:'leading(g)' */ g.e1 AS c_0 FROM pm1.g1 AS g ORDER BY c_0"}, plan); List<?>[] expected = new List[] {}; helpProcess(plan, manager(null, "leading(g)"), expected); }
context.setDQPWorkContext(workContext); return context;
@Test public void testWithHintPushdown() throws TeiidException { String sql = "WITH x as /*+ no_inline */ (SELECT /*+ sh:'x' */ e1 from pm1.g2) " + "SELECT /*+ sh:'foo' bar:'leading' */ g1.e1 from pm1.g1, x where g1.e1 = x.e1 order by g1.e1 limit 1"; //$NON-NLS-1$ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); caps.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true); CommandContext context = new CommandContext(); context.setDQPWorkContext(new DQPWorkContext()); context.getDQPWorkContext().getSession().setVdb(RealMetadataFactory.example1VDB()); ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(caps), context); List<?>[] expected = new List[] {}; helpProcess(plan, manager("foo x", "leading"), expected); }
@Test public void testUnionHintPushdown() throws TeiidException { String sql = "SELECT /*+ sh:'foo' bar:'leading' */ g1.e1 from pm1.g1 " + "UNION ALL SELECT * from (SELECT /*+ sh:'x' bar:'z' */ g1.e1 from pm1.g1) as x"; //$NON-NLS-1$ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); caps.setCapabilitySupport(Capability.QUERY_UNION, true); CommandContext context = new CommandContext(); context.setDQPWorkContext(new DQPWorkContext()); context.getDQPWorkContext().getSession().setVdb(RealMetadataFactory.example1VDB()); ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(caps), context); List<?>[] expected = new List[] {}; helpProcess(plan, manager("foo x", "leading z"), expected); }
this.context.setSession(workContext.getSession()); this.context.setRequestId(this.requestId); this.context.setDQPWorkContext(this.workContext); this.context.setTransactionService(this.transactionService); this.context.setVDBClassLoader(workContext.getVDB().getAttachment(ClassLoader.class));
this.context.setSession(workContext.getSession()); this.context.setRequestId(this.requestId); this.context.setDQPWorkContext(this.workContext); this.context.setTransactionService(this.transactionService); this.context.setVDBClassLoader(workContext.getVDB().getAttachment(ClassLoader.class));
this.context.setSession(workContext.getSession()); this.context.setRequestId(this.requestId); this.context.setDQPWorkContext(this.workContext); this.context.setTransactionService(this.transactionService); this.context.setVDBClassLoader(workContext.getVDB().getAttachment(ClassLoader.class));
cc.setDQPWorkContext(RealMetadataFactory.buildWorkContext(tm)); TestProcessor.helpProcess(plan, cc, dataManager, new List[] {Arrays.asList(TimestampUtil.createDate(0, 0, 0))});
context.setDQPWorkContext(workContext); context.setOptions(options); ProcessorPlan plan = QueryOptimizer.optimizePlan(command, wrapper, idGenerator, finder, analysis, context);