Package org.voltdb.catalog

Examples of org.voltdb.catalog.Table


                // System.out.println(query + "\n" + query_cost + "\n");
                //
                // For each table, get the values used for the partition keys
                //
                for (String table_key : query_cost.getTableKeys()) {
                    Table catalog_tbl = CatalogKey.getFromKey(info.catalogContext.database, table_key, Table.class);
                    assert (catalog_tbl != null);
                    Table root = pplan.getRoot(catalog_tbl);
                    assert (root != null);

                    // for (Object value : query_cost.getPartitions(table_key))
                    // {
                    // int hash = hasher.hash(value, catalog_tbl);
View Full Code Here


        return null;
    }

    public FragmentAffinity getFragmentAffinity(Table root0, Table root1) {
        if (root0.compareTo(root1) > 0) {
            Table temp = root0;
            root0 = root1;
            root1 = temp;
        }
        Pair<Table, Table> pair = new Pair<Table, Table>(root0, root1);
        // System.out.println("MY PAIR: " + pair + " [" + pair.hashCode() +
View Full Code Here

                    }
                }
                if (!found) {
                    switch (const_type) {
                        case FOREIGN_KEY: {
                            Table catalog_fkey_tbl = catalog_const.getForeignkeytable();
                            Column catalog_fkey_col = null;
                            for (ColumnRef ref : catalog_const.getForeignkeycols()) {
                                catalog_fkey_col = ref.getColumn();
                                break; // Nasty hack to get first item
                            }

                            assert(catalog_fkey_col != null);
                            ret += " REFERENCES " + catalog_fkey_tbl.getTypeName() + " (" + catalog_fkey_col.getTypeName() + ")";
                            skip_constraints.add(catalog_const);
                            break;
                        }
                        default:
                            // Nothing for now
                    }
                }
            }

            add = ",\n";
        }

        // Constraints
        for (Constraint catalog_const : catalog_tbl.getConstraints()) {
            if (skip_constraints.contains(catalog_const)) continue;
            ConstraintType const_type = ConstraintType.get(catalog_const.getType());
            if (const_type == ConstraintType.FOREIGN_KEY && include_fkeys == false) continue;

            // Primary Keys / Unique Constraints
            if (const_type == ConstraintType.PRIMARY_KEY || const_type == ConstraintType.UNIQUE) {
                Index catalog_idx = catalog_const.getIndex();
                IndexType idx_type = IndexType.get(catalog_idx.getType());
                String idx_suffix = idx_type.getSQLSuffix();

                ret += add + spacer +
                       (!idx_suffix.isEmpty() ? "CONSTRAINT " + catalog_const.getTypeName() + " " : "") +
                       (const_type == ConstraintType.PRIMARY_KEY ? "PRIMARY KEY" : "UNIQUE") + " (";

                String col_add = "";
                for (ColumnRef catalog_colref : CatalogUtil.getSortedCatalogItems(catalog_idx.getColumns(), "index")) {
                    ret += col_add + catalog_colref.getColumn().getTypeName();
                    col_add = ", ";
                } // FOR
                ret += ")";
                skip_indexes.add(catalog_idx);

            // Foreign Key
            } else if (const_type == ConstraintType.FOREIGN_KEY) {
                Table catalog_fkey_tbl = catalog_const.getForeignkeytable();
                String col_add = "";
                String our_columns = "";
                String fkey_columns = "";
                for (ColumnRef catalog_colref : catalog_const.getForeignkeycols()) {
                    // The name of the ColumnRef is the column in our base table
                    Column our_column = catalog_tbl.getColumns().getIgnoreCase(catalog_colref.getTypeName());
                    assert(our_column != null);
                    our_columns += col_add + our_column.getTypeName();

                    Column fkey_column = catalog_colref.getColumn();
                    assert(fkey_column != null);
                    fkey_columns += col_add + fkey_column.getTypeName();

                    col_add = ", ";
                }
                ret += add + spacer + "CONSTRAINT " + catalog_const.getTypeName() + " " +
                                      "FOREIGN KEY (" + our_columns + ") " +
                                      "REFERENCES " + catalog_fkey_tbl.getTypeName() + " (" + fkey_columns + ")";
            }
            skip_constraints.add(catalog_const);
        }
        ret += "\n);\n";
