Examples of MaterializedViewInfo


Examples of org.voltdb.catalog.MaterializedViewInfo

                dest_tbl.setPartitioncolumn(dest_part_col);
            }
        // MaterializedViewInfo
        } else if (src_item instanceof MaterializedViewInfo) {
            // ColumnRefs
            MaterializedViewInfo src_view = (MaterializedViewInfo) src_item;
            MaterializedViewInfo dest_view = (MaterializedViewInfo) clone;
            updateColumnsRefs((Table) src_view.getParent(), src_view.getGroupbycols(), (Table) dest_view.getParent(), dest_view.getGroupbycols());

        // Index
        } else if (src_item instanceof Index) {
            // ColumnRefs
            Index src_idx = (Index) src_item;
View Full Code Here

Examples of org.voltdb.catalog.MaterializedViewInfo

            Collection<Constraint> consts = CatalogUtil.getConstraints(catalog_col.getConstraints());
            m[0].put("constraints", CatalogUtil.getDisplayNames(consts));
        }
        // MATERIALIZEDVIEWINFO
        else if (catalog_obj instanceof MaterializedViewInfo) {
            MaterializedViewInfo catalog_view = (MaterializedViewInfo)catalog_obj;
            Collection<ColumnRef> cols = catalog_view.getGroupbycols();
            m[0].put("groupbycols", CatalogUtil.debug(CatalogUtil.getColumns(cols)));
        }
        // PROCEDURE
        else if (catalog_obj instanceof Procedure) {
            Procedure catalog_proc = (Procedure)catalog_obj;
            Collection<Procedure> rwConflicts = ConflictSetUtil.getReadWriteConflicts(catalog_proc);
            Collection<Procedure> wwConflicts = ConflictSetUtil.getWriteWriteConflicts(catalog_proc);
           
            if (rwConflicts.size() > 0 || wwConflicts.size() > 0) {
                Map<String, Object> orig_m = m[0];
                m = (Map<String, Object>[])new Map[2];
                m[0] = orig_m;
               
                m[1] = new TreeMap<String, Object>();
                Collection<Procedure> conflicts[] = (Collection<Procedure>[])new Collection<?>[] {
                    rwConflicts,
                    wwConflicts
                };
                String labels[] = { "Read-Write", "Write-Write" };
               
                for (int i = 0; i < labels.length; i++) {
                    String value = "";
                   
                    Collection<Procedure> c = conflicts[i];
                    if (c.size() > 0) {
                        List<String> conflictLabels = new ArrayList<String>(CatalogUtil.getDisplayNames(rwConflicts));
                        Collections.sort(conflictLabels);
                        value = StringUtil.join("\n", conflictLabels);
                    } else {
                        value ="<NONE>";
                    }
                    m[1].put(labels[i] + " Conflicts", value + "\n");
                } // FOR
            }
        }
       
        StringBuilder sb = new StringBuilder(StringUtil.formatMaps(m));
       
        // DATABASE
        if (catalog_obj instanceof Database) {
            sb.append(StringUtil.SINGLE_LINE);
            sb.append(Encoder.hexDecodeToString(((Database)catalog_obj).getSchema()));
        }
        // PLANFRAGMENT
        else if (catalog_obj instanceof PlanFragment) {
            PlanFragment catalog_frgmt = (PlanFragment)catalog_obj;
            try {
                AbstractPlanNode node = PlanNodeUtil.getPlanNodeTreeForPlanFragment(catalog_frgmt);
                sb.append(StringUtil.SINGLE_LINE);
                sb.append(PlanNodeUtil.debug(node));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        // TABLE
        else if (catalog_obj instanceof Table) {
            sb.append(StringUtil.SINGLE_LINE);
            Table catalog_tbl = (Table)catalog_obj;
           
            // MATERIALIZED VIEW
            if (catalog_tbl.getMaterializer() != null) {
                Table parent = catalog_tbl.getMaterializer();
                MaterializedViewInfo catalog_view = parent.getViews().get(catalog_tbl.getName());
                assert(catalog_view != null) :
                    "Unexpected null MaterializedViewInfo '" + catalog_tbl.getName() + "'";
                sb.append(MaterializedViewInfo.class.getSimpleName()).append("\n");
                sb.append(this.getAttributesText(catalog_view));
               
                SQLFormatter f = new SQLFormatter(catalog_view.getSqltext());
                sb.append(StringUtil.SINGLE_LINE);
                sb.append("\n").append(f.format()).append("\n");
            } else {
                String schema = CatalogUtil.toSchema(catalog_tbl);
                sb.append("\n").append(schema).append("\n");
View Full Code Here

Examples of org.voltdb.catalog.MaterializedViewInfo

                            constraints_node.add(constraint_node);
                            buildSearchIndex(catalog_cnst, constraint_node);
                        } // FOR (constraints)
                    }
                    // Vertical Partitions
                    final MaterializedViewInfo catalog_vp = vertical_partitions.get(catalog_tbl);
                    if (catalog_vp != null) {
                        DefaultMutableTreeNode vp_node = new CatalogMapTreeNode(MaterializedViewInfo.class, "Vertical Partition", catalog_vp.getGroupbycols());
                        table_node.add(vp_node);
                        for (Column catalog_col : CatalogUtil.getSortedCatalogItems(CatalogUtil.getColumns(catalog_vp.getGroupbycols()), "index")) {
                            DefaultMutableTreeNode column_node = new DefaultMutableTreeNode(new WrapperNode(catalog_col) {
                                @Override
                                public String toString() {
                                    Column column_cat = (Column)this.getCatalogType();
                                    String type = VoltType.get((byte)column_cat.getType()).toSQLString();
                                    return (String.format("%s.%s (%s)", catalog_vp.getName(), super.toString(), type));
                                }
                            });
                            vp_node.add(column_node);
//                            buildSearchIndex(catalog_col, column_node);
                        } // FOR
View Full Code Here

Examples of org.voltdb.catalog.MaterializedViewInfo

     */
    public static Map<Table, MaterializedViewInfo> getVerticallyPartitionedTables(CatalogType catalog_obj) {
        Database catalog_db = CatalogUtil.getDatabase(catalog_obj);
        Map<Table, MaterializedViewInfo> ret = new HashMap<Table, MaterializedViewInfo>();
        for (Table catalog_tbl : catalog_db.getTables()) {
            MaterializedViewInfo catalog_view = CatalogUtil.getVerticalPartition(catalog_tbl);
            if (catalog_view != null)
                ret.put(catalog_tbl, catalog_view);
        } // FOR
        return (ret);
    }
View Full Code Here

Examples of org.voltdb.catalog.MaterializedViewInfo

                assertEquals(CatalogUtil.getDisplayName(clone_col), clone_tbl, (Table) clone_col.getParent());
                assertEquals(CatalogUtil.getDisplayName(clone_col), clone_tbl.hashCode(), clone_col.getParent().hashCode());
            } // FOR
            for (MaterializedViewInfo catalog_view : catalog_tbl.getViews()) {
                assert (catalog_view.getGroupbycols().size() > 0);
                MaterializedViewInfo clone_view = clone_tbl.getViews().get(catalog_view.getName());
                checkFields(MaterializedViewInfo.class, catalog_view, clone_view);
            } // FOR

        } // FOR
View Full Code Here

Examples of org.voltdb.catalog.MaterializedViewInfo

        if (debug.val) LOG.debug("Passing " + pfs.length + " sysproc fragments to executeSysProcPlanFragments()");
        results = executeSysProcPlanFragments(pfs, (int)DEP_aggregate);
       
        // Check whether this table has a vertical partition
        // If so, then we'll automatically blast out the data that it needs
        MaterializedViewInfo catalog_view = CatalogUtil.getVerticalPartition(catalog_tbl);
        if (debug.val)
            LOG.debug(String.format("%s - %s Vertical Partition: %s",
                      ts, catalog_tbl.getName(), catalog_view));
        if (catalog_view != null) {
            if (debug.val)
                LOG.debug(String.format("%s - Updating %s's vertical partition %s",
                          ts, catalog_tbl.getName(), catalog_view.getDest().getName()));
            executeSysProcPlanFragments(createVerticalPartitionPlan(ts, catalog_view, table), (int)DEP_aggregate);
        }
       
        return (results);
    }
