Package org.voltdb.planner

Examples of org.voltdb.planner.PlanColumn


                        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


        assertEquals(1, dist_nodes.size());
        DistinctPlanNode dist_node = CollectionUtil.first(dist_nodes);
        assertNotNull(dist_node);
       
        int col_guid = dist_node.getDistinctColumnGuid();
        PlanColumn pc = PlannerContext.singleton().get(col_guid);
        assertNotNull(pc);
        assertEquals("OL_I_ID", pc.getDisplayName());
    }
View Full Code Here

    /** Updates intermediate table for column offsets **/
    public void updateIntermediateTblOffset(AbstractPlanNode node, final Map<String, Integer> intermediate_offset_tbl) {
        int offset_cnt = 0;
        intermediate_offset_tbl.clear();
        for (Integer col_guid : node.getOutputColumnGUIDs()) {
            PlanColumn plan_col = PlannerContext.singleton().get(col_guid);
            // TupleValueExpression tv_expr =
            // (TupleValueExpression)plan_col.getExpression();
            intermediate_offset_tbl.put(plan_col.getDisplayName(), offset_cnt);
            offset_cnt++;
        }
    }
View Full Code Here

    /** Updates intermediate table for column GUIDs **/
    public void updateIntermediateTblGUIDs(AbstractPlanNode node, final Map<String, Integer> intermediate_GUID_tbl) {
//        int offset_cnt = 0;
        intermediate_GUID_tbl.clear();
        for (Integer col_guid : node.getOutputColumnGUIDs()) {
            PlanColumn plan_col = PlannerContext.singleton().get(col_guid);
            // TupleValueExpression tv_expr =
            // (TupleValueExpression)plan_col.getExpression();
            intermediate_GUID_tbl.put(plan_col.getDisplayName(), plan_col.guid());
        }
    }
View Full Code Here

    public void checkTableOffsets(AbstractPlanNode node, final Map<String, Integer> tbl_map) {
        /** Aggregates **/
        if (node instanceof AggregatePlanNode) {
            /** check aggregate column offsets **/
            for (Integer col_guid : ((AggregatePlanNode) node).getAggregateColumnGuids()) {
                PlanColumn plan_col = PlannerContext.singleton().get(col_guid);
                assert (plan_col.getExpression().getExpressionType().equals(ExpressionType.VALUE_TUPLE)) : " plan column expression type is: " + plan_col.getExpression().getExpressionType()
                        + " NOT TupleValueExpression";
                TupleValueExpression tv_exp = (TupleValueExpression) plan_col.getExpression();
                checkColumnIndex(tv_exp, tbl_map);
            }
            /** check output column offsets **/
            for (Integer col_guid : ((AggregatePlanNode) node).getAggregateOutputColumns()) {
                PlanColumn plan_col = PlannerContext.singleton().get(col_guid);
                assert (plan_col.getExpression().getExpressionType().equals(ExpressionType.VALUE_TUPLE)) : " plan column expression type is: " + plan_col.getExpression().getExpressionType()
                        + " NOT TupleValueExpression";
                TupleValueExpression tv_exp = (TupleValueExpression) plan_col.getExpression();
                checkColumnIndex(tv_exp, tbl_map);
            }
            /** check group by column offsets **/
            for (Integer col_guid : ((AggregatePlanNode) node).getGroupByColumnOffsets()) {
                PlanColumn plan_col = PlannerContext.singleton().get(col_guid);
                assert (plan_col.getExpression().getExpressionType().equals(ExpressionType.VALUE_TUPLE)) : " plan column expression type is: " + plan_col.getExpression().getExpressionType()
                        + " NOT TupleValueExpression";
                TupleValueExpression tv_exp = (TupleValueExpression) plan_col.getExpression();
                checkColumnIndex(tv_exp, tbl_map);
            }
            /** Order By's **/
        } else if (node instanceof OrderByPlanNode) {

        } else {
            // check the offsets of the output column
            // Set<TupleValueExpression> ExpressionUtil.getExpressions(node,
            // TupleValueExpression.class);
            for (Integer col_guid : node.getOutputColumnGUIDs()) {
                PlanColumn plan_col = PlannerContext.singleton().get(col_guid);
                new ExpressionTreeWalker() {
                    @Override
                    protected void callback(AbstractExpression element) {
                        if (element.getClass().equals(TupleValueExpression.class)) {
                            assert (element.getExpressionType().equals(ExpressionType.VALUE_TUPLE)) : "plan column expression type is: " + element.getExpressionType() + " NOT TupleValueExpression";
                            TupleValueExpression tv_exp = (TupleValueExpression) element;
                            checkColumnIndex(tv_exp, tbl_map);
                        }
                        return;
                    }
                }.traverse(plan_col.getExpression());
            }
        }
    }
