Package org.voltdb.catalog

Examples of org.voltdb.catalog.Column


    public void addTablePartitionCandidate(Database catalog_db, String table_name, String column_name) {
        Table catalog_tbl = catalog_db.getTables().get(table_name);
        assert (catalog_tbl != null) : "Invalid table name '" + table_name + "'";

        Column catalog_col = null;
        if (column_name.equals(ReplicatedColumn.COLUMN_NAME)) {
            catalog_col = ReplicatedColumn.get(catalog_tbl);
        } else {
            catalog_col = catalog_tbl.getColumns().get(column_name);
        }
View Full Code Here


                    // Search Key Expressions
                    List<ColumnRef> index_cols = CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index");
                    for (int i = 0, cnt = cast_node.getSearchKeyExpressions().size(); i < cnt; i++) {
                        AbstractExpression index_exp = cast_node.getSearchKeyExpressions().get(i);
                        Column catalog_col = index_cols.get(i).getColumn();
                        if (debug.val)
                            LOG.debug("[" + i + "] " + catalog_col);
                        exps.add(CatalogUtil.createTempExpression(catalog_col, index_exp));
                        if (debug.val)
                            LOG.debug("Added temp index search key expression:\n" + ExpressionUtil.debug(exps.get(exps.size() - 1)));
                    } // FOR

                    // End Expression
                    if (cast_node.getEndExpression() != null) {
                        exps.add(cast_node.getEndExpression());
                        if (debug.val)
                            LOG.debug("Added scan end expression:\n" + ExpressionUtil.debug(exps.get(exps.size() - 1)));
                    }

                    // Post-Scan Expression
                    if (cast_node.getPredicate() != null) {
                        exps.add(cast_node.getPredicate());
                        if (debug.val)
                            LOG.debug("Added post-scan predicate:\n" + ExpressionUtil.debug(exps.get(exps.size() - 1)));
                    }

                    // SeqScanPlanNode
                } else if (node instanceof SeqScanPlanNode) {
                    SeqScanPlanNode cast_node = (SeqScanPlanNode) node;
                    if (cast_node.getPredicate() != null) {
                        exps.add(cast_node.getPredicate());
                        if (debug.val)
                            LOG.debug("Adding scan node predicate:\n" + ExpressionUtil.debug(exps.get(exps.size() - 1)));
                    }

                    // Materialize
                } else if (node instanceof MaterializePlanNode) {
                    // Assume that if we're here, then they want the mappings
                    // from columns to StmtParameters
                    assert (tables.size() == 1);
                    Table catalog_tbl = CollectionUtil.first(tables);
                    for (int ctr = 0, cnt = node.getOutputColumnGUIDs().size(); ctr < cnt; ctr++) {
                        int column_guid = node.getOutputColumnGUIDs().get(ctr);
                        PlanColumn column = PlannerContext.singleton().get(column_guid);
                        assert (column != null);

                        Column catalog_col = catalog_tbl.getColumns().get(column.getDisplayName());
                        assert (catalog_col != null) : "Invalid column name '" + column.getDisplayName() + "' for " + catalog_tbl;

                        AbstractExpression exp = column.getExpression();
                        if (exp instanceof ParameterValueExpression) {
                            StmtParameter catalog_param = catalog_stmt.getParameters().get(((ParameterValueExpression) exp).getParameterId());
View Full Code Here

            }
            m[0].put("columns", CatalogUtil.getDisplayNames(cols));
        }
        // COLUMN
        else if (catalog_obj instanceof Column) {
            Column catalog_col = (Column)catalog_obj;
            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;
View Full Code Here

                        //
                        // Make a temporary expression where COL = Expression
                        // Har har har! I'm so clever!
                        //
                        String column_name = (column.originColumnName() != null ? column.originColumnName() : column.getDisplayName());
                        Column catalog_col = catalog_tbl.getColumns().get(column_name);
                        if (catalog_col == null)
                            System.err.println(catalog_tbl + ": " + CatalogUtil.debug(catalog_tbl.getColumns()));
                        assert (catalog_col != null) : "Missing column '" + catalog_tbl.getName() + "." + column_name + "'";
                        AbstractExpression root_exp = CatalogUtil.createTempExpression(catalog_col, exp);
                        // System.out.println(ExpressionUtil.debug(root_exp));
View Full Code Here

                    new_catalog_tbl.setIsreplicated(true);
                    break;
                case HASH:
                case MAP:
                    new_catalog_tbl.setIsreplicated(false);
                    Column new_catalog_col = new_catalog_tbl.getColumns().get(entry.getAttribute().getName());
                    new_catalog_tbl.setPartitioncolumn(new_catalog_col);
                    break;
                default:
                    LOG.fatal("Unsupported partition type '" + entry.getMethod() + "'");
                    System.exit(1);
            } // SWITCH
        } // FOR

        //
        // Then add all our of our indexes
        //
        Map<Table, Integer> table_idxs = new HashMap<Table, Integer>();
        for (Table catalog_tbl : this.indexes.keySet()) {
            for (IndexPlan.Entry index : this.indexes.get(catalog_tbl)) {
                Table new_catalog_tbl = new_catalog_db.getTables().get(catalog_tbl.getName());
                if (!table_idxs.containsKey(new_catalog_tbl)) {
                    table_idxs.put(new_catalog_tbl, 0);
                }
                int idx = table_idxs.get(new_catalog_tbl);
                table_idxs.put(new_catalog_tbl, idx + 1);

                // TODO: Support different index types
                String idx_name = "IDX_" + new_catalog_tbl.getName() + "_DESIGNER_" + idx;
                Index new_catalog_index = catalog_tbl.getIndexes().add(idx_name);
                new_catalog_index.setType(IndexType.HASH_TABLE.getValue());

                // need to set other index data here (column, etc)
                for (int i = 0, cnt = index.getColumns().size(); i < cnt; i++) {
                    Column catalog_col = index.getColumns().get(i);
                    Column new_catalog_col = new_catalog_tbl.getColumns().get(catalog_col.getName());
                    ColumnRef cref = new_catalog_index.getColumns().add(new_catalog_col.getName());
                    cref.setColumn(new_catalog_col);
                    cref.setIndex(i);
                } // FOR
            } // FOR
        } // FOR
