public Object clone(){ AccessNode clonedNode = new AccessNode(); this.copyTo(clonedNode); return clonedNode; }
private void checkForSharedSourceCommand(AccessNode aNode) { //create a top level key to avoid the full command toString String modelName = aNode.getModelName(); Command cmd = aNode.getCommand(); //don't share full scans against internal sources, it's a waste of buffering if (CoreConstants.SYSTEM_MODEL.equals(modelName) || CoreConstants.SYSTEM_ADMIN_MODEL.equals(modelName) || TempMetadataAdapter.TEMP_MODEL.getName().equals(modelName)) { if (!(cmd instanceof Query)) { return; } Query query = (Query)cmd; if (query.getOrderBy() == null && query.getCriteria() == null) { return; } } AccessNode other = sharedCommands.get(cmd); if (other == null) { sharedCommands.put(cmd, aNode); } else { if (other.info == null) { other.info = new RegisterRequestParameter.SharedAccessInfo(); other.info.id = sharedId.getAndIncrement(); } other.info.sharingCount++; aNode.info = other.info; } }
openInternal(); //-- blocked during actual open open = true; return this.getChildren()[0].nextBatch(); while (shouldExecute && (!tupleSources.isEmpty() || hasNextCommand())) { if (tupleSources.isEmpty() && processCommandsIndividually()) { registerNext(); addBatchRow(tuple); if (isBatchFull()) { return pullBatch(); if (reserved > 0) { reserved -= schemaSize; getBufferManager().releaseBuffers(schemaSize); if (!processCommandsIndividually()) { registerNext(); if (processCommandsIndividually()) { if (hasPendingRows()) { return pullBatch(); if (processCommandsIndividually()) { if (hasPendingRows()) { return pullBatch();
public static QueryCommand getQueryCommand(AccessNode aNode) { if (aNode == null) { return null; } Command command = aNode.getCommand(); if(!(command instanceof QueryCommand)) { return null; } QueryCommand queryCommand = (QueryCommand)command; if (aNode.getProjection() != null && aNode.getProjection().length > 0) { Query newCommand = (Query)queryCommand.clone(); newCommand.getSelect().setSymbols(aNode.getOriginalSelect()); return newCommand; } return queryCommand; }
RelationalPlan value = entry.getValue(); value.reset(); state.processor = new QueryProcessor(value, getContext().clone(), getBufferManager(), getDataManager()); state.collector = state.processor.createBatchCollector(); this.evaluatedPlans.put(entry.getKey(), state); VDBMetaData vdb = getContext().getVdb(); ModelMetaData model = vdb.getModel(getModelName()); List<String> sources = model.getSourceNames(); if (this.getChildCount() != 0 && (this.sourceNames == null || !this.sourceNames.equals(sources))) { this.childCount--; this.getChildren()[0] = null; if (this.getChildCount() == 0) { sourceNames = sources; RelationalNode node = multiSourceModify(this, connectorBindingExpression, getContext().getMetadata(), sourceNames); RelationalPlan.connectExternal(node, getContext(), getDataManager(), getBufferManager()); this.addChild(node); this.getChildren()[0].open(); return; this.connectorBindingId = (String) getEvaluator(Collections.emptyMap()).evaluate(this.connectorBindingExpression, null); VDBMetaData vdb = getContext().getVdb(); ModelMetaData model = vdb.getModel(getModelName()); List<String> sources = model.getSourceNames(); String replacement = this.connectorBindingId;
aNode.setShouldEvaluateExpressions(true); } else { aNode = new AccessNode(getID()); processNode = aNode; aNode.setShouldEvaluateExpressions(ev.requiresEvaluation(EvaluationLevel.PROCESSING) || shouldEval); aNode.setCommand(command); if (modelID != null) { String fullName = metadata.getFullName(modelID); SourceCapabilities caps = capFinder.findCapabilities(fullName); aNode.setTransactionSupport((TransactionSupport) caps.getSourceProperty(Capability.TRANSACTION_SUPPORT)); if (aNode.getModelId() != null && metadata.isMultiSource(aNode.getModelId())) { VDBMetaData vdb = context.getVdb(); aNode.setShouldEvaluateExpressions(true); //forces a rewrite aNode.setElements( (List) node.getProperty(NodeConstants.Info.OUTPUT_COLS) ); if (node.hasBooleanProperty(Info.IS_MULTI_SOURCE)) { Expression ex = rewriteMultiSourceCommand(aNode.getCommand()); aNode.setConnectorBindingExpression(ex); aNode.setMultiSource(true); } else { String sourceName = (String)node.getProperty(Info.SOURCE_NAME); aNode.setConnectorBindingExpression(new Constant(sourceName)); if (!aNode.isShouldEvaluate()) { aNode.minimizeProject(command); aNode.setSubPlans(plans);
boolean hasOutParams = RelationalNodeUtil.hasOutputParams(accessNode.getCommand()); if (!Constant.NULL_CONSTANT.equals(ex)) { for(String sourceName:sourceNames) { Command command = accessNode.getCommand(); AccessNode instanceNode = (AccessNode) accessNode.clone(); instanceNode.setMultiSource(false); instanceNode.setCommand(command); accessNodes.add(instanceNode); instanceNode.setConnectorBindingId(sourceName); throw new QueryProcessingException(QueryPlugin.Event.TEIID30561, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30561, accessNode.getCommand())); if (RelationalNodeUtil.isUpdate(accessNode.getCommand())) { ProjectNode pnode = new ProjectNode(accessNode.getID()); pnode.setSelectSymbols(Arrays.asList(new Constant(0))); return pnode; NullNode nullNode = new NullNode(accessNode.getID()); return nullNode; UnionAllNode unionNode = new UnionAllNode(accessNode.getID()); unionNode.setElements(accessNode.getElements()); for (AccessNode newNode : accessNodes) { unionNode.addChild(newNode); if (RelationalNodeUtil.isUpdate(accessNode.getCommand())) {
private void helpTestOpen(Command command, String expectedCommand, boolean shouldRegisterRequest) throws Exception { // Setup AccessNode node = new AccessNode(1); node.setCommand(command); CommandContext context = new CommandContext(); BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); FakeDataManager dataManager = new FakeDataManager(); TestProcessor.sampleData1(dataManager); node.setElements(command.getProjectedSymbols()); node.initialize(context, bm, dataManager); node.setShouldEvaluateExpressions(true); // Call open() node.open(); if (shouldRegisterRequest) { assertEquals(Arrays.asList(expectedCommand), dataManager.getQueries()); } else { assertEquals(0, dataManager.getQueries().size()); } }
Map<GroupSymbol, RelationalPlan> subplans = accessNode.getSubPlans(); if (subplans != null) { for (RelationalPlan subplan : subplans.values()) { Command command = accessNode.getCommand(); if (command instanceof Insert && ((Insert)command).getQueryExpression() != null) { command = ((Insert)command).getQueryExpression(); accessNode.setShouldEvaluateExpressions(true);
public static Object validateCommandPushdown(Object critNodeModelID, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, AccessNode aNode, boolean considerConformed) throws TeiidComponentException { // Check that query in access node is for the same model as current node try { if (!(aNode.getCommand() instanceof QueryCommand)) { return null; } Object modelID = aNode.getModelId(); if (critNodeModelID == null) { critNodeModelID = modelID; } else if(!CapabilitiesUtil.isSameConnector(critNodeModelID, modelID, metadata, capFinder) && (!considerConformed || !RuleRaiseAccess.isConformed(metadata, capFinder, aNode.getConformedTo(), modelID, null, critNodeModelID))) { return null; } } catch(QueryMetadataException e) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30272, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30272)); } return critNodeModelID; }
@Test public void testConformedJoin() throws Exception { String sql = "select pm1.g1.e1 from pm1.g1, pm2.g2 where g1.e1=g2.e1"; RelationalPlan plan = (RelationalPlan)helpPlan(sql, tm, new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0, pm2.g2 AS g_1 WHERE g_0.e1 = g_1.e1"}, ComparisonMode.EXACT_COMMAND_STRING); AccessNode anode = (AccessNode) plan.getRootNode(); assertEquals("pm2", anode.getModelName()); //it should work either way sql = "select pm1.g1.e1 from pm2.g2, pm1.g1 where g1.e1=g2.e1"; plan = (RelationalPlan)helpPlan(sql, tm, new String[] {"SELECT g_1.e1 FROM pm2.g2 AS g_0, pm1.g1 AS g_1 WHERE g_1.e1 = g_0.e1"}, ComparisonMode.EXACT_COMMAND_STRING); anode = (AccessNode) plan.getRootNode(); assertEquals("pm2", anode.getModelName()); }
@Test public void testUninitailizedClose() throws Exception { new AccessNode().close(); } }
@Override public void open() throws TeiidComponentException, TeiidProcessingException { CommandContext context = getContext().clone(); context.pushVariableContext(new VariableContext()); this.setContext(context); DependentProcedureExecutionNode.shareVariableContext(this, context); super.open(); }
private static void getAtomicCommands(RelationalNode node, Set<Command> atomicQueries) { if(node instanceof AccessNode) { AccessNode accessNode = (AccessNode) node; atomicQueries.add( accessNode.getCommand()); } // Recurse through children RelationalNode[] children = node.getChildren(); for(int i=0; i<children.length; i++) { if(children[i] != null) { getAtomicCommands(children[i], atomicQueries); } else { break; } } }
RelationalPlan value = entry.getValue(); value.reset(); state.processor = new QueryProcessor(value, getContext().clone(), getBufferManager(), getDataManager()); state.collector = state.processor.createBatchCollector(); this.evaluatedPlans.put(entry.getKey(), state); VDBMetaData vdb = getContext().getVdb(); ModelMetaData model = vdb.getModel(getModelName()); List<String> sources = model.getSourceNames(); if (this.getChildCount() != 0 && (this.sourceNames == null || !this.sourceNames.equals(sources))) { this.childCount--; this.getChildren()[0] = null; if (this.getChildCount() == 0) { sourceNames = sources; RelationalNode node = multiSourceModify(this, connectorBindingExpression, getContext().getMetadata(), sourceNames); RelationalPlan.connectExternal(node, getContext(), getDataManager(), getBufferManager()); this.addChild(node); this.getChildren()[0].open(); return; this.connectorBindingId = (String) getEvaluator(Collections.emptyMap()).evaluate(this.connectorBindingExpression, null); VDBMetaData vdb = getContext().getVdb(); ModelMetaData model = vdb.getModel(getModelName()); List<String> sources = model.getSourceNames(); String replacement = this.connectorBindingId;
aNode.setShouldEvaluateExpressions(true); } else { aNode = new AccessNode(getID()); processNode = aNode; aNode.setShouldEvaluateExpressions(ev.requiresEvaluation(EvaluationLevel.PROCESSING) || shouldEval); aNode.setCommand(command); if (modelID != null) { String fullName = metadata.getFullName(modelID); SourceCapabilities caps = capFinder.findCapabilities(fullName); aNode.setTransactionSupport((TransactionSupport) caps.getSourceProperty(Capability.TRANSACTION_SUPPORT)); if (aNode.getModelId() != null && metadata.isMultiSource(aNode.getModelId())) { VDBMetaData vdb = context.getVdb(); aNode.setShouldEvaluateExpressions(true); //forces a rewrite aNode.setElements( (List) node.getProperty(NodeConstants.Info.OUTPUT_COLS) ); if (node.hasBooleanProperty(Info.IS_MULTI_SOURCE)) { Expression ex = rewriteMultiSourceCommand(aNode.getCommand()); aNode.setConnectorBindingExpression(ex); aNode.setMultiSource(true); } else { String sourceName = (String)node.getProperty(Info.SOURCE_NAME); aNode.setConnectorBindingExpression(new Constant(sourceName)); if (!aNode.isShouldEvaluate()) { aNode.minimizeProject(command); aNode.setSubPlans(plans);
boolean hasOutParams = RelationalNodeUtil.hasOutputParams(accessNode.getCommand()); if (!Constant.NULL_CONSTANT.equals(ex)) { for(String sourceName:sourceNames) { Command command = accessNode.getCommand(); AccessNode instanceNode = (AccessNode) accessNode.clone(); instanceNode.setMultiSource(false); instanceNode.setCommand(command); accessNodes.add(instanceNode); instanceNode.setConnectorBindingId(sourceName); throw new QueryProcessingException(QueryPlugin.Event.TEIID30561, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30561, accessNode.getCommand())); if (RelationalNodeUtil.isUpdate(accessNode.getCommand())) { ProjectNode pnode = new ProjectNode(accessNode.getID()); pnode.setSelectSymbols(Arrays.asList(new Constant(0))); return pnode; NullNode nullNode = new NullNode(accessNode.getID()); return nullNode; UnionAllNode unionNode = new UnionAllNode(accessNode.getID()); unionNode.setElements(accessNode.getElements()); for (AccessNode newNode : accessNodes) { unionNode.addChild(newNode); if (RelationalNodeUtil.isUpdate(accessNode.getCommand())) {
@Test public void testExecCount()throws Exception{ // Setup AccessNode node = new AccessNode(1); Query query = (Query)TestResolver.helpResolve("SELECT e1, e2 FROM pm1.g1 WHERE e2 = 5", RealMetadataFactory.example1Cached()); //$NON-NLS-1$ node.setCommand(query); CommandContext context = new CommandContext(); BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); FakeDataManager dataManager = new FakeDataManager(); TestProcessor.sampleData1(dataManager); node.setElements(query.getProjectedSymbols()); node.initialize(context, bm, dataManager); // Call open() node.open(); assertEquals(Arrays.asList("SELECT e1, e2 FROM pm1.g1 WHERE e2 = 5"), dataManager.getQueries()); //$NON-NLS-1$ }
Map<GroupSymbol, RelationalPlan> subplans = accessNode.getSubPlans(); if (subplans != null) { for (RelationalPlan subplan : subplans.values()) { Command command = accessNode.getCommand(); if (command instanceof Insert && ((Insert)command).getQueryExpression() != null) { command = ((Insert)command).getQueryExpression(); accessNode.setShouldEvaluateExpressions(true);
public static QueryCommand getQueryCommand(AccessNode aNode) { if (aNode == null) { return null; } Command command = aNode.getCommand(); if(!(command instanceof QueryCommand)) { return null; } QueryCommand queryCommand = (QueryCommand)command; if (aNode.getProjection() != null && aNode.getProjection().length > 0) { Query newCommand = (Query)queryCommand.clone(); newCommand.getSelect().setSymbols(aNode.getOriginalSelect()); return newCommand; } return queryCommand; }