View Full Code Here

     * walk through the output columns of the current plan_node and compare the
     * GUIDs of the output columns of the child of the current plan_node
     **/
    public void checkNodeColumnGUIDs(AbstractPlanNode plan_node, Map<String, Integer> intermediate_GUID_tbl) {
        for (Integer orig_guid : plan_node.getOutputColumnGUIDs()) {
            PlanColumn orig_pc = PlannerContext.singleton().get(orig_guid);
            assertNotNull(orig_pc);
           
            // XXX boolean found = false;
            for (String int_name : intermediate_GUID_tbl.keySet()) {
                Integer new_guid = intermediate_GUID_tbl.get(int_name);
                if (orig_pc.getDisplayName().equals(int_name)) {
                    assertEquals(plan_node + " Column name: " + int_name + " guid id: " + orig_guid + " doesn't match guid from child: ",
                                 orig_guid, new_guid);
                }
            }
        }
View Full Code Here

                        Integer intermediate_tbl_offset = intermediate_offset_tbl.size();
                        for (Map.Entry<String, Integer> col : scan_node_map.entrySet()) {
                            intermediate_offset_tbl.put(col.getKey(), intermediate_tbl_offset + col.getValue());
                        }
                        for (Integer col_guid : scan_node.getOutputColumnGUIDs()) {
                            PlanColumn plan_col = PlannerContext.singleton().get(col_guid);
                            intermediate_GUID_tbl.put(plan_col.getDisplayName(), plan_col.guid());
                        }
                        // check that expression column offsets + output column
                        // offsets match + GUIDs match with the original target
                        // table
                        checkExpressionOffsets(scan_node, intermediate_offset_tbl);
                        checkTableOffsets(scan_node, intermediate_offset_tbl);
                        checkMatchInline(element, scan_node);
                        checkNodeColumnGUIDs(element, intermediate_GUID_tbl);
                    }
                    /** Projection Node **/
                    else if (element instanceof ProjectionPlanNode) {
                        // check that expression column offsets + output column
                        // offsets match + GUIDs match with the original target
                        // table
                        checkExpressionOffsets(element, intermediate_offset_tbl);
                        checkTableOffsets(element, intermediate_offset_tbl);
                        checkNodeColumnGUIDs(element, intermediate_offset_tbl);
                        // update intermediate table (offset + guids)
                        updateIntermediateTblOffset(element, intermediate_offset_tbl);
                        updateIntermediateTblGUIDs(element, intermediate_GUID_tbl);
                    } else if (element instanceof AggregatePlanNode) {
                        // only want to check the expression here because the
                        // output will be different for aggregates
                        checkExpressionOffsets(element, intermediate_offset_tbl);
                        // update intermediate table to reflect output of
                        // aggregates
                        updateIntermediateTblOffset(element, intermediate_offset_tbl);
                    } else if (element instanceof OrderByPlanNode) {
                        // check sort column GUIDs against the intermediate
                        // table
                        for (int order_node_guid : ((OrderByPlanNode) element).getSortColumnGuids()) {
                            PlanColumn order_node_pc = PlannerContext.singleton().get(order_node_guid);
                            int int_order_node_guid = -1;
                            int_order_node_guid = intermediate_GUID_tbl.get(order_node_pc.getDisplayName());
                            assert (int_order_node_guid != -1) : order_node_pc.getDisplayName() + " doesn't exist in intermediate table";
                            assert (order_node_guid == int_order_node_guid) : order_node_pc.getDisplayName() + " sort column guid: " + order_node_guid + " doesn't match: " + int_order_node_guid;
                        }
                        // only want to check the expression here because the
                        // output will be different for aggregates
                        checkExpressionOffsets(element, intermediate_offset_tbl);
                        // update intermediate table to reflect output of
View Full Code Here

       
        // Get the Limit nodes output columns and make sure their valid
        for (LimitPlanNode limit_node : limit_nodes) {
            assertNotNull(limit_node);
            for (int column_guid : limit_node.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());
                assertNotNull("Invalid PlanColumn [guid=" + column_guid + "]", column);
                assertEquals(column_guid, column.guid());
            } // FOR
        } // FOR
    }
View Full Code Here

        // Get the Limit nodes output columns and make sure their valid
        LimitPlanNode limit_node = CollectionUtil.first(limit_nodes);
        assertNotNull(limit_node);
        for (int column_guid : limit_node.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());
            assertNotNull("Invalid PlanColumn [guid=" + column_guid + "]", column);
            assertEquals(column_guid, column.guid());
        } // FOR

        // System.err.println(PlanNodeUtil.debug(root));
    }
View Full Code Here

        // Get the Limit nodes output columns and make sure their valid
        LimitPlanNode limit_node = CollectionUtil.first(limit_nodes);
        assertNotNull(limit_node);
        for (int column_guid : limit_node.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());
            assertNotNull("Invalid PlanColumn [guid=" + column_guid + "]", column);
            assertEquals(column_guid, column.guid());
        } // FOR

        // System.err.println(PlanNodeUtil.debug(root));
    }
View Full Code Here

TOP

Related Classes of org.voltdb.planner.PlanColumn

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.