View Full Code Here

                this.stats = new WorkloadStatistics(this.stats_catalog_db);
                for (Table catalog_tbl : this.stats_catalog_db.getTables()) {
                    this.stats.getTableStatistics(catalog_tbl).preprocess(this.stats_catalog_db);
                } // FOR
            }
            final Table catalog_tbl = CatalogUtil.getCatalogTable(stats_catalog_db, voltTable);
            if (catalog_tbl == null) {
                LOG.fatal("Failed to find corresponding table catalog object for parameter " + ctr + " in " + catalog_proc);
                String msg = "Table Columns: ";
                for (int i = 0, cnt = voltTable.getColumnCount(); i < cnt; i++) {
                    msg += voltTable.getColumnName(i) + " ";
                }
                LOG.fatal(msg);
                return;
            }
            final String table_key = CatalogKey.createKey(catalog_tbl);
            TableStatistics table_stats = this.stats.getTableStatistics(table_key);
           
            // Temporary Loader Procedure
            TransactionTrace loader_xact = new TransactionTrace(xact_id, catalog_proc, new Object[0]) {
                /**
                 * We need this wrapper so that when CatalogUtil tries to figure out what
                 * the index of partitioning parameter we can just use the column index of partitioning
                 * attribute of the table that we are inserting into
                 */
                private final Procedure proc = new Procedure() {
                    @Override
                    public int getPartitionparameter() {
                        return (catalog_tbl.getPartitioncolumn().getIndex());
                    }
                    @Override
                    public Catalog getCatalog() {
                        return (catalog);
                    }
                };
                @Override
                public Procedure getCatalogItem(Database catalog_db) {
                    return (proc);
                }
            }; // Nasty...
           
            // Use a temporary query trace to wrap the "insert" of each tuple
            Statement catalog_stmt = this.stats_load_stmts.get(table_key);
            if (catalog_stmt == null) {
                catalog_stmt = catalog_proc.getStatements().add("INSERT_" + catalog_tbl.getName());
                catalog_stmt.setQuerytype(QueryType.INSERT.getValue());
                this.stats_load_stmts.put(table_key, catalog_stmt);

                // TERRIBLE HACK!
                // 2011-01-25 :: Why do I need to do this??
//                String stmt_key = CatalogKey.createKey(catalog_stmt);
//                CatalogUtil.CACHE_STATEMENT_COLUMNS_KEYS.put(stmt_key, new java.util.HashSet<String>());
//                CatalogUtil.CACHE_STATEMENT_COLUMNS_KEYS.get(stmt_key).add(table_key);
            }
            QueryTrace loader_query = new QueryTrace(catalog_stmt, new Object[0], 0);
            loader_xact.addQuery(loader_query);
           
            // Gather column types
            int num_columns = voltTable.getColumnCount();
            VoltType col_types[] = new VoltType[num_columns];
            for (int i = 0; i < num_columns; i++) {
                Column catalog_col = catalog_tbl.getColumns().get(i);
                col_types[i] = VoltType.get((byte)catalog_col.getType());
            } // FOR

            loader_query.params = new Object[num_columns];
            int num_tuples = voltTable.getRowCount();
            try {
                LOG.info("Processing " + num_tuples + " (sample=10) tuples for statistics on " + catalog_tbl.getName());
                boolean show_progress = (num_tuples > 25000);
                for (int i = 0; i < num_tuples; i += 10) {
                    if (i >= num_tuples) break;
                    VoltTableRow tuple = voltTable.fetchRow(i);
                    for (int j = 0; j < num_columns; j++) {
                        loader_query.params[j] = tuple.get(j, col_types[j]);
                    } // FOR
                    table_stats.process(stats_catalog_db, loader_xact);
                    if (show_progress && i > 0 && i % 10000 == 0) LOG.info(i + " tuples");
//                        if (i > 25000) break;
                } // FOR
                LOG.info("Processing finished for " + catalog_tbl.getName());
            } catch (Exception ex) {
                ex.printStackTrace();
                System.exit(1);
            }
        } // FOR
