Package org.jboss.dna.graph.query.plan

Examples of org.jboss.dna.graph.query.plan.PlanNode


     * @return true if all nodes between the criteria and originating nodes are SELECT nodes
     */
    protected boolean atBoundary( PlanNode criteriaNode,
                                  PlanNode originatingNode ) {
        // Walk from source node to critNode to check each intervening node
        PlanNode currentNode = originatingNode.getParent();
        while (currentNode != criteriaNode) {
            if (currentNode.getType() != Type.SELECT) return false;
            currentNode = currentNode.getParent();
        }
        return true;
    }
View Full Code Here


                SelectorName selector2 = equiJoinCondition.getSelector2Name();
                String property1 = equiJoinCondition.getProperty1Name();
                String property2 = equiJoinCondition.getProperty2Name();

                // Walk up the tree looking for SELECT nodes that apply to one of the sides ...
                PlanNode node = join.getParent();
                while (node != null) {
                    if (!copiedSelectNodes.contains(node)) {
                        PlanNode copy = copySelectNode(context, node, selector1, property1, selector2, property2);
                        if (copy != null) {
                            node.insertAsParent(copy);
                            copiedSelectNodes.add(node);
                            copiedSelectNodes.add(copy);
                        } else {
                            copy = copySelectNode(context, node, selector2, property2, selector1, property1);
                            if (copy != null) {
                                node.insertAsParent(copy);
                                copiedSelectNodes.add(node);
                                copiedSelectNodes.add(copy);
                            }
                        }
                    }
                    node = node.getParent();
                }
            }

            if (joinCondition instanceof EquiJoinCondition || joinCondition instanceof SameNodeJoinCondition) {
                // Then for each side of the join ...
                PlanNode left = join.getFirstChild();
                PlanNode right = join.getLastChild();
                copySelectNodes(context, left, right);
                copySelectNodes(context, right, left);
            }
        }
        return plan;
View Full Code Here

        Set<SelectorName> toSelectors = new HashSet<SelectorName>();
        for (PlanNode toNode : toJoined.findAllAtOrBelow()) {
            toSelectors.addAll(toNode.getSelectors());
        }

        PlanNode nodeBelowSelects = null;

        // Walk down the 'fromJoined' side looking for all SELECT nodes ...
        for (PlanNode select : fromJoined.findAllAtOrBelow(Type.SELECT)) {
            // If all of the SELECT's selectors are also found on the right ...
            if (toSelectors.containsAll(select.getSelectors())) {
                // Copy the criteria ...
                PlanNode copy = new PlanNode(Type.SELECT, select.getSelectors());
                copy.setProperty(Property.SELECT_CRITERIA, select.getProperty(Property.SELECT_CRITERIA));

                if (nodeBelowSelects == null) {
                    nodeBelowSelects = toJoined.findAtOrBelow(Type.SOURCE, Type.JOIN, Type.SET_OPERATION, Type.NULL);
                    if (nodeBelowSelects == null) {
                        nodeBelowSelects = toJoined;
View Full Code Here

        // We know that this constraint ONLY applies to the referenced selector and property,
        // so we will duplicate this constraint ...

        // Create the new node ...
        PlanNode copy = new PlanNode(Type.SELECT, copySelectorName);

        // Copy the constraint, but change the references to the copy selector and property ...
        PlanUtil.ColumnMapping mappings = new PlanUtil.ColumnMapping(selectorName);
        mappings.map(propertyName, new Column(copySelectorName, copyPropertyName, copyPropertyName));
        Constraint newCriteria = PlanUtil.replaceReferences(context, constraint, mappings, copy);
        copy.setProperty(Property.SELECT_CRITERIA, newCriteria);

        return copy;
    }
View Full Code Here

                             LinkedList<OptimizerRule> ruleStack ) {

        // Find all of the ACCESS nodes to make sure there is a PROJECT ...
        for (PlanNode access : plan.findAllAtOrBelow(Type.ACCESS)) {
            // Find the first node that is below any LIMIT, SORT, or DUP_REMOVE ...
            PlanNode parentOfProject = access;
            while (parentOfProject.isOneOf(Type.LIMIT, Type.SORT, Type.DUP_REMOVE)) {
                parentOfProject = parentOfProject.getParent();
            }

            // Is there already a PROJECT here ?
            assert parentOfProject.getChildCount() == 1; // should only have one child ...
            PlanNode child = parentOfProject.getFirstChild(); // should only have one child ...
            if (child.is(Type.PROJECT)) {
                // Check to see if there is a PROJECT above the access node ...
                PlanNode accessParent = access.getParent();
                if (accessParent == null || accessParent.isNot(Type.PROJECT)) continue;
                // Otherwise, the parent is a PROJECT, but there is another PROJECT above the ACCESS node.
                // Remove the lower PROJECT so the next code block moves the top PROJECT down below the ACCESS node ...
                assert accessParent.is(Type.PROJECT);
                child.extractFromParent();
                child = parentOfProject.getFirstChild();
            }

            // If the parent of the ACCESS node is a PROJECT, then we can simply move it to here ...
            PlanNode accessParent = access.getParent();
            if (accessParent != null && accessParent.is(Type.PROJECT)) {
                PlanNode project = accessParent;
                if (project == plan) {
                    // The PROJECT node is the root, so the ACCESS node will be the root ...
                    plan = access;
                    access.removeFromParent();
                } else {
                    project.extractFromParent();
                }
                child.insertAsParent(project);
                if (plan == access) return plan;

                // We need to make sure we have all of the columns needed for any ancestor ...
                List<Column> requiredColumns = PlanUtil.findRequiredColumns(context, project);
                project.setProperty(Property.PROJECT_COLUMNS, requiredColumns);
                project.addSelectors(getSelectorsFor(requiredColumns));
                continue;
            }

            // There is no PROJECT, so find the columns that are required by the plan above this point ...
            List<Column> requiredColumns = PlanUtil.findRequiredColumns(context, child);

            // And insert the PROJECT ...
            PlanNode projectNode = new PlanNode(Type.PROJECT);
            projectNode.setProperty(Property.PROJECT_COLUMNS, requiredColumns);
            projectNode.addSelectors(getSelectorsFor(requiredColumns));
            child.insertAsParent(projectNode);
        }
        return plan;
    }
View Full Code Here

        for (PlanNode source : plan.findAllAtOrBelow(Type.SOURCE)) {
            // The source node may have children if it is a view ...
            if (source.getChildCount() != 0) continue;

            // Create the ACCESS node, set the selectors, and insert above the source node ...
            PlanNode access = new PlanNode(Type.ACCESS);
            access.addSelectors(source.getSelectors());
            source.insertAsParent(access);
        }
        return plan;
    }
View Full Code Here

                        foundNoResults = true;
                        break; // don't do anything else under this access node
                    }
                    if (merged != null) {
                        // Add a SELECT node for the new merged constraint ...
                        PlanNode newSelect = new PlanNode(Type.SELECT);
                        newSelect.getSelectors().addAll(selectors);
                        newSelect.setProperty(Property.SELECT_CRITERIA, merged);

                        // And insert the SELECT node into the tree (just below the ACCESS, we'll rerun pushdown selects) ...
                        assert access.getChildCount() == 1;
                        access.getFirstChild().insertAsParent(newSelect);
                        rewritten = true;
                    }

                    // Remove any of the SELECT nodes that were not needed (this can happen if the constraints are not needed) ...
                    Iterator<PlanNode> nodeIter = selectNodes.iterator();
                    Iterator<Comparison> constraintIter = rangeConstraints.iterator();
                    while (nodeIter.hasNext()) {
                        assert constraintIter.hasNext();
                        PlanNode node = nodeIter.next();
                        Comparison comparison = constraintIter.next();
                        if (comparison == null) {
                            // This comparison was rewritten, so remove the PlanNode ...
                            node.extractFromParent();
                            nodeIter.remove();
                        }
                    }
                    assert !constraintIter.hasNext();
                }
