private boolean placeConvertedSelectNode(PlanNode critNode, GroupSymbol sourceGroup, PlanNode projectNode, SymbolMap symbolMap, QueryMetadataInterface metadata) throws QueryPlannerException { PlanNode copyNode = createConvertedSelectNode(critNode, sourceGroup, projectNode, symbolMap, metadata); if (copyNode == null) { return false; } PlanNode intermediateParent = NodeEditor.findParent(projectNode, NodeConstants.Types.ACCESS, NodeConstants.Types.SOURCE | NodeConstants.Types.SET_OP); if (intermediateParent != null) { intermediateParent.addAsParent(copyNode); } else { projectNode.getFirstChild().addAsParent(copyNode); } return true; }
private boolean placeConvertedSelectNode(PlanNode critNode, GroupSymbol sourceGroup, PlanNode projectNode, SymbolMap symbolMap, QueryMetadataInterface metadata) throws QueryPlannerException { PlanNode copyNode = createConvertedSelectNode(critNode, sourceGroup, projectNode, symbolMap, metadata); if (copyNode == null) { return false; } PlanNode intermediateParent = NodeEditor.findParent(projectNode, NodeConstants.Types.ACCESS, NodeConstants.Types.SOURCE | NodeConstants.Types.SET_OP); if (intermediateParent != null) { intermediateParent.addAsParent(copyNode); } else { projectNode.getFirstChild().addAsParent(copyNode); } return true; }
private void handleDuplicate(PlanNode joinNode, boolean isLeft, List independentExpressions, List dependentExpressions) { Map<Expression, Integer> seen = new HashMap<Expression, Integer>(); for (int i = 0; i < dependentExpressions.size(); i++) { Expression ex = (Expression) dependentExpressions.get(i); Integer index = seen.get(ex); if (index == null) { seen.put(ex, i); } else { Expression e1 = (Expression)independentExpressions.get(i); Expression e2 = (Expression)independentExpressions.get(index); CompareCriteria cc = new CompareCriteria(e1, CompareCriteria.EQ, e2); PlanNode impliedCriteria = RelationalPlanner.createSelectNode(cc, false); if (isLeft) { joinNode.getLastChild().addAsParent(impliedCriteria); } else { joinNode.getFirstChild().addAsParent(impliedCriteria); } independentExpressions.remove(i); dependentExpressions.remove(i); i--; } } }
private boolean placeConvertedSelectNode(PlanNode critNode, GroupSymbol sourceGroup, PlanNode projectNode, SymbolMap symbolMap, QueryMetadataInterface metadata) throws QueryPlannerException { PlanNode copyNode = createConvertedSelectNode(critNode, sourceGroup, projectNode, symbolMap, metadata); if (copyNode == null) { return false; } PlanNode intermediateParent = NodeEditor.findParent(projectNode, NodeConstants.Types.ACCESS, NodeConstants.Types.SOURCE | NodeConstants.Types.SET_OP); if (intermediateParent != null) { intermediateParent.addAsParent(copyNode); } else { projectNode.getFirstChild().addAsParent(copyNode); } return true; }
private void addEmptyFilter(Collection<AggregateSymbol> aggregates, PlanNode stageGroup, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, Object modelId) throws QueryMetadataException, TeiidComponentException { PlanNode selectNode = NodeFactory.getNewNode(NodeConstants.Types.SELECT); AggregateSymbol count = new AggregateSymbol(NonReserved.COUNT, false, null); aggregates.add(count); //consider the count aggregate for the push down call below Criteria crit = new CompareCriteria(count, CompareCriteria.GT, new Constant(new Integer(0))); selectNode.setProperty(NodeConstants.Info.SELECT_CRITERIA, crit); selectNode.setProperty(NodeConstants.Info.IS_HAVING, Boolean.TRUE); stageGroup.addAsParent(selectNode); }
private void addEmptyFilter(Collection<AggregateSymbol> aggregates, PlanNode stageGroup, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, Object modelId) throws QueryMetadataException, TeiidComponentException { PlanNode selectNode = NodeFactory.getNewNode(NodeConstants.Types.SELECT); AggregateSymbol count = new AggregateSymbol(NonReserved.COUNT, false, null); aggregates.add(count); //consider the count aggregate for the push down call below Criteria crit = new CompareCriteria(count, CompareCriteria.GT, new Constant(new Integer(0))); selectNode.setProperty(NodeConstants.Info.SELECT_CRITERIA, crit); selectNode.setProperty(NodeConstants.Info.IS_HAVING, Boolean.TRUE); stageGroup.addAsParent(selectNode); }
private void addEmptyFilter(Collection<AggregateSymbol> aggregates, PlanNode stageGroup, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, Object modelId) throws QueryMetadataException, TeiidComponentException { PlanNode selectNode = NodeFactory.getNewNode(NodeConstants.Types.SELECT); AggregateSymbol count = new AggregateSymbol(NonReserved.COUNT, false, null); aggregates.add(count); //consider the count aggregate for the push down call below Criteria crit = new CompareCriteria(count, CompareCriteria.GT, new Constant(new Integer(0))); selectNode.setProperty(NodeConstants.Info.SELECT_CRITERIA, crit); selectNode.setProperty(NodeConstants.Info.IS_HAVING, Boolean.TRUE); stageGroup.addAsParent(selectNode); }
static PlanNode performRaise(PlanNode rootNode, PlanNode accessNode, PlanNode parentNode) { if (!checkConformedSubqueries(accessNode, parentNode, true)) { return rootNode; } accessNode.removeProperty(NodeConstants.Info.EST_CARDINALITY); combineSourceHints(accessNode, parentNode); NodeEditor.removeChildNode(parentNode, accessNode); parentNode.addAsParent(accessNode); PlanNode grandparentNode = accessNode.getParent(); if(grandparentNode != null) { return rootNode; } return accessNode; }
static PlanNode performRaise(PlanNode rootNode, PlanNode accessNode, PlanNode parentNode) { if (!checkConformedSubqueries(accessNode, parentNode, true)) { return rootNode; } accessNode.removeProperty(NodeConstants.Info.EST_CARDINALITY); combineSourceHints(accessNode, parentNode); NodeEditor.removeChildNode(parentNode, accessNode); parentNode.addAsParent(accessNode); PlanNode grandparentNode = accessNode.getParent(); if(grandparentNode != null) { return rootNode; } return accessNode; }
static PlanNode performRaise(PlanNode rootNode, PlanNode accessNode, PlanNode parentNode) { if (!checkConformedSubqueries(accessNode, parentNode, true)) { return rootNode; } accessNode.removeProperty(NodeConstants.Info.EST_CARDINALITY); combineSourceHints(accessNode, parentNode); NodeEditor.removeChildNode(parentNode, accessNode); parentNode.addAsParent(accessNode); PlanNode grandparentNode = accessNode.getParent(); if(grandparentNode != null) { return rootNode; } return accessNode; }
static PlanNode createSource(GroupSymbol group, PlanNode child, List<ElementSymbol> newProject) { PlanNode branchSource = NodeFactory.getNewNode(NodeConstants.Types.SOURCE); branchSource.addGroup(group); PlanNode projectNode = NodeEditor.findNodePreOrder(child, NodeConstants.Types.PROJECT); branchSource.setProperty(Info.SYMBOL_MAP, SymbolMap.createSymbolMap(newProject, (List<? extends Expression>)projectNode.getProperty(Info.PROJECT_COLS))); child.addAsParent(branchSource); return branchSource; }
static PlanNode createSource(GroupSymbol group, PlanNode child, List<ElementSymbol> newProject) { PlanNode branchSource = NodeFactory.getNewNode(NodeConstants.Types.SOURCE); branchSource.addGroup(group); PlanNode projectNode = NodeEditor.findNodePreOrder(child, NodeConstants.Types.PROJECT); branchSource.setProperty(Info.SYMBOL_MAP, SymbolMap.createSymbolMap(newProject, (List<? extends Expression>)projectNode.getProperty(Info.PROJECT_COLS))); child.addAsParent(branchSource); return branchSource; }
static PlanNode createSource(GroupSymbol group, PlanNode child, List<ElementSymbol> newProject) { PlanNode branchSource = NodeFactory.getNewNode(NodeConstants.Types.SOURCE); branchSource.addGroup(group); PlanNode projectNode = NodeEditor.findNodePreOrder(child, NodeConstants.Types.PROJECT); branchSource.setProperty(Info.SYMBOL_MAP, SymbolMap.createSymbolMap(newProject, (List<? extends Expression>)projectNode.getProperty(Info.PROJECT_COLS))); child.addAsParent(branchSource); return branchSource; }
private void addBranchLimit(PlanNode limitNode, List<PlanNode> limitNodes, QueryMetadataInterface metadata, Expression parentLimit, Expression parentOffset, PlanNode grandChild) { PlanNode newLimit = newLimit(limitNode); newLimit.setProperty(NodeConstants.Info.MAX_TUPLE_LIMIT, op(SourceSystemFunctions.ADD_OP, parentLimit, parentOffset, metadata.getFunctionLibrary())); grandChild.addAsParent(newLimit); newLimit.setProperty(NodeConstants.Info.OUTPUT_COLS, newLimit.getFirstChild().getProperty(NodeConstants.Info.OUTPUT_COLS)); if (NodeEditor.findParent(newLimit, NodeConstants.Types.ACCESS) == null) { limitNodes.add(newLimit); } if (grandChild.getType() == NodeConstants.Types.SET_OP) { newLimit.setProperty(Info.IS_COPIED, true); } newLimit.setProperty(Info.IS_PUSHED, true); }
private void addBranchLimit(PlanNode limitNode, List<PlanNode> limitNodes, QueryMetadataInterface metadata, Expression parentLimit, Expression parentOffset, PlanNode grandChild) { PlanNode newLimit = newLimit(limitNode); newLimit.setProperty(NodeConstants.Info.MAX_TUPLE_LIMIT, op(SourceSystemFunctions.ADD_OP, parentLimit, parentOffset, metadata.getFunctionLibrary())); grandChild.addAsParent(newLimit); newLimit.setProperty(NodeConstants.Info.OUTPUT_COLS, newLimit.getFirstChild().getProperty(NodeConstants.Info.OUTPUT_COLS)); if (NodeEditor.findParent(newLimit, NodeConstants.Types.ACCESS) == null) { limitNodes.add(newLimit); } if (grandChild.getType() == NodeConstants.Types.SET_OP) { newLimit.setProperty(Info.IS_COPIED, true); } newLimit.setProperty(Info.IS_PUSHED, true); }
private void addBranchLimit(PlanNode limitNode, List<PlanNode> limitNodes, QueryMetadataInterface metadata, Expression parentLimit, Expression parentOffset, PlanNode grandChild) { PlanNode newLimit = newLimit(limitNode); newLimit.setProperty(NodeConstants.Info.MAX_TUPLE_LIMIT, op(SourceSystemFunctions.ADD_OP, parentLimit, parentOffset, metadata.getFunctionLibrary())); grandChild.addAsParent(newLimit); newLimit.setProperty(NodeConstants.Info.OUTPUT_COLS, newLimit.getFirstChild().getProperty(NodeConstants.Info.OUTPUT_COLS)); if (NodeEditor.findParent(newLimit, NodeConstants.Types.ACCESS) == null) { limitNodes.add(newLimit); } if (grandChild.getType() == NodeConstants.Types.SET_OP) { newLimit.setProperty(Info.IS_COPIED, true); } newLimit.setProperty(Info.IS_PUSHED, true); }
private void pushOrderByAndLimit(PlanNode limitNode, List<PlanNode> limitNodes, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, CommandContext context, PlanNode child, Expression parentLimit, Expression parentOffset, PlanNode branch) throws QueryMetadataException, TeiidComponentException { //push both the limit and order by OrderBy parentOrderBy = (OrderBy) child.getProperty(NodeConstants.Info.SORT_ORDER); PlanNode newSort = NodeFactory.getNewNode(NodeConstants.Types.SORT); OrderBy newOrderBy = parentOrderBy.clone(); newSort.setProperty(Info.SORT_ORDER, newOrderBy); newSort.addGroups(child.getGroups()); newSort.setProperty(NodeConstants.Info.OUTPUT_COLS, branch.getProperty(NodeConstants.Info.OUTPUT_COLS)); branch.addAsParent(newSort); addBranchLimit(limitNode, limitNodes, metadata, parentLimit, parentOffset, newSort); if (limitNode.hasBooleanProperty(Info.IS_PUSHED)) { //remove the intermediate ordering/limit NodeEditor.removeChildNode(limitNode, limitNode.getFirstChild()); NodeEditor.removeChildNode(limitNode.getParent(), limitNode); } }
private void pushOrderByAndLimit(PlanNode limitNode, List<PlanNode> limitNodes, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, CommandContext context, PlanNode child, Expression parentLimit, Expression parentOffset, PlanNode branch) throws QueryMetadataException, TeiidComponentException { //push both the limit and order by OrderBy parentOrderBy = (OrderBy) child.getProperty(NodeConstants.Info.SORT_ORDER); PlanNode newSort = NodeFactory.getNewNode(NodeConstants.Types.SORT); OrderBy newOrderBy = parentOrderBy.clone(); newSort.setProperty(Info.SORT_ORDER, newOrderBy); newSort.addGroups(child.getGroups()); newSort.setProperty(NodeConstants.Info.OUTPUT_COLS, branch.getProperty(NodeConstants.Info.OUTPUT_COLS)); branch.addAsParent(newSort); addBranchLimit(limitNode, limitNodes, metadata, parentLimit, parentOffset, newSort); if (limitNode.hasBooleanProperty(Info.IS_PUSHED)) { //remove the intermediate ordering/limit NodeEditor.removeChildNode(limitNode, limitNode.getFirstChild()); NodeEditor.removeChildNode(limitNode.getParent(), limitNode); } }
private void pushOrderByAndLimit(PlanNode limitNode, List<PlanNode> limitNodes, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, CommandContext context, PlanNode child, Expression parentLimit, Expression parentOffset, PlanNode branch) throws QueryMetadataException, TeiidComponentException { //push both the limit and order by OrderBy parentOrderBy = (OrderBy) child.getProperty(NodeConstants.Info.SORT_ORDER); PlanNode newSort = NodeFactory.getNewNode(NodeConstants.Types.SORT); OrderBy newOrderBy = parentOrderBy.clone(); newSort.setProperty(Info.SORT_ORDER, newOrderBy); newSort.addGroups(child.getGroups()); newSort.setProperty(NodeConstants.Info.OUTPUT_COLS, branch.getProperty(NodeConstants.Info.OUTPUT_COLS)); branch.addAsParent(newSort); addBranchLimit(limitNode, limitNodes, metadata, parentLimit, parentOffset, newSort); if (limitNode.hasBooleanProperty(Info.IS_PUSHED)) { //remove the intermediate ordering/limit NodeEditor.removeChildNode(limitNode, limitNode.getFirstChild()); NodeEditor.removeChildNode(limitNode.getParent(), limitNode); } }
@Test public void testPushAcrossFrameWithAccessNode() throws Exception { QueryMetadataInterface metadata = new TempMetadataAdapter(RealMetadataFactory.example1Cached(), new TempMetadataStore()); Command command = TestOptimizer.helpGetCommand("select * from (select * from pm1.g1 union select * from pm1.g2) x where e1 = 1", metadata); //$NON-NLS-1$ Command subCommand = TestOptimizer.helpGetCommand("select * from pm1.g1 union select * from pm1.g2", metadata); //$NON-NLS-1$ RelationalPlanner p = new RelationalPlanner(); CommandContext cc = new CommandContext(); p.initialize(command, null, metadata, null, null, cc); PlanNode root = p.generatePlan(command); PlanNode child = p.generatePlan(subCommand); PlanNode sourceNode = NodeEditor.findNodePreOrder(root, NodeConstants.Types.SOURCE); sourceNode.addFirstChild(child); sourceNode.setProperty(NodeConstants.Info.SYMBOL_MAP, SymbolMap.createSymbolMap(sourceNode.getGroups().iterator().next(), (List<Expression>)child.getFirstChild().getProperty(Info.PROJECT_COLS), metadata)); //add a dummy access node PlanNode accessNode = NodeFactory.getNewNode(NodeConstants.Types.ACCESS); accessNode.addGroups(child.getFirstChild().getGroups()); child.getFirstChild().addAsParent(accessNode); new RulePushSelectCriteria().execute(root, metadata, new DefaultCapabilitiesFinder(), new RuleStack(), AnalysisRecord.createNonRecordingRecord(), cc); // the select node should still be above the access node accessNode = NodeEditor.findNodePreOrder(root, NodeConstants.Types.ACCESS); assertEquals(NodeConstants.Types.SELECT, accessNode.getParent().getType()); assertNull(NodeEditor.findNodePreOrder(accessNode, NodeConstants.Types.SELECT)); }