Package org.voltdb.plannodes

Examples of org.voltdb.plannodes.ProjectionPlanNode


        // 2011-07-20: Using the AbstractExpressions is the more accurate way of
        // getting the
        // Columns referenced in the output
        // If this is Scan that has an inline Projection, grab those too
        if ((node instanceof AbstractScanPlanNode) && node.getInlinePlanNode(PlanNodeType.PROJECTION) != null) {
            ProjectionPlanNode prj_node = node.getInlinePlanNode(PlanNodeType.PROJECTION);
            planColumnIds.addAll(prj_node.getOutputColumnGUIDs());
            if (debug.val)
                LOG.debug(prj_node.getPlanNodeType() + ": " + planColumnIds);
        } else {
            planColumnIds.addAll(node.getOutputColumnGUIDs());
            if (debug.val)
                LOG.debug(node.getPlanNodeType() + ": " + planColumnIds);
        }
View Full Code Here


                updateReferenceColumns(PlanNodeUtil.getUpdatedColumnsForPlanNode(catalog_db, scan_node), false, allCols, modifiedCols, readOnlyCols);

                // XXX: Why is this necessary?
                if (scan_node.getInlinePlanNodeCount() > 0) {
                    ProjectionPlanNode proj_node = scan_node.getInlinePlanNode(PlanNodeType.PROJECTION);
                    assert (proj_node != null);

                    // This is a bit tricky. We have to go by the names of the
                    // output columns to find what
                    // column is meant to be updated
                    PlannerContext pcontext = PlannerContext.singleton();
                    for (Integer col_guid : proj_node.getOutputColumnGUIDs()) {
                        PlanColumn pc = pcontext.get(col_guid);
                        assert (pc != null);
                        if (pc.getExpression() instanceof TupleAddressExpression)
                            continue;
View Full Code Here

            for (AbstractScanPlanNode scan_node : scan_nodes) {
                List<PlanColumn> output_cols = new ArrayList<PlanColumn>();
                List<AbstractExpression> output_exps = new ArrayList<AbstractExpression>();
                if (scan_node.getOutputColumnGUIDs().isEmpty()) {
                    if (scan_node.getInlinePlanNode(PlanNodeType.PROJECTION) != null) {
                        ProjectionPlanNode proj_node = (ProjectionPlanNode) scan_node.getInlinePlanNode(PlanNodeType.PROJECTION);
                        for (int guid : proj_node.getOutputColumnGUIDs()) {
                            PlanColumn column = PlannerContext.singleton().get(guid);
                            assert (column != null);
                            output_cols.add(column);
                            output_exps.add(column.getExpression());
                        } // FOR
View Full Code Here

                return (false);
            }
        }

        // Now create a new ProjectionPlanNode that outputs just those columns
        ProjectionPlanNode proj_node = new ProjectionPlanNode(state.plannerContext, PlanAssembler.getNextPlanNodeId());
        this.populateProjectionPlanNode(node, proj_node, new_output_cols);

        // Add a projection above this node
        // TODO: Add the ability to automatically check whether we can make
        // something inline
        if (inline) {
            // Add projection inline to scan node
            node.addInlinePlanNode(proj_node);
            assert (proj_node.isInline());

            // Then make sure that we update it's output columns to match the
            // inline output
            node.getOutputColumnGUIDs().clear();
            node.getOutputColumnGUIDs().addAll(proj_node.getOutputColumnGUIDs());
        } else {
            AbstractPlanNode parent = node.getParent(0);
            assert (parent != null);
            node.clearParents();
            parent.clearChildren();
            proj_node.addAndLinkChild(node);
            parent.addAndLinkChild(proj_node);
        }

        // Mark the new ProjectionPlanNode as dirty
        state.markDirty(proj_node);
        state.markDirty(node);

        if (debug.val)
            LOG.debug(String.format("PLANOPT - Added %s%s with %d columns for node %s", (inline ? "inline " : ""), proj_node, proj_node.getOutputColumnGUIDCount(), node));

        return (true);
    }
View Full Code Here

                // same order that are straight TupleValueExpression, then we
                // know that we're just dumping out the table, so therefore we don't
                // need the projection at all!
                if (element instanceof AbstractScanPlanNode) {
                    AbstractScanPlanNode scan_node = (AbstractScanPlanNode) element;
                    ProjectionPlanNode proj_node = element.getInlinePlanNode(PlanNodeType.PROJECTION);
                    if (proj_node == null) {
                        if (debug.val)
                            LOG.debug("SKIP - " + element + " does not an inline ProjectionPlanNode");
                        return;
                    }

                    String table_name = scan_node.getTargetTableName();
                    Table catalog_tbl = state.catalog_db.getTables().get(table_name);
                    assert (catalog_tbl != null) : "Unexpected table '" + table_name + "'";
                    if (catalog_tbl.getColumns().size() != proj_node.getOutputColumnGUIDCount()) {
                        if (debug.val)
                            LOG.debug("SKIP - Inline " + proj_node + " does not have the same number of output columns as " + catalog_tbl);
                        return;
                    }

                    for (int i = 0, cnt = catalog_tbl.getColumns().size(); i < cnt; i++) {
                        int col_guid = proj_node.getOutputColumnGUID(i);
                        PlanColumn plan_col = state.plannerContext.get(col_guid);
                        assert (plan_col != null);

                        AbstractExpression col_exp = plan_col.getExpression();
                        assert (col_exp != null);
                        if ((col_exp instanceof TupleValueExpression) == false) {
                            if (debug.val)
                                LOG.debug("SKIP - Inline " + proj_node + " does not have a TupleValueExpression for output column #" + i);
                            return;
                        }

                        Collection<Column> columns = ExpressionUtil.getReferencedColumns(state.catalog_db, col_exp);
                        assert (columns.size() == 1);
                        Column catalog_col = CollectionUtil.first(columns);
                        if (catalog_col.getIndex() != i) {
                            return;
                        }
                    } // FOR

                    // If we're here, the new know that we can remove the
                    // projection
                    scan_node.removeInlinePlanNode(PlanNodeType.PROJECTION);
                    modified.set(true);

                    if (debug.val)
                        LOG.debug(String.format("PLANOPT - Removed redundant %s from %s\n%s", proj_node, scan_node, PlanNodeUtil.debug(rootNode)));
                }

                // CASE #2
                // We are ProjectionPlanNode that references the same columns as one
                // further below. That means we are unnecessary and can be removed!
                if (element instanceof ProjectionPlanNode) {
                    // Find the first ProjectionPlanNode below us
                    ProjectionPlanNode next_proj = getFirstProjection(element);
                    assert (next_proj == null || next_proj != element);
                    if (next_proj == null) {
                        if (debug.val)
                            LOG.debug("SKIP - No other Projection found below " + element);
                        return;
                    }
                    // They must at least have the same number of output columns
                    else if (element.getOutputColumnGUIDCount() != next_proj.getOutputColumnGUIDCount()) {
                        if (debug.val)
                            LOG.debug(String.format("SKIP - %s and %s do not have the same number of output columns", element, next_proj));
                        return;
                    }
                   
                    // There can't be a JOIN PlanNode in between us, since that may mean we need
                    // to prune out the colums at the bottom scan node
                    Collection<AbstractJoinPlanNode> join_nodes = PlanNodeUtil.getPlanNodes(element, AbstractJoinPlanNode.class);
                    if (debug.val) LOG.debug(String.format("%s has %d join nodes below it: %s",
                                                             element, join_nodes.size(), join_nodes));
                    if (join_nodes.isEmpty() == false) {
                        // Check to see whether the joins appear *after* the projection node
                        int elementDepth = PlanNodeUtil.getDepth(rootNode, element);
                        int nextDepth = PlanNodeUtil.getDepth(rootNode, next_proj);
                        assert(elementDepth < nextDepth) :
                            String.format("%s %d < %s %d", element, elementDepth, next_proj, nextDepth);
                        for (AbstractJoinPlanNode join_node : join_nodes) {
                            int joinDepth = PlanNodeUtil.getDepth(rootNode, join_node);
                            assert(elementDepth < joinDepth);
                            assert(nextDepth != joinDepth);
                            if (joinDepth < nextDepth) {
                                if (debug.val)
                                    LOG.debug(String.format("SKIP - %s has %s that comes after %s", element, join_node, next_proj));
                                return;
                            }
                        } // FOR
                    }
                   
                   
                    // Check whether we have the same output columns
                    List<PlanColumn> elementColumns = new ArrayList<PlanColumn>();
                    for (Integer guid : element.getOutputColumnGUIDs()) {
                        PlanColumn pc = state.plannerContext.get(guid);
                        assert(pc != null);
                        elementColumns.add(pc);
                    } // FOR
                    boolean match = true;
                    int idx = 0;
                    for (Integer guid : next_proj.getOutputColumnGUIDs()) {
                        PlanColumn pc = state.plannerContext.get(guid);
                        assert(pc != null);
                        if (elementColumns.get(idx).equals(pc, true, true) == false) {
                            match = false;
                            break;
View Full Code Here

        assert (this.new_root != null);
        return (Pair.of(modified.get(), this.new_root));
    }

    private ProjectionPlanNode getFirstProjection(final AbstractPlanNode root) {
        final ProjectionPlanNode proj_node[] = { null };
        new PlanNodeTreeWalker(true) {
            @Override
            protected void callback(AbstractPlanNode element) {
                if (element != root && element instanceof ProjectionPlanNode) {
                    proj_node[0] = (ProjectionPlanNode) element;
View Full Code Here

        assertFalse(col_offset_xref.isEmpty());
        assertEquals(catalog_tbl.getName(), scan_node.getTargetTableName());
       
        // The inline projection in the leaf ScanPlanNode should only output a
        // single column (S_I_ID), since this is the only column used in the JOIN
        ProjectionPlanNode proj_node = scan_node.getInlinePlanNode(PlanNodeType.PROJECTION);
        assertNotNull(proj_node);
        assertEquals(1, proj_node.getOutputColumnGUIDCount());
       
        System.err.println(PlanNodeUtil.debug(scan_node));
        checkExpressionOffsets(proj_node, col_offset_xref);
       
    }
View Full Code Here

    /**
     * testGetPlanNodes
     */
    public void testGetPlanNodes() throws Exception {
        PlannerContext cntxt = new PlannerContext();
        AbstractPlanNode root_node = new ProjectionPlanNode(cntxt, 1);
        root_node.addAndLinkChild(new SeqScanPlanNode(cntxt, 2));
       
        Collection<SeqScanPlanNode> found0 = PlanNodeUtil.getPlanNodes(root_node, SeqScanPlanNode.class);
        assertFalse(found0.isEmpty());
       
        Collection<AbstractScanPlanNode> found1 = PlanNodeUtil.getPlanNodes(root_node, AbstractScanPlanNode.class);
View Full Code Here

        AbstractScanPlanNode scan_node = CollectionUtil.first(scan_nodes);
        assertNotNull(scan_node);
        assertEquals(1, scan_node.getInlinePlanNodes().size());

        // Get the Projection and make sure it has valid output columns
        ProjectionPlanNode inline_proj = (ProjectionPlanNode) scan_node.getInlinePlanNodes().get(PlanNodeType.PROJECTION);
        assertNotNull(inline_proj);
        for (int column_guid : inline_proj.getOutputColumnGUIDs()) {
            PlanColumn column = PlannerContext.singleton().get(column_guid);
            // System.err.println(String.format("[%02d] %s", column_guid,
            // column));
            // System.err.println("==================");
            // System.err.println(PlannerContext.singleton().debug());
View Full Code Here

        AbstractScanPlanNode scan_node = CollectionUtil.first(scan_nodes);
        assertNotNull(scan_node);
        Table catalog_tbl = this.getTable(scan_node.getTargetTableName());

        assertEquals(1, scan_node.getInlinePlanNodes().size());
        ProjectionPlanNode inline_proj = (ProjectionPlanNode) scan_node.getInlinePlanNodes().get(PlanNodeType.PROJECTION);
        assertNotNull(inline_proj);

        // Validate output columns
        for (int column_guid : inline_proj.getOutputColumnGUIDs()) {
            PlanColumn column = PlannerContext.singleton().get(column_guid);
            assertNotNull("Missing PlanColumn [guid=" + column_guid + "]", column);
            assertEquals(column_guid, column.guid());

            // Check that only columns from the scanned table are there
View Full Code Here

TOP

Related Classes of org.voltdb.plannodes.ProjectionPlanNode

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.