View Full Code Here

        CheckArg.isNotNull(context, "context");
        CheckArg.isNotNull(query, "query");

        // Create the canonical plan ...
        long start = System.nanoTime();
        PlanNode plan = planner.createPlan(context, query);
        long duration = System.nanoTime() - start;
        Statistics stats = new Statistics(duration);

        QueryResultColumns resultColumns = QueryResultColumns.empty();
        if (!context.getProblems().hasErrors()) {
            // Optimize the plan ...
            start = System.nanoTime();
            PlanNode optimizedPlan = optimizer.optimize(context, plan);
            duration = System.nanoTime() - start;
            stats = stats.withOptimizationTime(duration);

            // Find the query result columns ...
            start = System.nanoTime();
View Full Code Here

    }

    protected QueryResultColumns determineQueryResultColumns( PlanNode optimizedPlan,
                                                              PlanHints hints ) {
        // Look for which columns to include in the results; this will be defined by the highest PROJECT node ...
        PlanNode project = optimizedPlan.findAtOrBelow(Traversal.LEVEL_ORDER, Type.PROJECT);
        if (project != null) {
            List<Column> columns = project.getPropertyAsList(Property.PROJECT_COLUMNS, Column.class);
            // Determine whether to include the full-text search scores in the results ...
            boolean includeFullTextSearchScores = hints.hasFullTextSearch;
            if (!includeFullTextSearchScores) {
                for (PlanNode select : optimizedPlan.findAllAtOrBelow(Type.SELECT)) {
                    Constraint constraint = select.getProperty(Property.SELECT_CRITERIA, Constraint.class);
View Full Code Here

                Set<SelectorName> rightSelectors = joinNode.getLastChild().getSelectors();
                List<Object> leftSortBy = new LinkedList<Object>();
                List<Object> rightSortBy = new LinkedList<Object>();
                createOrderBysForJoinCondition(condition, leftSelectors, leftSortBy, rightSelectors, rightSortBy);

                PlanNode leftSort = new PlanNode(Type.SORT, leftSelectors);
                leftSort.setProperty(Property.SORT_ORDER_BY, leftSortBy);
                joinNode.getFirstChild().insertAsParent(leftSort);
                if (joinNode.getFirstChild().findAllAtOrBelow(Type.DUP_REMOVE).isEmpty()) {
                    // There is no duplicate removal below the left-hand side of the join, so insert it ...
                    PlanNode leftDupRemoval = new PlanNode(Type.DUP_REMOVE, leftSelectors);
                    joinNode.getFirstChild().insertAsParent(leftDupRemoval);
                }

                // There is no sort below the right-hand side of the join, so insert it ...
                PlanNode rightSort = new PlanNode(Type.SORT, rightSelectors);
                rightSort.setProperty(Property.SORT_ORDER_BY, rightSortBy);
                joinNode.getLastChild().insertAsParent(rightSort);
                if (joinNode.getLastChild().findAllAtOrBelow(Type.DUP_REMOVE).isEmpty()) {
                    // There is no duplicate removal below the right-hand side of the join, so insert it ...
                    PlanNode rightDupRemoval = new PlanNode(Type.DUP_REMOVE, rightSelectors);
                    joinNode.getLastChild().insertAsParent(rightDupRemoval);
                }
            }
        }
        return plan;
View Full Code Here

TOP

Related Classes of org.jboss.dna.graph.query.plan.PlanNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.