View Full Code Here

Examples of org.voltdb.catalog.MaterializedViewInfo

            // throw an error if the view isn't withing voltdb's limited worldview
            checkViewMeetsSpec(destTable.getTypeName(), stmt);

            // create the materializedviewinfo catalog node for the source table
            Table srcTable = stmt.tableList.get(0);
            MaterializedViewInfo matviewinfo = srcTable.getViews().add(destTable.getTypeName());
            matviewinfo.setDest(destTable);
            matviewinfo.setSqltext(query);
            if (stmt.where == null)
                matviewinfo.setPredicate("");
            else {
                String hex = Encoder.hexEncode(stmt.where.toJSONString());
                matviewinfo.setPredicate(hex);
            }
            destTable.setMaterializer(srcTable);

            List<Column> srcColumnArray = CatalogUtil.getSortedCatalogItems(srcTable.getColumns(), "index");
            List<Column> destColumnArray = CatalogUtil.getSortedCatalogItems(destTable.getColumns(), "index");

            // add the group by columns from the src table
            for (int i = 0; i < stmt.groupByColumns.size(); i++) {
                ParsedSelectStmt.ParsedColInfo gbcol = stmt.groupByColumns.get(i);
                Column srcCol = srcColumnArray.get(gbcol.index);
                ColumnRef cref = matviewinfo.getGroupbycols().add(srcCol.getTypeName());
                // groupByColumns is iterating in order of groups. Store that grouping order
                // in the column ref index. When the catalog is serialized, it will, naturally,
                // scramble this order like a two year playing dominos, presenting the data
                // in a meaningless sequence.
                cref.setIndex(i);           // the column offset in the view's grouping order
View Full Code Here

Examples of org.voltdb.catalog.MaterializedViewInfo

                String msg = String.format("A materialized view (%s) can not be defined on another view (%s).",
                        viewName, srcTable.getTypeName());
                throw m_compiler.new VoltCompilerException(msg);
            }

            MaterializedViewInfo matviewinfo = srcTable.getViews().add(viewName);
            matviewinfo.setDest(destTable);
            AbstractExpression where = stmt.getSingleTableFilterExpression();
            if (where != null) {
                String hex = Encoder.hexEncode(where.toJSONString());
                matviewinfo.setPredicate(hex);
            } else {
                matviewinfo.setPredicate("");
            }
            destTable.setMaterializer(srcTable);

            List<Column> srcColumnArray = CatalogUtil.getSortedCatalogItems(srcTable.getColumns(), "index");
            List<Column> destColumnArray = CatalogUtil.getSortedCatalogItems(destTable.getColumns(), "index");
            List<AbstractExpression> groupbyExprs = null;

            if (stmt.hasComplexGroupby()) {
                groupbyExprs = new ArrayList<AbstractExpression>();
                for (ParsedColInfo col: stmt.m_groupByColumns) {
                    groupbyExprs.add(col.expression);
                }
                // Parse group by expressions to json string
                String groupbyExprsJson = null;
                try {
                    groupbyExprsJson = convertToJSONArray(groupbyExprs);
                } catch (JSONException e) {
                    throw m_compiler.new VoltCompilerException ("Unexpected error serializing non-column " +
                            "expressions for group by expressions: " + e.toString());
                }
                matviewinfo.setGroupbyexpressionsjson(groupbyExprsJson);

            } else {
                // add the group by columns from the src table
                for (int i = 0; i < stmt.m_groupByColumns.size(); i++) {
                    ParsedSelectStmt.ParsedColInfo gbcol = stmt.m_groupByColumns.get(i);
                    Column srcCol = srcColumnArray.get(gbcol.index);
                    ColumnRef cref = matviewinfo.getGroupbycols().add(srcCol.getTypeName());
                    // groupByColumns is iterating in order of groups. Store that grouping order
                    // in the column ref index. When the catalog is serialized, it will, naturally,
                    // scramble this order like a two year playing dominos, presenting the data
                    // in a meaningless sequence.
                    cref.setIndex(i);           // the column offset in the view's grouping order
                    cref.setColumn(srcCol);     // the source column from the base (non-view) table
                }

                // parse out the group by columns into the dest table
                for (int i = 0; i < stmt.m_groupByColumns.size(); i++) {
                    ParsedSelectStmt.ParsedColInfo col = stmt.m_displayColumns.get(i);
                    Column destColumn = destColumnArray.get(i);
                    processMaterializedViewColumn(matviewinfo, srcTable, destColumn,
                            ExpressionType.VALUE_TUPLE, (TupleValueExpression)col.expression);
                }
            }

            // Set up COUNT(*) column
            ParsedSelectStmt.ParsedColInfo countCol = stmt.m_displayColumns.get(stmt.m_groupByColumns.size());
            assert(countCol.expression.getExpressionType() == ExpressionType.AGGREGATE_COUNT_STAR);
            assert(countCol.expression.getLeft() == null);
            processMaterializedViewColumn(matviewinfo, srcTable,
                    destColumnArray.get(stmt.m_groupByColumns.size()),
                    ExpressionType.AGGREGATE_COUNT_STAR, null);

            // create an index and constraint for the table
            Index pkIndex = destTable.getIndexes().add(HSQLInterface.AUTO_GEN_MATVIEW_IDX);
            pkIndex.setType(IndexType.BALANCED_TREE.getValue());
            pkIndex.setUnique(true);
            // add the group by columns from the src table
            // assume index 1 throuh #grpByCols + 1 are the cols
            for (int i = 0; i < stmt.m_groupByColumns.size(); i++) {
                ColumnRef c = pkIndex.getColumns().add(String.valueOf(i));
                c.setColumn(destColumnArray.get(i));
                c.setIndex(i);
            }
            Constraint pkConstraint = destTable.getConstraints().add(HSQLInterface.AUTO_GEN_MATVIEW_CONST);
            pkConstraint.setType(ConstraintType.PRIMARY_KEY.getValue());
            pkConstraint.setIndex(pkIndex);

            // prepare info for aggregation columns.
            List<AbstractExpression> aggregationExprs = new ArrayList<AbstractExpression>();
            boolean hasAggregationExprs = false;
            boolean hasMinOrMaxAgg = false;
            ArrayList<AbstractExpression> minMaxAggs = new ArrayList<AbstractExpression>();
            for (int i = stmt.m_groupByColumns.size() + 1; i < stmt.m_displayColumns.size(); i++) {
                ParsedSelectStmt.ParsedColInfo col = stmt.m_displayColumns.get(i);
                AbstractExpression aggExpr = col.expression.getLeft();
                if (aggExpr.getExpressionType() != ExpressionType.VALUE_TUPLE) {
                    hasAggregationExprs = true;
                }
                aggregationExprs.add(aggExpr);
                if (col.expression.getExpressionType() ==  ExpressionType.AGGREGATE_MIN ||
                        col.expression.getExpressionType() == ExpressionType.AGGREGATE_MAX) {
                    hasMinOrMaxAgg = true;
                    minMaxAggs.add(aggExpr);
                }
            }

            // set Aggregation Expressions.
            if (hasAggregationExprs) {
                String aggregationExprsJson = null;
                try {
                    aggregationExprsJson = convertToJSONArray(aggregationExprs);
                } catch (JSONException e) {
                    throw m_compiler.new VoltCompilerException ("Unexpected error serializing non-column " +
                            "expressions for aggregation expressions: " + e.toString());
                }
                matviewinfo.setAggregationexpressionsjson(aggregationExprsJson);
            }

            if (hasMinOrMaxAgg) {
                // TODO: deal with minMaxAggs, i.e. if only one min/max agg, try to find the index
                // with group by cols followed by this agg col; if multiple min/max aggs, decide
                // what to do (probably the index on group by cols is the best choice)
                Index found = findBestMatchIndexForMatviewMinOrMax(matviewinfo, srcTable, groupbyExprs);
                if (found != null) {
                    matviewinfo.setIndexforminmax(found.getTypeName());
                } else {
                    matviewinfo.setIndexforminmax("");
                    m_compiler.addWarn("No index found to support min() / max() UPDATE and DELETE on Materialized View " +
                            matviewinfo.getTypeName() +
                            ", and a sequential scan might be issued when current min / max value is updated / deleted.");
                }
            } else {
                matviewinfo.setIndexforminmax("");
            }

            // parse out the aggregation columns into the dest table
            for (int i = stmt.m_groupByColumns.size() + 1; i < stmt.m_displayColumns.size(); i++) {
                ParsedSelectStmt.ParsedColInfo col = stmt.m_displayColumns.get(i);
View Full Code Here

Examples of org.voltdb.catalog.MaterializedViewInfo

        if (partitionCol == null) {
            return false;
        }

        int partitionColIndex = partitionCol.getIndex();
        MaterializedViewInfo mvInfo = srcTable.getViews().get(mvTableName);

        int numOfGroupByColumns;
        // Justify whether partition column is in group by column list or not
        String complexGroupbyJson = mvInfo.getGroupbyexpressionsjson();
        if (complexGroupbyJson.length() > 0) {
            List<AbstractExpression> mvComplexGroupbyCols = null;
            try {
                mvComplexGroupbyCols = AbstractExpression.fromJSONArrayString(complexGroupbyJson, null);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            numOfGroupByColumns = mvComplexGroupbyCols.size();

            for (AbstractExpression expr: mvComplexGroupbyCols) {
                if (expr instanceof TupleValueExpression) {
                    TupleValueExpression tve = (TupleValueExpression) expr;
                    if (tve.getColumnIndex() == partitionColIndex) {
                        // If group by columns contain partition column from source table.
                        // Then, query on MV table will have duplicates from each partition.
                        // There is no need to fix this case, so just return.
                        return false;
                    }
                }
            }
        } else {
            CatalogMap<ColumnRef> mvSimpleGroupbyCols = mvInfo.getGroupbycols();
            numOfGroupByColumns = mvSimpleGroupbyCols.size();

            for (ColumnRef colRef: mvSimpleGroupbyCols) {
                if (colRef.getColumn().getIndex() == partitionColIndex) {
                    // If group by columns contain partition column from source table.
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.