public static final PlanNode findParent(PlanNode root, int types) { return findParent(root, types, NodeConstants.Types.NO_TYPE); }
public static final PlanNode findParent(PlanNode root, int types) { return findParent(root, types, NodeConstants.Types.NO_TYPE); }
public static final PlanNode findParent(PlanNode root, int types) { return findParent(root, types, NodeConstants.Types.NO_TYPE); }
public List<SymbolMap> getExportedCorrelatedReferences() { if (type != NodeConstants.Types.JOIN) { return Collections.emptyList(); } LinkedList<SymbolMap> result = new LinkedList<SymbolMap>(); for (PlanNode child : NodeEditor.findAllNodes(this, NodeConstants.Types.SOURCE, NodeConstants.Types.ACCESS)) { SymbolMap references = (SymbolMap)child.getProperty(NodeConstants.Info.CORRELATED_REFERENCES); if (references == null) { continue; } Set<GroupSymbol> correlationGroups = GroupsUsedByElementsVisitor.getGroups(references.getValues()); PlanNode joinNode = NodeEditor.findParent(child, NodeConstants.Types.JOIN, NodeConstants.Types.SOURCE); while (joinNode != null) { if (joinNode.getGroups().containsAll(correlationGroups)) { if (joinNode == this) { result.add(references); } break; } joinNode = NodeEditor.findParent(joinNode, NodeConstants.Types.JOIN, NodeConstants.Types.SOURCE); } } return result; }
public List<SymbolMap> getExportedCorrelatedReferences() { if (type != NodeConstants.Types.JOIN) { return Collections.emptyList(); } LinkedList<SymbolMap> result = new LinkedList<SymbolMap>(); for (PlanNode child : NodeEditor.findAllNodes(this, NodeConstants.Types.SOURCE, NodeConstants.Types.ACCESS)) { SymbolMap references = (SymbolMap)child.getProperty(NodeConstants.Info.CORRELATED_REFERENCES); if (references == null) { continue; } Set<GroupSymbol> correlationGroups = GroupsUsedByElementsVisitor.getGroups(references.getValues()); PlanNode joinNode = NodeEditor.findParent(child, NodeConstants.Types.JOIN, NodeConstants.Types.SOURCE); while (joinNode != null) { if (joinNode.getGroups().containsAll(correlationGroups)) { if (joinNode == this) { result.add(references); } break; } joinNode = NodeEditor.findParent(joinNode, NodeConstants.Types.JOIN, NodeConstants.Types.SOURCE); } } return result; }
public List<SymbolMap> getExportedCorrelatedReferences() { if (type != NodeConstants.Types.JOIN) { return Collections.emptyList(); } LinkedList<SymbolMap> result = new LinkedList<SymbolMap>(); for (PlanNode child : NodeEditor.findAllNodes(this, NodeConstants.Types.SOURCE, NodeConstants.Types.ACCESS)) { SymbolMap references = (SymbolMap)child.getProperty(NodeConstants.Info.CORRELATED_REFERENCES); if (references == null) { continue; } Set<GroupSymbol> correlationGroups = GroupsUsedByElementsVisitor.getGroups(references.getValues()); PlanNode joinNode = NodeEditor.findParent(child, NodeConstants.Types.JOIN, NodeConstants.Types.SOURCE); while (joinNode != null) { if (joinNode.getGroups().containsAll(correlationGroups)) { if (joinNode == this) { result.add(references); } break; } joinNode = NodeEditor.findParent(joinNode, NodeConstants.Types.JOIN, NodeConstants.Types.SOURCE); } } return result; }
/** * Finds the closest project columns in the current frame */ static List<Expression> findTopCols(PlanNode node) { PlanNode project = NodeEditor.findNodePreOrder(node, NodeConstants.Types.PROJECT, NodeConstants.Types.SOURCE); if (project == null) { project = NodeEditor.findParent(node, NodeConstants.Types.PROJECT, NodeConstants.Types.SOURCE); } if (project != null) { return (List<Expression>)project.getProperty(NodeConstants.Info.PROJECT_COLS); } Assertion.failed("no top cols in frame"); //$NON-NLS-1$ return null; }
/** * Finds the closest project columns in the current frame */ static List<Expression> findTopCols(PlanNode node) { PlanNode project = NodeEditor.findNodePreOrder(node, NodeConstants.Types.PROJECT, NodeConstants.Types.SOURCE); if (project == null) { project = NodeEditor.findParent(node, NodeConstants.Types.PROJECT, NodeConstants.Types.SOURCE); } if (project != null) { return (List<Expression>)project.getProperty(NodeConstants.Info.PROJECT_COLS); } Assertion.failed("no top cols in frame"); //$NON-NLS-1$ return null; }
/** * Finds the closest project columns in the current frame */ static List<Expression> findTopCols(PlanNode node) { PlanNode project = NodeEditor.findNodePreOrder(node, NodeConstants.Types.PROJECT, NodeConstants.Types.SOURCE); if (project == null) { project = NodeEditor.findParent(node, NodeConstants.Types.PROJECT, NodeConstants.Types.SOURCE); } if (project != null) { return (List<Expression>)project.getProperty(NodeConstants.Info.PROJECT_COLS); } Assertion.failed("no top cols in frame"); //$NON-NLS-1$ return null; }
/** * Check to ensure that we are not projecting a subquery or null dependent expressions * @param parentProject2 */ private static boolean checkProjectedSymbols(PlanNode projectNode, GroupSymbol virtualGroup, PlanNode parentJoin, QueryMetadataInterface metadata, List<PlanNode> sources, boolean checkForNullDependent, PlanNode parentProject) { if (projectNode.hasBooleanProperty(Info.HAS_WINDOW_FUNCTIONS) && (parentProject.hasBooleanProperty(Info.HAS_WINDOW_FUNCTIONS) || NodeEditor.findParent(projectNode, NodeConstants.Types.PROJECT, NodeConstants.Types.SORT | NodeConstants.Types.GROUP | NodeConstants.Types.SELECT | NodeConstants.Types.JOIN) == null)) { //if there something above using the window function symbols, then we can move the projection return false; } List<Expression> selectSymbols = (List<Expression>)projectNode.getProperty(NodeConstants.Info.PROJECT_COLS); HashSet<GroupSymbol> groups = new HashSet<GroupSymbol>(); for (PlanNode sourceNode : sources) { groups.addAll(sourceNode.getGroups()); } return checkProjectedSymbols(virtualGroup, parentJoin, metadata, selectSymbols, groups, checkForNullDependent); }
/** * Check to ensure that we are not projecting a subquery or null dependent expressions * @param parentProject2 */ private static boolean checkProjectedSymbols(PlanNode projectNode, GroupSymbol virtualGroup, PlanNode parentJoin, QueryMetadataInterface metadata, List<PlanNode> sources, boolean checkForNullDependent, PlanNode parentProject) { if (projectNode.hasBooleanProperty(Info.HAS_WINDOW_FUNCTIONS) && (parentProject.hasBooleanProperty(Info.HAS_WINDOW_FUNCTIONS) || NodeEditor.findParent(projectNode, NodeConstants.Types.PROJECT, NodeConstants.Types.SORT | NodeConstants.Types.GROUP | NodeConstants.Types.SELECT | NodeConstants.Types.JOIN) == null)) { //if there something above using the window function symbols, then we can move the projection return false; } List<Expression> selectSymbols = (List<Expression>)projectNode.getProperty(NodeConstants.Info.PROJECT_COLS); HashSet<GroupSymbol> groups = new HashSet<GroupSymbol>(); for (PlanNode sourceNode : sources) { groups.addAll(sourceNode.getGroups()); } return checkProjectedSymbols(virtualGroup, parentJoin, metadata, selectSymbols, groups, checkForNullDependent); }
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 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 addLimit(RuleStack rules, PlanNode parent, QueryMetadataInterface metadata, CapabilitiesFinder capabilitiesFinder) throws QueryMetadataException, TeiidComponentException { PlanNode accessNode = NodeEditor.findParent(parent.getFirstChild(), NodeConstants.Types.ACCESS); if (accessNode != null) { Object mid = RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata); if (!CapabilitiesUtil.supports(Capability.ROW_LIMIT, mid, metadata, capabilitiesFinder)) { if (NodeEditor.findParent(parent, NodeConstants.Types.SET_OP | NodeConstants.Types.JOIN, NodeConstants.Types.ACCESS) != null) { return false; //access node is too high } parent = accessNode; } } PlanNode limit = NodeFactory.getNewNode(NodeConstants.Types.TUPLE_LIMIT); limit.setProperty(Info.MAX_TUPLE_LIMIT, new Constant(1)); if (!rules.contains(RuleConstants.PUSH_LIMIT)) { rules.push(RuleConstants.PUSH_LIMIT); } if (parent.getParent() == null) { if (parent.getType() == NodeConstants.Types.ACCESS) { return false; } parent = parent.getFirstChild(); } parent.addAsParent(limit); return true; }
public void testFindParent() { PlanNode node0 = NodeFactory.getNewNode(NodeConstants.Types.SOURCE); PlanNode node1 = NodeFactory.getNewNode(NodeConstants.Types.PROJECT); PlanNode node2 = NodeFactory.getNewNode(NodeConstants.Types.JOIN); PlanNode node3 = NodeFactory.getNewNode(NodeConstants.Types.ACCESS); PlanNode node4 = NodeFactory.getNewNode(NodeConstants.Types.ACCESS); node0.addLastChild(node1); node1.addLastChild(node2); node2.addLastChild(node3); node2.addLastChild(node4); assertEquals("Found wrong node", node1, NodeEditor.findParent(node4, NodeConstants.Types.PROJECT)); //$NON-NLS-1$ assertNull("Found wrong node", NodeEditor.findParent(node1, NodeConstants.Types.PROJECT)); //$NON-NLS-1$ assertNull("Found wrong node", NodeEditor.findParent(node4, NodeConstants.Types.PROJECT, NodeConstants.Types.JOIN|NodeConstants.Types.SELECT)); //$NON-NLS-1$ assertNull("Found wrong node", NodeEditor.findParent(node1, NodeConstants.Types.GROUP)); //$NON-NLS-1$ } }
private boolean addLimit(RuleStack rules, PlanNode parent, QueryMetadataInterface metadata, CapabilitiesFinder capabilitiesFinder) throws QueryMetadataException, TeiidComponentException { PlanNode accessNode = NodeEditor.findParent(parent.getFirstChild(), NodeConstants.Types.ACCESS); if (accessNode != null) { Object mid = RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata); if (!CapabilitiesUtil.supports(Capability.ROW_LIMIT, mid, metadata, capabilitiesFinder)) { if (NodeEditor.findParent(parent, NodeConstants.Types.SET_OP | NodeConstants.Types.JOIN, NodeConstants.Types.ACCESS) != null) { return false; //access node is too high } parent = accessNode; } } PlanNode limit = NodeFactory.getNewNode(NodeConstants.Types.TUPLE_LIMIT); limit.setProperty(Info.MAX_TUPLE_LIMIT, new Constant(1)); if (!rules.contains(RuleConstants.PUSH_LIMIT)) { rules.push(RuleConstants.PUSH_LIMIT); } if (parent.getParent() == null) { if (parent.getType() == NodeConstants.Types.ACCESS) { return false; } parent = parent.getFirstChild(); } parent.addAsParent(limit); return 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 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); }