@Test(expected=TeiidProcessingException.class) public void testMaxRecursive() throws Exception { String sql = "WITH t(n) AS ( VALUES (1) UNION ALL SELECT n+1 FROM t WHERE n < 64 ) SELECT sum(n) FROM t;"; //$NON-NLS-1$ List<?>[] expected = new List[] { Arrays.asList(2080l), }; FakeDataManager dataManager = new FakeDataManager(); ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached()); CommandContext cc = createCommandContext(); cc.setSession(new SessionMetadata()); cc.setSessionVariable(TempTableStore.TEIID_MAX_RECURSION, 10); helpProcess(plan, cc, dataManager, expected); }
@Before public void setup() { context = new CommandContext(); context.setDQPWorkContext(new DQPWorkContext()); context.setSession(context.getDQPWorkContext().getSession()); }
cc.setSession(new SessionMetadata()); cc.setSession(new SessionMetadata());
@Test(expected=TeiidProcessingException.class) public void testLargeArrays() throws Exception { String sql = "WITH t(n) AS ( VALUES (1) UNION ALL SELECT n+1 FROM t WHERE n < 70000 ) SELECT array_agg((n, n, n, n, n)) FROM t;"; //$NON-NLS-1$ List<?>[] expected = new List[] { Arrays.asList(2080l), }; FakeDataManager dataManager = new FakeDataManager(); dataManager.setBlockOnce(); sampleData1(dataManager); ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached()); CommandContext cc = createCommandContext(); cc.setSession(new SessionMetadata()); cc.setSessionVariable(TempTableStore.TEIID_MAX_RECURSION, 100000); helpProcess(plan, cc, dataManager, expected); }
@Test public void testInvokeUser() throws Exception { CommandContext c = new CommandContext(); c.setUserName("foodude"); //$NON-NLS-1$ c.setSession(new SessionMetadata()); c.getSession().setSecurityDomain("x"); helpInvokeMethod("user", new Class<?>[] {}, new Object[] {}, c, "foodude@x"); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testRecursive() throws Exception { String sql = "WITH t(n) AS ( VALUES (1) UNION ALL SELECT n+1 FROM t WHERE n < 64 ) SELECT sum(n) FROM t;"; //$NON-NLS-1$ List<?>[] expected = new List[] { Arrays.asList(2080l), }; FakeDataManager dataManager = new FakeDataManager(); dataManager.setBlockOnce(); sampleData1(dataManager); ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached()); CommandContext cc = createCommandContext(); cc.setSession(new SessionMetadata()); helpProcess(plan, cc, dataManager, expected); }
@Test public void testRecursiveUnion() throws Exception { String sql = "WITH t(n) AS ( (VALUES (1) union all values(2)) UNION (SELECT n+1 FROM t WHERE n < 64 union all SELECT e2 from pm1.g1) ) SELECT sum(n) FROM t;"; //$NON-NLS-1$ List<?>[] expected = new List[] { Arrays.asList(2080l), }; FakeDataManager dataManager = new FakeDataManager(); dataManager.setBlockOnce(); sampleData1(dataManager); ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached()); CommandContext cc = createCommandContext(); cc.setSession(new SessionMetadata()); helpProcess(plan, cc, dataManager, expected); }
@Test public void testRecursiveWithProjectionMinimization() throws Exception { String sql = "WITH table3 (column5,column6,column7) AS (\n" + "SELECT column1, column2, column3 FROM table1 where column1 = 'joe'\n" + "UNION ALL \n" + "SELECT column1, column2, column3 FROM table1 inner join table3 on table3.column6=table1.column1 \n" + ") \n" + "SELECT column3, column4 FROM table2 WHERE column3 IN (SELECT column5 FROM table3)"; String ddl = "CREATE FOREIGN TABLE table1 (\n" + "column1 string(4000),\n" + "column2 string(4000),\n" + "column3 string(4000)\n" + ") OPTIONS(NAMEINSOURCE 'table1', UPDATABLE 'TRUE');\n" + "\n" + "CREATE FOREIGN TABLE table2 (\n" + "column3 string(4000),\n" + "column4 string(4000)\n" + ") OPTIONS(NAMEINSOURCE 'table2', UPDATABLE 'TRUE');"; TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "x", "y"); CommandContext cc = createCommandContext(); cc.setSession(new SessionMetadata()); ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(TestOptimizer.getTypicalCapabilities()), cc); HardcodedDataManager dataManager = new HardcodedDataManager(); dataManager.addData("SELECT g_0.column1, g_0.column2 FROM y.table1 AS g_0 WHERE g_0.column1 = 'joe'", Arrays.asList("joe", "bob")); dataManager.addData("SELECT g_0.column1, g_0.column2 FROM y.table1 AS g_0 WHERE g_0.column1 = 'bob'"); dataManager.addData("SELECT g_0.column3 AS c_0, g_0.column4 AS c_1 FROM y.table2 AS g_0 WHERE g_0.column3 = 'joe' ORDER BY c_0", Arrays.asList("joe", "employee")); helpProcess(plan, cc, dataManager, new List[] {Arrays.asList("joe", "employee")}); }
@Test public void testSessionVariables() throws Exception { CommandContext c = new CommandContext(); c.setSession(new SessionMetadata()); Object result = helpInvokeMethod("teiid_session_set", new Class<?>[] {DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.OBJECT}, new Object[] {"key", "value"}, c); assertNull(result); result = helpInvokeMethod("teiid_session_get", new Class<?>[] {DataTypeManager.DefaultDataClasses.STRING}, new Object[] {"key"}, c); assertEquals("value", result); result = helpInvokeMethod("teiid_session_set", new Class<?>[] {DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.OBJECT}, new Object[] {"key", "value1"}, c); assertEquals("value", result); result = helpInvokeMethod("teiid_session_get", new Class<?>[] {DataTypeManager.DefaultDataClasses.STRING}, new Object[] {"key"}, c); assertEquals("value1", result); }
bufferManager.initialize(); CommandContext context = new CommandContext(); context.setSession(new SessionMetadata()); CommandContext.pushThreadLocalContext(context); try {
context.setSubject(workContext.getSubject()); this.context.setOptions(options); this.context.setSession(workContext.getSession()); this.context.setRequestId(this.requestId); this.context.setDQPWorkContext(this.workContext);
context.setSubject(workContext.getSubject()); this.context.setOptions(options); this.context.setSession(workContext.getSession()); this.context.setRequestId(this.requestId); this.context.setDQPWorkContext(this.workContext);
context.setSubject(workContext.getSubject()); this.context.setOptions(options); this.context.setSession(workContext.getSession()); this.context.setRequestId(this.requestId); this.context.setDQPWorkContext(this.workContext);
private AtomicRequestMessage helpSetupRequest(String sql, int nodeId, QueryMetadataInterface metadata) throws Exception { DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(metadata, vdb); Command command = helpGetCommand(sql, metadata); RequestMessage original = new RequestMessage(); original.setExecutionId(id++); original.setPartialResults(true); RequestID requestID = workContext.getRequestID(original.getExecutionId()); context = new CommandContext(); context.setSession(workContext.getSession()); context.setVdbName("test"); //$NON-NLS-1$ context.setVdbVersion(1); context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(dtm.getBufferManager(), dtm, new DefaultCapabilitiesFinder(), null, metadata)); workItem = TestDQPCoreRequestHandling.addRequest(rm, original, requestID, null, workContext); context.setWorkItem(workItem); AtomicRequestMessage request = new AtomicRequestMessage(original, workContext, nodeId); request.setCommand(command); request.setConnectorName("FakeConnectorID"); //$NON-NLS-1$ request.setCommandContext(context); return request; }