View Full Code Here

                    table_node.add(columns_node);
                    for (Column catalog_col : CatalogUtil.getSortedCatalogItems(catalog_tbl.getColumns(), "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 (super.toString() + " (" + type + ")");
                            }
                        });
                        columns_node.add(column_node);
                        buildSearchIndex(catalog_col, column_node);
                    } // FOR (columns)
                    // Indexes
                    if (!catalog_tbl.getIndexes().isEmpty()) {
                        DefaultMutableTreeNode indexes_node = new CatalogMapTreeNode(Index.class, "Indexes", catalog_tbl.getIndexes());
                        table_node.add(indexes_node);
                        for (Index catalog_idx : catalog_tbl.getIndexes()) {
                            DefaultMutableTreeNode index_node = new DefaultMutableTreeNode(new WrapperNode(catalog_idx));
                            indexes_node.add(index_node);
                            buildSearchIndex(catalog_idx, index_node);
                        } // FOR (indexes)
                    }
                    // Constraints
                    if (!catalog_tbl.getConstraints().isEmpty()) {
                        DefaultMutableTreeNode constraints_node = new CatalogMapTreeNode(Constraint.class, "Constraints", catalog_tbl.getConstraints());
                        table_node.add(constraints_node);
                        for (Constraint catalog_cnst : catalog_tbl.getConstraints()) { 
                            DefaultMutableTreeNode constraint_node = new DefaultMutableTreeNode(new WrapperNode(catalog_cnst));
                            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);
View Full Code Here

                    statement_node.add(columnRootNode);
                    for (Column column_cat : statement_cat.getOutput_columns()) {
                        DefaultMutableTreeNode column_node = new DefaultMutableTreeNode(new WrapperNode(column_cat) {
                            @Override
                            public String toString() {
                                Column column_cat = (Column)this.getCatalogType();
                                String type = VoltType.get((byte)column_cat.getType()).toSQLString();
                                return (super.toString() + " (" + type + ")");
                            }
                        });
                        columnRootNode.add(column_node);
                        buildSearchIndex(column_cat, column_node);
View Full Code Here

            tables++;
           
            // COLUMNS
            cols += t.getColumns().size();
            for (Column c : t.getColumns()) {
                Column fkey = CatalogUtil.getForeignKeyParent(c);
                if (fkey != null) fkeys++;
            }
           
            // INDEXES
            idx_total += t.getIndexes().size();
View Full Code Here

            // Replication
            // -------------------------------
            if (hints.force_replication.contains(table_key) || (calculate_memory && ts.readonly && hints.enable_replication_readonly && partition_ratio <= hints.force_replication_size_limit)) {
                total_partitionRatio += partition_ratio;
                total_partitionSize += ts.tuple_size_total;
                Column catalog_col = ReplicatedColumn.get(catalog_tbl);
                pentry = new TableEntry(PartitionMethodType.REPLICATION, catalog_col);
                if (debug.val)
                    LOG.debug(String.format("Replicating %s at all partitions [%s]", catalog_tbl.getName(), catalog_col.fullName()));

                // -------------------------------
                // Forced Selection
                // -------------------------------
            } else if (forced_columns.isEmpty() == false) {
                // Assume there is only one candidate
                assert (forced_columns.size() == 1) : "Unexpected number of forced columns: " + forced_columns;
                Column catalog_col = CollectionUtil.first(forced_columns);
                pentry = new TableEntry(PartitionMethodType.HASH, catalog_col);
                total_partitionRatio += partition_size / (double) hints.max_memory_per_partition;
                total_partitionSize += partition_size;
                if (debug.val)
                    LOG.debug(String.format("Forcing %s to be partitioned by specific column [%s]", catalog_tbl.getName(), catalog_col.fullName()));

                // -------------------------------
                // Select Most Popular
                // -------------------------------
            } else {
                // If there are no edges, then we'll just randomly pick a column
                // since it doesn't matter
                final Collection<DesignerEdge> edges = agraph.getIncidentEdges(v);
                if (edges.isEmpty())
                    continue;
                if (trace.val)
                    LOG.trace(catalog_tbl + " has " + edges.size() + " edges in AccessGraph");

                ObjectHistogram<Column> column_histogram = null;
                ObjectHistogram<Column> join_column_histogram = new ObjectHistogram<Column>();
                ObjectHistogram<Column> self_column_histogram = new ObjectHistogram<Column>();
                // Map<Column, Double> unsorted = new HashMap<Column, Double>();
                for (DesignerEdge e : edges) {
                    Collection<DesignerVertex> vertices = agraph.getIncidentVertices(e);
                    DesignerVertex v0 = CollectionUtil.get(vertices, 0);
                    DesignerVertex v1 = CollectionUtil.get(vertices, 1);
                    boolean self = (v0.equals(v) && v1.equals(v));
                    column_histogram = (self ? self_column_histogram : join_column_histogram);

                    double edge_weight = e.getTotalWeight();
                    PredicatePairs cset = e.getAttribute(AccessGraph.EdgeAttributes.COLUMNSET);
                    if (trace.val)
                        LOG.trace("Examining ColumnSet for " + e.toString(true));

                    Histogram<Column> cset_histogram = cset.buildHistogramForType(Column.class);
                    Collection<Column> columns = cset_histogram.values();
                    if (trace.val)
                        LOG.trace("Constructed Histogram for " + catalog_tbl + " from ColumnSet:\n"
                                + cset_histogram.setDebugLabels(CatalogUtil.getHistogramLabels(cset_histogram.values())).toString(100, 50));
                    for (Column catalog_col : columns) {
                        if (!catalog_col.getParent().equals(catalog_tbl))
                            continue;
                        if (catalog_col.getNullable())
                            continue;
                        long cnt = cset_histogram.get(catalog_col);
                        if (trace.val)
                            LOG.trace("Found Match: " + catalog_col.fullName() + " [cnt=" + cnt + "]");
                        column_histogram.put(catalog_col, Math.round(cnt * edge_weight));
                    } // FOR
                    // System.err.println(cset.debug());
                    // LOG.info("[" + e.getTotalWeight() + "]: " + cset);
                } // FOR

                // If there were no join columns, then use the self-reference
                // histogram
                column_histogram = (join_column_histogram.isEmpty() ? self_column_histogram : join_column_histogram);
                if (column_histogram.isEmpty()) {
                    EventObserver<DesignerVertex> observer = new EventObserver<DesignerVertex>() {
                        @Override
                        public void update(EventObservable<DesignerVertex> o, DesignerVertex v) {
                            for (DesignerEdge e : agraph.getIncidentEdges(v)) {
                                LOG.info(e.getAttribute(AccessGraph.EdgeAttributes.COLUMNSET));
                            }
                            LOG.info(StringUtil.repeat("-", 100));
                        }
                    };
                    LOG.info("Edges: " + edges);
                    GraphVisualizationPanel.createFrame(agraph, observer).setVisible(true);
                    // ThreadUtil.sleep(10000);
                }

                // We might not find anything if we are calculating the lower
                // bounds using only one transaction
                // if (column_histogram.isEmpty()) {
                // if (trace.val)
                // LOG.trace("Failed to find any ColumnSets for " +
                // catalog_tbl);
                // continue;
                // }
                assert (!column_histogram.isEmpty()) : "Failed to find any ColumnSets for " + catalog_tbl;
                if (trace.val)
                    LOG.trace("Column Histogram:\n" + column_histogram);

                Column catalog_col = CollectionUtil.first(column_histogram.getMaxCountValues());
                pentry = new TableEntry(PartitionMethodType.HASH, catalog_col, null, null);
                total_partitionRatio += partition_size / (double) hints.max_memory_per_partition;
                total_partitionSize += partition_size;

                if (debug.val)
                    LOG.debug(String.format("Selected %s's most popular column for partitioning [%s]", catalog_tbl.getName(), catalog_col.fullName()));
            }
            pplan.table_entries.put(catalog_tbl, pentry);

            if (debug.val)
                LOG.debug(String.format("Current Partition Size: %s", StringUtil.formatSize(total_partitionSize), StringUtil.formatSize(hints.max_memory_per_partition)));
            assert (total_partitionRatio <= 1) : String.format("Too much memory per partition: %s / %s", StringUtil.formatSize(total_partitionSize),
                    StringUtil.formatSize(hints.max_memory_per_partition));
        } // FOR

        for (Table catalog_tbl : info.catalogContext.database.getTables()) {
            if (pplan.getTableEntry(catalog_tbl) == null) {
                Column catalog_col = CollectionUtil.random(catalog_tbl.getColumns());
                assert (catalog_col != null) : "Failed to randomly pick column for " + catalog_tbl;
                pplan.table_entries.put(catalog_tbl, new TableEntry(PartitionMethodType.HASH, catalog_col, null, null));
                if (debug.val)
                    LOG.debug(String.format("No partitioning column selected for %s. Choosing a random attribute [%s]", catalog_tbl, catalog_col.fullName()));
            }
        } // FOR

        if (hints.enable_procparameter_search) {
            if (debug.val)
View Full Code Here

                Table catalog_tbl = CatalogKey.getFromKey(catalogContext.database, table_key, Table.class);
                if (catalog_tbl.getIsreplicated()) {
                    continue;
                }

                Column table_partition_col = catalog_tbl.getPartitioncolumn();
                PartitionSet partitions = e.getValue();

                // If there is more than one partition, then we'll never be multi-partition
                // so we can stop our search right here.
                if (partitions.size() > 1) {
                    if (trace.val)
                        LOG.trace(String.format("%s references %s's partitioning attribute %s on %d different partitions -- VALUES %s", catalog_proc.getName(), catalog_tbl.getName(),
                                table_partition_col.fullName(), partitions.size(), partitions));
                    txn_entry.singlesited = false;
                    break;

                // Make sure that the partitioning ProcParameter hashes to the same
                // site as the value used on the partitioning column for this table
View Full Code Here

TOP

Related Classes of org.voltdb.catalog.Column

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.