public ExecutionContextImpl(String vdbName, Object vdbVersion, Serializable executionPayload, String originalConnectionID, String connectorName, long requestId, String partId, String execCount) { commandContext = new CommandContext(); commandContext.setVdbName(vdbName); commandContext.setVdbVersion(vdbVersion.toString()); commandContext.setCommandPayload(executionPayload); commandContext.setConnectionID(originalConnectionID); commandContext.setRequestId(new RequestID(originalConnectionID, requestId)); this.connectorName = connectorName; this.partID = partId; this.executeCount = execCount; }
@Override protected TupleSource createTupleSource() throws TeiidComponentException, TeiidProcessingException { TempTableStore tts = contextStore; TempTable tt = tts.getOrCreateTempTable(tableName, query, bufferManager, true, false, context, group); if (context.getDataObjects() != null) { Object id = RelationalPlanner.getTrackableGroup(group, context.getMetadata()); if (id != null) { context.accessedDataObject(id); } } return tt.createTupleSource(query.getProjectedSymbols(), query.getCriteria(), query.getOrderBy()); } };
public static boolean applyRowSecurity(QueryMetadataInterface metadata, final GroupSymbol group, CommandContext cc) throws QueryMetadataException, TeiidComponentException { Map<String, DataPolicy> policies = cc.getAllowedDataPolicies(); if (policies == null || policies.isEmpty()) { return false; } String fullName = metadata.getFullName(group.getMetadataID()); for (Map.Entry<String, DataPolicy> entry : policies.entrySet()) { DataPolicyMetadata dpm = (DataPolicyMetadata)entry.getValue(); if (dpm.hasRowSecurity(fullName)) { return true; } } return false; }
public GlobalTableStoreImpl getSessionScopedStore(boolean create) { GlobalTableStoreImpl impl = getSession().getAttachment(GlobalTableStoreImpl.class); if (!create) { return impl; } impl = getSession().getAttachment(GlobalTableStoreImpl.class); if (impl == null) { impl = new GlobalTableStoreImpl(getBufferManager(), null, getMetadata()); getSession().addAttchment(GlobalTableStoreImpl.class, impl); } return impl; }
public void putPlan(String key, PreparedPlan plan, Determinism determinismLevel) { if (this.globalState.planCache == null) { return; } CacheID id = new CacheID(new ParseInfo(), key, getVdbName(), getVdbVersion(), getConnectionId(), getUserName()); this.globalState.planCache.put(id, determinismLevel, plan, null); }
boolean load = false; if (!info.isUpToDate()) { boolean invalidate = shouldInvalidate(context.getVdb()); load = globalStore.needsLoading(tableName, globalStore.getAddress(), true, false, info.isValid() && invalidate); if (load) { synchronized (info) { if (!info.isUpToDate()) { RequestWorkItem workItem = context.getWorkItem(); info.addWaiter(workItem); if (moreWork != null) { if (info.getVdbMetaData() != null && context.getDQPWorkContext() != null && !info.getVdbMetaData().getFullName().equals(context.getDQPWorkContext().getVDB().getFullName())) { assert executor != null; CommandContext newContext = context.clone(); newContext.setNewVDBState(newWorkContext); loadingTupleSource = loadGlobalTable(newContext, group, tableName, newContext.getGlobalTableStore()); } else { loadingTupleSource = loadGlobalTable(context, group, tableName, globalStore); loadViaRefresh(context, tableName, context.getDQPWorkContext().getVDB(), info); context.accessedDataObject(group.getMetadataID()); TupleSource result = table.createTupleSource(query.getProjectedSymbols(), query.getCriteria(), query.getOrderBy()); cancelMoreWork();
public TupleSource registerRequest(CommandContext context, Command command, String modelName, final RegisterRequestParameter parameterObject) throws TeiidComponentException, TeiidProcessingException { RequestWorkItem workItem = context.getWorkItem(); Assertion.isNotNull(workItem); if(CoreConstants.SYSTEM_MODEL.equals(modelName) || CoreConstants.SYSTEM_ADMIN_MODEL.equals(modelName)) { if (context.getDataObjects() != null) { QueryMetadataInterface metadata = context.getMetadata(); accessedGroups = GroupCollectorVisitor.getGroupsIgnoreInlineViews(command, false); boolean usedModel = false; for (GroupSymbol gs : accessedGroups) { context.accessedDataObject(gs.getMetadataID()); usedModel = true; context.setDeterminismLevel(Determinism.valueOf(prop.toUpperCase())); context.setDeterminismLevel(Determinism.valueOf(specificProp.toUpperCase())); TupleBuffer tb = null; if (cid != null) { tb = getBufferManager().createTupleBuffer(aqr.getCommand().getProjectedSymbols(), aqr.getCommandContext().getConnectionId(), TupleSourceType.PROCESSOR); result = new CachingTupleSource(this, tb, (DataTierTupleSource)result, cid, parameterObject, cd, accessedGroups, workItem);
String matTableName = CODE_PREFIX + codeTableName + ElementSymbol.SEPARATOR + keyElementName + ElementSymbol.SEPARATOR + returnElementName; TupleSource ts = context.getCodeLookup(matTableName, keyValue); if (ts == null) { QueryMetadataInterface metadata = context.getMetadata(); TempMetadataID id = context.getGlobalTableStore().getCodeTableMetadataId(codeTableName, returnElementName, keyElementName, matTableName); query.setCriteria(new CompareCriteria(keyElement, CompareCriteria.EQ, new Constant(keyValue))); ts = registerQuery(context, context.getTempTableStore(), query); return result; } catch (BlockedException e) { context.putCodeLookup(matTableName, keyValue, ts); throw e;
private DQPWorkContext createWorkContext(final CommandContext context, VDBMetaData vdb) { SessionMetadata session = createTemporarySession(context.getUserName(), "asynch-mat-view-load", vdb); //$NON-NLS-1$ session.setSubject(context.getSubject()); session.setSecurityDomain(context.getSession().getSecurityDomain()); session.setSecurityContext(context.getSession().getSecurityContext()); DQPWorkContext workContext = new DQPWorkContext(); workContext.setAdmin(true); DQPWorkContext current = context.getDQPWorkContext(); workContext.setSession(session); workContext.setPolicies(current.getAllowedDataPolicies()); workContext.setSecurityHelper(current.getSecurityHelper()); return workContext; }
@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)}); }
@Override public PreparedPlan getPreparedPlan(String query, String recursionGroup, CommandContext commandContext, QueryMetadataInterface metadata) throws TeiidComponentException, TeiidProcessingException { if (recursionGroup != null) { commandContext.pushCall(recursionGroup); } PreparedPlan pp = commandContext.getPlan(query); if (pp == null) { ParseInfo parseInfo = new ParseInfo(); Command newCommand = QueryParser.getQueryParser().parseCommand(query, parseInfo); QueryResolver.resolveCommand(newCommand, metadata); List<Reference> references = ReferenceCollectorVisitor.getReferences(newCommand); AbstractValidationVisitor visitor = new ValidationVisitor(); Request.validateWithVisitor(visitor, metadata, newCommand); newCommand = QueryRewriter.rewrite(newCommand, metadata, commandContext); AnalysisRecord record = new AnalysisRecord(false, false); ProcessorPlan plan = QueryOptimizer.optimizePlan(newCommand, metadata, idGenerator, finder, record, commandContext); pp = new PreparedPlan(); pp.setPlan(plan, commandContext); pp.setReferences(references); pp.setAnalysisRecord(record); pp.setCommand(newCommand); commandContext.putPlan(query, pp, commandContext.getDeterminismLevel()); } return pp; }
@Before public void setup() { context = new CommandContext(); context.setDQPWorkContext(new DQPWorkContext()); context.setSession(context.getDQPWorkContext().getSession()); }
/** * @see ProcessorPlan#connectDataManager(ProcessorDataManager) */ public void initialize(CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) { if (this.with != null) { context = context.clone(); tempTableStore = new TempTableStore(context.getConnectionId(), TransactionMode.NONE); tempTableStore.setParentTempTableStore(context.getTempTableStore()); context.setTempTableStore(tempTableStore); } setContext(context); connectExternal(this.root, context, dataMgr, bufferMgr); }
public ProcessorPlan execute(String sql, List<?>[] expectedResults, CapabilitiesFinder finder) throws Exception { CommandContext cc = TestProcessor.createCommandContext(); ProcessorPlan plan = TestProcessor.helpGetPlan(TestProcessor.helpParse(sql), metadata, finder, cc); cc.setTransactionContext(tc); cc.setMetadata(metadata); cc.setTempTableStore(tempStore); TestProcessor.doProcess(plan, dataManager, expectedResults, cc); assertTrue(Determinism.SESSION_DETERMINISTIC.compareTo(cc.getDeterminismLevel()) <= 0); return plan; }
@Override protected TupleSource createTupleSource() throws TeiidComponentException, TeiidProcessingException { TempTableStore tts = contextStore; TempTable tt = tts.getOrCreateTempTable(tableName, query, bufferManager, true, false, context, group); if (context.getDataObjects() != null) { Object id = RelationalPlanner.getTrackableGroup(group, context.getMetadata()); if (id != null) { context.accessedDataObject(id); } } if (context.isParallel() && query.getCriteria() == null && query.getOrderBy() != null && tt.getRowCount() > MIN_ASYNCH_SIZE) { return new AsyncTupleSource(new Callable<TupleSource>() { @Override public TupleSource call() throws Exception { synchronized (this) { return tt.createTupleSource(query.getProjectedSymbols(), query.getCriteria(), query.getOrderBy()); } } }, context); } return tt.createTupleSource(query.getProjectedSymbols(), query.getCriteria(), query.getOrderBy()); } };
@Test public void testSubqueryDoNotRewriteToJoin2() throws Exception { CommandContext cc = new CommandContext(); cc.setOptions(new Options().subqueryUnnestDefault(true)); TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where e2 < some (select pm1.g1.e2 FROM pm1.g1)", "SELECT e1 FROM pm3.g1 WHERE e2 < (SELECT MAX(X.e2) FROM (SELECT pm1.g1.e2 FROM pm1.g1) AS X)", RealMetadataFactory.example4(), cc); }
XMLQueryRowProcessor(boolean exists, CommandContext context) throws TeiidProcessingException { if (!exists) { concat = new XmlConcat(context.getBufferManager()); result = new StreamResult(concat.getWriter()); } }
protected boolean isValid(T result, CommandContext cc) { return !(result instanceof AbstractMetadataRecord) || cc.getDQPWorkContext().isAdmin() || cc.getAuthorizationValidator().isAccessible((AbstractMetadataRecord)result, cc); }
@Override protected TupleSource createTupleSource() throws TeiidComponentException, TeiidProcessingException { TupleBuffer tb = bc.collectTuples(); CachedResults cr = new CachedResults(); cr.setResults(tb, qp.getProcessorPlan()); Determinism determinismLevel = qp.getContext().getDeterminismLevel(); if (hint != null && hint.getDeterminism() != null) { LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Cache hint modified the query determinism from ",determinismLevel, " to ", hint.getDeterminism() }); //$NON-NLS-1$ //$NON-NLS-2$ determinismLevel = hint.getDeterminism(); } cache.put(cid, determinismLevel, cr, hint != null?hint.getTtl():null); context.setDeterminismLevel(determinismLevel); success = true; return tb.createIndexedTupleSource(); }
/** * @see org.teiid.query.processor.relational.PlanExecutionNode#prepareNextCommand() */ protected boolean prepareNextCommand() throws BlockedException, TeiidComponentException, TeiidProcessingException { if (this.criteriaProcessor == null) { Criteria crit = (Criteria)inputCriteria.clone(); crit = QueryRewriter.evaluateAndRewrite(crit, getEvaluator(Collections.emptyMap()), this.getContext(), this.getContext().getMetadata()); this.criteriaProcessor = new DependentProcedureCriteriaProcessor(this, crit, inputReferences, inputDefaults); } return criteriaProcessor.prepareNextCommand(this.getProcessorPlan().getContext().getVariableContext()); }