@Test public void testLoopInstructionTransaction() throws Exception { //create a dummy instruction that may need a transaction to create the loop LoopInstruction loop = new LoopInstruction(new Program(false) { @Override public Boolean requiresTransaction(boolean transactionalReads) { return null; } }, "x", new RelationalPlan(new RelationalNode(1) { @Override protected TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException { return null; } @Override public Object clone() { return null; } }), "y"); assertNull(loop.requiresTransaction(true)); }
/** * Set the ProcessorPlan. * @param context */ public void setPlan(ProcessorPlan planValue, CommandContext context){ plan = planValue; this.accessInfo.populate(context, false); //TODO: expand this logic if (planValue instanceof RelationalPlan) { RelationalPlan rp = (RelationalPlan)planValue; if (rp.getRootNode() instanceof AccessNode) { this.accessInfo.setSensitiveToMetadataChanges(false); } } }
protected void copyTo(AccessNode target){ super.copyTo(target); target.modelName = modelName; target.modelId = modelId; if (this.connectorBindingExpression == null) { target.connectorBindingId = this.connectorBindingId; } target.shouldEvaluate = shouldEvaluate; if (!shouldEvaluate) { target.projection = projection; target.originalSelect = originalSelect; } target.command = command; target.info = info; target.connectorBindingExpression = this.connectorBindingExpression; target.multiSource = multiSource; target.sourceNames = sourceNames; target.conformedTo = this.conformedTo; if (this.subPlans != null) { target.subPlans = new HashMap<GroupSymbol, RelationalPlan>(); for (Map.Entry<GroupSymbol, RelationalPlan> entry : this.subPlans.entrySet()) { target.subPlans.put(entry.getKey(), entry.getValue().clone()); } } }
/** * @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 void testNoRowsFirstBatch() throws Exception { RelationalNode node = new FakeRelationalNode(0, new List[0]); RelationalPlan plan = new RelationalPlan(node); TupleBatch batch = plan.nextBatch(); assertTrue("Did not get terminator batch", batch.getTerminationFlag()); //$NON-NLS-1$ }
public RelationalPlan clone(){ RelationalPlan plan = new RelationalPlan((RelationalNode)root.clone()); plan.setOutputElements(outputCols); if (with != null) { List<WithQueryCommand> newWith = LanguageObject.Util.deepClone(this.with, WithQueryCommand.class); for (WithQueryCommand withQueryCommand : newWith) { if (withQueryCommand.isRecursive()) { SetQuery setQuery = (SetQuery)withQueryCommand.getCommand(); setQuery.getLeftQuery().setProcessorPlan(setQuery.getLeftQuery().getProcessorPlan().clone()); setQuery.getRightQuery().setProcessorPlan(setQuery.getRightQuery().getProcessorPlan().clone()); } else { withQueryCommand.getCommand().setProcessorPlan(withQueryCommand.getCommand().getProcessorPlan().clone()); } } plan.setWith(newWith); } return plan; }
assignWithClause(result.getRootNode(), this.withPlanningState.pushdownWith, false); result.setWith(new ArrayList<WithQueryCommand>(this.withPlanningState.withList.values())); if (wqc.isRecursive()) { SetQuery sq = (SetQuery)wqc.getCommand(); assignWithClause(((RelationalPlan)sq.getLeftQuery().getProcessorPlan()).getRootNode(), this.withPlanningState.pushdownWith, false); assignWithClause(((RelationalPlan)sq.getRightQuery().getProcessorPlan()).getRootNode(), this.withPlanningState.pushdownWith, false); } else { assignWithClause(((RelationalPlan)wqc.getCommand().getProcessorPlan()).getRootNode(), this.withPlanningState.pushdownWith, false); result.setOutputElements(topCols); this.sourceHint = previous; this.withPlanningState = saved;
SubqueryState state = new SubqueryState(); RelationalPlan value = entry.getValue(); value.reset(); state.processor = new QueryProcessor(value, getContext().clone(), getBufferManager(), getDataManager()); state.collector = state.processor.createBatchCollector(); sourceNames = sources; RelationalNode node = multiSourceModify(this, connectorBindingExpression, getContext().getMetadata(), sourceNames); RelationalPlan.connectExternal(node, getContext(), getDataManager(), getBufferManager()); this.addChild(node);
static Boolean requiresTransaction(boolean transactionalReads, RelationalNode node) { Boolean requiresTxn = node.requiresTransaction(transactionalReads); if (Boolean.TRUE.equals(requiresTxn)) { return true; } boolean last = true; for (RelationalNode child : node.getChildren()) { if (child == null) { continue; } Boolean childRequires = requiresTransaction(transactionalReads, child); if (Boolean.TRUE.equals(childRequires)) { return true; } if (childRequires == null) { if (requiresTxn == null) { return true; } requiresTxn = null; last = true; } else { last = false; } } if (requiresTxn == null && !last) { return true; } return requiresTxn; }
@Test public void testGet(){ SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0); helpPutPreparedPlans(cache, token, 0, 10); helpPutPreparedPlans(cache, token2, 0, 15); //read an entry for session2 (token2) PreparedPlan pPlan = cache.get(new CacheID(token2, pi, EXAMPLE_QUERY + 12)); assertNotNull("Unable to get prepared plan from cache", pPlan); //$NON-NLS-1$ assertEquals("Error getting plan from cache", new RelationalPlan(new ProjectNode(12)).toString(), pPlan.getPlan().toString()); //$NON-NLS-1$ assertEquals("Error getting command from cache", EXAMPLE_QUERY + 12, pPlan.getCommand().toString()); //$NON-NLS-1$ assertNotNull("Error getting plan description from cache", pPlan.getAnalysisRecord()); //$NON-NLS-1$ assertEquals("Error gettting reference from cache", new Reference(1), pPlan.getReferences().get(0)); //$NON-NLS-1$ }
static void connectExternal(RelationalNode node, CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) { node.initialize(context, bufferMgr, dataMgr); RelationalNode[] children = node.getChildren(); int childCount = node.getChildCount(); for(int i=0; i<childCount; i++) { if(children[i] != null) { connectExternal(children[i], context, dataMgr, bufferMgr); } else { break; } } }
@Override public void open() throws TeiidComponentException, TeiidProcessingException { if (with != null && tempTableStore.getProcessors() == null) { HashMap<String, TableProcessor> processors = new HashMap<String, TableProcessor>(); tempTableStore.setProcessors(processors); for (WithQueryCommand withCommand : this.with) { if (withCommand.isRecursive()) { SetQuery setQuery = (SetQuery)withCommand.getCommand(); ProcessorPlan initial = setQuery.getLeftQuery().getProcessorPlan(); QueryProcessor withProcessor = new QueryProcessor(initial, getContext().clone(), root.getBufferManager(), root.getDataManager()); processors.put(withCommand.getGroupSymbol().getName(), new RecursiveTableProcessor(withProcessor, withCommand.getColumns(), setQuery.getRightQuery().getProcessorPlan(), setQuery.isAll())); continue; } ProcessorPlan plan = withCommand.getCommand().getProcessorPlan(); QueryProcessor withProcessor = new QueryProcessor(plan, getContext().clone(), root.getBufferManager(), root.getDataManager()); processors.put(withCommand.getGroupSymbol().getName(), new TableProcessor(withProcessor, withCommand.getColumns())); } } this.root.open(); }
public synchronized PlanNode getDescriptionProperties() { if (getChildCount() > 0) { return this.getChildren()[0].getDescriptionProperties(); } PlanNode props = super.getDescriptionProperties(); props.addProperty(PROP_SQL, this.command.toString()); props.addProperty(PROP_MODEL_NAME, this.modelName); Collection<? extends SubqueryContainer<?>> objects = getObjects(); if (!objects.isEmpty()) { int index = 0; for (Iterator<? extends SubqueryContainer<?>> iterator = objects.iterator(); iterator.hasNext();) { SubqueryContainer<?> subqueryContainer = iterator.next(); props.addProperty(PROP_SQL + " Subplan " + index++, subqueryContainer.getCommand().getProcessorPlan().getDescriptionProperties()); //$NON-NLS-1$ } } if (this.projection != null && this.projection.length > 0 && this.originalSelect != null) { props.addProperty(PROP_SELECT_COLS, this.originalSelect.toString()); } if (this.info != null) { props.addProperty(PROP_SHARING_ID, String.valueOf(this.info.id)); } if (this.subPlans != null) { for (Map.Entry<GroupSymbol, RelationalPlan> entry : this.subPlans.entrySet()) { props.addProperty(entry.getKey() + " Dependent Subplan", entry.getValue().getDescriptionProperties()); //$NON-NLS-1$ } } return props; }
RelationalPlan subPlan = convert(entry.getValue()); List<ElementSymbol> elems = ResolverUtil.resolveElementsInGroup(entry.getKey(), metadata); subPlan.setOutputElements(elems); plans.put(entry.getKey(), subPlan); WithQueryCommand withQueryCommand = new WithQueryCommand(entry.getKey(), elems, null);
public RelationalPlan clone(){ RelationalPlan plan = new RelationalPlan((RelationalNode)root.clone()); plan.setOutputElements(outputCols); if (with != null) { List<WithQueryCommand> newWith = LanguageObject.Util.deepClone(this.with, WithQueryCommand.class); for (WithQueryCommand withQueryCommand : newWith) { if (withQueryCommand.isRecursive()) { SetQuery setQuery = (SetQuery)withQueryCommand.getCommand(); setQuery.getLeftQuery().setProcessorPlan(setQuery.getLeftQuery().getProcessorPlan().clone()); setQuery.getRightQuery().setProcessorPlan(setQuery.getRightQuery().getProcessorPlan().clone()); } else { withQueryCommand.getCommand().setProcessorPlan(withQueryCommand.getCommand().getProcessorPlan().clone()); } } plan.setWith(newWith); } return plan; }
assignWithClause(result.getRootNode(), this.withPlanningState.pushdownWith, false); result.setWith(new ArrayList<WithQueryCommand>(this.withPlanningState.withList.values())); if (wqc.isRecursive()) { SetQuery sq = (SetQuery)wqc.getCommand(); assignWithClause(((RelationalPlan)sq.getLeftQuery().getProcessorPlan()).getRootNode(), this.withPlanningState.pushdownWith, false); assignWithClause(((RelationalPlan)sq.getRightQuery().getProcessorPlan()).getRootNode(), this.withPlanningState.pushdownWith, false); } else { assignWithClause(((RelationalPlan)wqc.getCommand().getProcessorPlan()).getRootNode(), this.withPlanningState.pushdownWith, false); result.setOutputElements(topCols); this.sourceHint = previous; this.withPlanningState = saved;
/** * @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); }
SubqueryState state = new SubqueryState(); RelationalPlan value = entry.getValue(); value.reset(); state.processor = new QueryProcessor(value, getContext().clone(), getBufferManager(), getDataManager()); state.collector = state.processor.createBatchCollector(); sourceNames = sources; RelationalNode node = multiSourceModify(this, connectorBindingExpression, getContext().getMetadata(), sourceNames); RelationalPlan.connectExternal(node, getContext(), getDataManager(), getBufferManager()); this.addChild(node);
static Boolean requiresTransaction(boolean transactionalReads, RelationalNode node) { Boolean requiresTxn = node.requiresTransaction(transactionalReads); if (Boolean.TRUE.equals(requiresTxn)) { return true; } boolean last = true; for (RelationalNode child : node.getChildren()) { if (child == null) { continue; } Boolean childRequires = requiresTransaction(transactionalReads, child); if (Boolean.TRUE.equals(childRequires)) { return true; } if (childRequires == null) { if (requiresTxn == null) { return true; } requiresTxn = null; last = true; } else { last = false; } } if (requiresTxn == null && !last) { return true; } return requiresTxn; }
static void connectExternal(RelationalNode node, CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) { node.initialize(context, bufferMgr, dataMgr); RelationalNode[] children = node.getChildren(); int childCount = node.getChildCount(); for(int i=0; i<childCount; i++) { if(children[i] != null) { connectExternal(children[i], context, dataMgr, bufferMgr); } else { break; } } }