View Full Code Here

            }
        } // FOR
          // Go back through the table and create the sets of Procedures that
          // touch Columns
        for (Entry<Table, ListOrderedSet<Column>> e : this.orig_table_attributes.entrySet()) {
            Table catalog_tbl = e.getKey();

            // We need to know which Procedures reference each table so that we
            // can selectively choose
            // a new ProcParameter for each swap. Make sure we only include
            // those Procedures that
View Full Code Here

            Collection<Integer> rand_idxs = rand.getRandomIntSet(relax_size);
            if (trace.val)
                LOG.trace("Relaxed Table Identifiers: " + rand_idxs);
            for (int idx : rand_idxs) {
                assert (idx < this.orig_table_attributes.size()) : "Random Index is too large: " + idx + " " + this.orig_table_attributes.keySet();
                Table catalog_tbl = this.orig_table_attributes.get(idx);
                relaxed_tables.add(catalog_tbl);
            } // FOR (table)
            if (this.relaxed_sets.contains(relaxed_tables) == false) {
                break;
            }
View Full Code Here

                    final Map<Table, Double> vertex_weights = new HashMap<Table, Double>();
                    DependencyGraph dgraph = (DependencyGraph) this.getGraph();

                    if (agraph.containsVertex(element)) {
                        for (DesignerVertex child : dgraph.getSuccessors(element)) {
                            Table child_tbl = child.getCatalogItem();
                            DesignerVertex child_vertex = this.getGraph().getVertex(child_tbl);

                            if (agraph.containsVertex(child_vertex)) {
                                for (DesignerEdge edge : agraph.findEdgeSet(element, child_vertex)) {
                                    Double orig_weight = vertex_weights.get(child_tbl);
                                    if (orig_weight == null)
                                        orig_weight = 0.0d;
                                    vertex_weights.put(child_tbl, orig_weight + edge.getTotalWeight());
                                } // FOR
                            }
                        } // FOR
                    }

                    // Now sort the children them by weights and throw them at
                    // the walker
                    List<Table> sorted = new ArrayList<Table>(vertex_weights.keySet());
                    Collections.sort(sorted, new PartitionerUtil.CatalogWeightComparator<Table>(vertex_weights));
                    for (Table child_tbl : sorted) {
                        children.addAfter(this.getGraph().getVertex(child_tbl));
                    } // FOR
                    if (debug.val) {
                        LOG.debug(element);
                        LOG.debug("  sorted=" + sorted);
                        LOG.debug("  weights=" + vertex_weights);
                        LOG.debug("  children=" + children);
                    }
                };

                @Override
                protected void callback(DesignerVertex element) {
                    Table catalog_tbl = element.getCatalogItem();
                    if (!table_visit_order.contains(catalog_tbl)) {
                        table_visit_order.add(catalog_tbl);
                    }
                }
            }.traverse(root);
View Full Code Here

            Collection<Column> columns = CatalogUtil.getReadOnlyColumns(catalog_stmt);
            assert (columns != null) : catalog_stmt.fullName();

            // For now we only bother with two-column pairs
            for (Column catalog_col0 : columns) {
                Table catalog_tbl = catalog_col0.getParent();
                if (!multicolumns.containsKey(catalog_tbl)) {
                    multicolumns.put(catalog_tbl, new ArrayList<MultiColumn>());
                }
                if (trace.val)
                    LOG.trace(String.format("%s - MultiColumn Candidate: %s", catalog_stmt.fullName(), catalog_col0.fullName()));
                for (Column catalog_col1 : columns) {
                    if (catalog_col0.equals(catalog_col1) || !catalog_tbl.equals(catalog_col1.getParent()))
                        continue;
                    MultiColumn mc = MultiColumn.get(catalog_col0, catalog_col1);
                    assert (mc != null);
                    multicolumns.get(catalog_tbl).add(mc);
                } // FOR
View Full Code Here

    } // STATIC

    public static void populateCatalog(Database catalog_db, Map<String, ForeignKeyMapping> mapping) throws Exception {
        for (String table : mapping.keySet()) {
            LOG.info("Setting foreign key dependencies on table '" + table + "'");
            Table catalog_table = catalog_db.getTables().get(table);
            if (catalog_table == null) {
                throw new Exception("ERROR: Table '" + table + " is not in the catalog");
            }
            ForeignKeysUtil.setForeignKeyConstraints(catalog_table, mapping.get(table));
        } // FOR
View Full Code Here

        Map<Table, Constraint> table_const_map = new HashMap<Table, Constraint>();
        for (Entry<String, String> entry : fkeys.entrySet()) {
            String column = entry.getKey();
            String fkey[] = entry.getValue().split("\\.");
            Column catalog_col = catalog_tbl.getColumns().get(column);
            Table catalog_fkey_tbl = catalog_db.getTables().get(fkey[0]);
            Column catalog_fkey_col = catalog_fkey_tbl.getColumns().get(fkey[1]);

            if (catalog_fkey_tbl == null) {
                throw new Exception("ERROR: The foreign key table for '" + fkey[0] + "." + fkey[1] + "' is null");
            } else if (catalog_fkey_col == null) {
                throw new Exception("ERROR: The foreign key column for '" + fkey[0] + "." + fkey[1] + "' is null");
View Full Code Here

TOP

Related Classes of org.voltdb.catalog.Table

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.