Package org.voltdb.catalog

Examples of org.voltdb.catalog.Column


        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


                // this conflict vertex,
                // see whether there is an overlapping ancestor
                //
                Map<Column, Integer> ancestors = new HashMap<Column, Integer>();
                int max_count = 0;
                Column max_column = null;
                Column max_conflict_column = null;
                for (DesignerEdge conflict_edge : rtree.getInEdges(conflict_vertex)) {
                    PredicatePairs cset = (PredicatePairs) conflict_edge.getAttribute(AccessGraph.EdgeAttributes.COLUMNSET.name());
                    for (Column conflict_column : cset.findAllForParent(Column.class, conflict_tbl)) {
                        Column ancestor_column = CollectionUtil.last(info.dependencies.getAncestors(conflict_column));
                        Integer count = ancestors.get(ancestor_column);
                        count = (count == null ? 1 : count + 1);
                        ancestors.put(ancestor_column, count);
                        if (count > max_count) {
                            max_count = count;
                            max_column = ancestor_column;
                            max_conflict_column = conflict_column;
                        }
                    } // FOR
                } // FOR
                assert (max_column != null);
                //
                // If we have a column that is used in both trees, then that's
                // the one we'll want to partition
                // our buddy on...
                //
                boolean valid = true;
                for (Column column : ancestors.keySet()) {
                    if (!max_column.equals(column) && max_count == ancestors.get(column)) {
                        valid = false;
                        break;
                    }
                } // FOR
                LOG.debug("CONFLICT - " + conflict_vertex + ": " + ancestors);
                if (valid) {
                    String child_key = CatalogKey.createKey(max_conflict_column.getParent());
                    String parent_key = CatalogKey.createKey(max_column.getParent());
                    String orig_parent_key = proc_hints.force_dependency.put(child_key, parent_key);
                    if (!parent_key.equals(orig_parent_key)) {
                        LOG.debug("Forcing dependency " + child_key + "->" + parent_key);
                        forced_dependency = true;
                    }
                }
            } // FOR
            if (forced_dependency)
                continue;

            //
            // Now for each candidate we need to check whether replicating would
            // actually improve
            // the performance of this procedure. So first we need to get a
            // baseline cost
            // of the procedure on the workload
            // TODO: Support set sizes greater than 2!!
            //
            Set<Set<Table>> candidate_sets = new LinkedHashSet<Set<Table>>();
            assert (candidates.size() <= 2);
            for (int ctr0 = 0, cnt = candidates.size(); ctr0 < cnt; ctr0++) {
                Set<Table> set = new HashSet<Table>();
                set.add(candidates.get(ctr0));
                candidate_sets.add(set);
                for (int ctr1 = ctr0 + 1; ctr1 < cnt; ctr1++) {
                    set = new HashSet<Table>();
                    set.add(candidates.get(ctr0));
                    set.add(candidates.get(ctr1));
                    candidate_sets.add(set);
                } // FOR
            } // FOR

            //
            // Calculate the cost of each replication candidate set
            // If this is the first time we are doing this for this procedure,
            // then add in a blank
            // replication set so that we can get the baseline cost
            //
            Set<Table> best_set = null;
            double best_cost = Double.MAX_VALUE;
            if (best_cost == overall_best_cost)
                candidate_sets.add(new HashSet<Table>());
            for (Set<Table> replication_set : candidate_sets) {
                cost_model.invalidateCache(candidates);

                Catalog new_catalog = CatalogCloner.cloneBaseCatalog(info.catalogContext.database.getCatalog());
                for (Table catalog_tbl : proc_tables) {
                    DesignerVertex vertex = ptree.getVertex(catalog_tbl);
                    assert (vertex != null) : "PartitionTree is missing a vertex for " + catalog_tbl + " " + ptree.getVertices();
                    Table new_catalog_tbl = CatalogCloner.clone(catalog_tbl, new_catalog);

                    //
                    // Mark the table as replicated if it's in the current set
                    //
                    if (replication_set.contains(catalog_tbl) || ptree.isReplicated(vertex)) {
                        new_catalog_tbl.setIsreplicated(true);
                        new_catalog_tbl.setPartitioncolumn(ReplicatedColumn.get(new_catalog_tbl));
                        //
                        // Otherwise partition it according to the current
                        // partition tree
                        //
                    } else {
                        Column catalog_col = (Column) vertex.getAttribute(ptree, PartitionTree.VertexAttributes.ATTRIBUTE.name());
                        assert (catalog_col != null) : "Failed to retrieve partition column for " + catalog_tbl + " " + vertex.getAttributeValues(ptree);
                        Column new_catalog_col = new_catalog_tbl.getColumns().get(catalog_col.getName());
                        assert (new_catalog_col != null);
                        new_catalog_tbl.setIsreplicated(false);
                        new_catalog_tbl.setPartitioncolumn(new_catalog_col);
                    }
                } // FOR
View Full Code Here

            // node.
            // Therefore, we can only attach those children that have edges that
            // use these attributes
            //
            List<DesignerVertex> next_to_visit = new ArrayList<DesignerVertex>();
            Column parent_attribute = (Column) parent.getAttribute(ptree, PartitionTree.VertexAttributes.ATTRIBUTE.name());
            for (DesignerVertex child : next) {
                for (DesignerEdge edge : agraph.findEdgeSet(parent, child)) {
                    //
                    // Find the edge that links parent to this child
                    // If no edge exists, then the child can't be linked to the
View Full Code Here

                    protected void callback(DesignerVertex element) {
                        LOG.debug("SimpleCountingMapper.CALLBACK -> " + element.getCatalogItem());
                        DesignerVertex parent = this.getPrevious();

                        PartitionMethodType method = (PartitionMethodType) (element.getAttribute(ptree, PartitionTree.VertexAttributes.METHOD.name()));
                        Column attribute = null;
                        Table parent_table = null;
                        Column parent_attribute = null;

                        if (method == PartitionMethodType.REPLICATION) {
                            // Anything???
                        } else {
                            attribute = (Column) element.getAttribute(ptree, PartitionTree.VertexAttributes.ATTRIBUTE.name());
View Full Code Here

            VoltTable.ColumnInfo[] schema = mrInstance.getMapOutputSchema();
            String tableMapOutput = "MAP_" + procedure.getName();
            Table catalog_tbl = catalog_db.getTables().add(tableMapOutput);
            assert (catalog_tbl != null);
            for (int i = 0; i < schema.length; i++) {
                Column catalog_col = catalog_tbl.getColumns().add(schema[i].getName());
                catalog_col.setIndex(i);
                catalog_col.setNullable(i > 0);
                catalog_col.setType(schema[i].getType().getValue());
                if (i == 0)
                    catalog_tbl.setPartitioncolumn(catalog_col);
            } // FOR
            catalog_tbl.setMapreduce(true);
            catalog_tbl.setIsreplicated(false);

            // Initialize the reduceOutput table
            VoltTable.ColumnInfo[] schema_reduceOutput = mrInstance.getReduceOutputSchema();
            String tableReduceOutput = "REDUCE_" + procedure.getName();
            catalog_tbl = catalog_db.getTables().add(tableReduceOutput);
            assert (catalog_tbl != null);
            for (int i = 0; i < schema_reduceOutput.length; i++) {
                Column catalog_col = catalog_tbl.getColumns().add(schema_reduceOutput[i].getName());
                catalog_col.setIndex(i);
                catalog_col.setNullable(i > 0);
                catalog_col.setType(schema_reduceOutput[i].getType().getValue());
                if (i == 0)
                    catalog_tbl.setPartitioncolumn(catalog_col);
            } // FOR
            catalog_tbl.setMapreduce(true);
            catalog_tbl.setIsreplicated(false);
View Full Code Here

                        }
                        return;
                    }

                    String column_name = ((TupleValueExpression) element).getColumnName();
                    Column catalog_col = catalog_tbl.getColumns().get(column_name);
                    if (catalog_col == null) {
                        this.stop();
                        throw new RuntimeException(String.format("Unknown column '%s.%s' referenced in Expression node %s", table_name, column_name, element));
                    }
                    found_columns.add(catalog_col);
View Full Code Here

        } // FOR

        for (Table catalog_tbl : this.catalogContext.database.getTables()) {
            if (catalog_tbl.getSystable())
                continue;
            Column catalog_col = catalog_tbl.getPartitioncolumn();
           
            // Use the underlying partitioning column for views
            if (catalog_tbl.getMaterializer() != null) {
                catalog_col = catalog_tbl.getMaterializer().getPartitioncolumn();
            }
View Full Code Here

                            LOG.trace(String.format("Examining extracted %s: %s",
                                      pair.getClass().getSimpleName(), pair));

                        // Column = Column
                        if (pair.getFirst() instanceof Column && pair.getSecond() instanceof Column) {
                            Column col0 = (Column) pair.getFirst();
                            Column col1 = (Column) pair.getSecond();
                           
                            // If this table is a view, then we need to check whether
                            // we have to point the column down to the origin column
                            if (col0.getMatviewsource() != null) {
                                col0 = col0.getMatviewsource();
                            }
                            if (col1.getMatviewsource() != null) {
                                col1 = col1.getMatviewsource();
                            }

                            if (!pair.getComparisonExp().equals(ExpressionType.COMPARE_EQUAL)) {
                                if (debug.val)
                                    LOG.warn(String.format("Unsupported non-equality join in %s: %s",
                                             catalog_stmt.fullName(), pair));
                            } else {
                                if (!column_joins.containsKey(col0))
                                    column_joins.put(col0, new TreeSet<Column>());
                                if (!column_joins.containsKey(col1))
                                    column_joins.put(col1, new TreeSet<Column>());
                                column_joins.get(col0).add(col1);
                                column_joins.get(col1).add(col0);
                            }
                            continue;
                        }
                       
                        // Look for predicates with StmtParameters or ConstantValues
                        for (Table catalog_tbl : frag_tables) {
                            Column catalog_col = null;
                            CatalogType catalog_param = null;
                           
                            // *********************************** DEBUG ***********************************
                            if (trace.val) {
                                LOG.trace("Current Table: " + catalog_tbl.hashCode());
                                if (pair.getFirst() != null) {
                                    LOG.trace("entry.getFirst().getParent(): " + (pair.getFirst().getParent() != null ?
                                                    pair.getFirst().getParent().hashCode() :
                                                    pair.getFirst() + " parent is null?"));
                           
                                    if (pair.getFirst().getParent() instanceof Table) {
                                        Table parent = pair.getFirst().getParent();
                                        if (parent.getName().equals(catalog_tbl.getName())) {
                                            assert(parent.equals(catalog_tbl)) :
                                                "Mismatch on " + parent.getName() + "???";
                                        }
                                    }
                                } else {
                                    LOG.trace("entry.getFirst():             " + null);
                                }
                                if (pair.getSecond() != null) {
                                    LOG.trace("entry.getSecond().getParent(): " + (pair.getSecond().getParent() != null ?
                                                  pair.getSecond().getParent().hashCode() :
                                                  pair.getSecond() + " parent is null?"));
                                } else {
                                    LOG.trace("entry.getSecond():             " + null);
                                }
                            }
                            // *********************************** DEBUG ***********************************

                            // Column = (StmtParameter or ConstantValue)
                            if (pair.getFirst().getParent() != null && pair.getFirst().getParent().equals(catalog_tbl) &&
                                    (pair.getSecond() instanceof StmtParameter || pair.getSecond() instanceof ConstantValue) ) {
                                catalog_col = (Column) pair.getFirst();
                                catalog_param = pair.getSecond();
                           
                            }
                            // (StmtParameter or ConstantValue) = Column
                            else if (pair.getSecond().getParent() != null && pair.getSecond().getParent().equals(catalog_tbl) &&
                                    (pair.getFirst() instanceof StmtParameter || pair.getFirst() instanceof ConstantValue)) {
                                catalog_col = (Column) pair.getSecond();
                                catalog_param = pair.getFirst();
                            }
                            if (catalog_col != null && catalog_param != null) {
                                // If this table is a view, then we need to check whether
                                // we have to point the column down to the origin column
                                if (catalog_col.getMatviewsource() != null) {
                                    if (debug.val)
                                        LOG.debug("Found View Column: " + catalog_col.fullName() + " -> " + catalog_col.getMatviewsource().fullName());
                                    catalog_col = catalog_col.getMatviewsource();
                                }
                                if (trace.val)
                                    LOG.trace(String.format("[%s] Adding cache entry for %s: %s -> %s",
                                                            CatalogUtil.getDisplayName(catalog_tbl),
                                                            CatalogUtil.getDisplayName(catalog_frag),
                                                            CatalogUtil.getDisplayName(catalog_col),
                                                            CatalogUtil.getDisplayName(catalog_param)));
                                stmt_cache.put(catalog_col, catalog_param, pair.getComparisonExp(), catalog_tbl);
                                frag_cache.put(catalog_col, catalog_param, pair.getComparisonExp(), catalog_tbl);
                            }
                        } // FOR (tables)
                        if (trace.val)
                            LOG.trace("-------------------");
                    } // FOR (entry)

                    // We now have to take a second pass through the column mappings
                    // This will pick-up those columns that are joined together where one of them
                    // is also referenced with an input parameter. So we will map the input
                    // parameter to the second column as well
                    PartitionEstimator.populateColumnJoinSets(column_joins);

                    for (Column catalog_col : column_joins.keySet()) {
                        // Otherwise, we have to examine the the ColumnSet and
                        // look for any reference to this column
                        if (trace.val)
                            LOG.trace("Trying to find all references to " + CatalogUtil.getDisplayName(catalog_col));
                        for (Column other_col : column_joins.get(catalog_col)) {
                            // IMPORTANT: If the other entry is a column from another table and we don't
                            // have a reference in stmt_cache for ourselves, then we can look to see if
                            // this guy was used against a StmtParameter some where else in the Statement
                            // If this is the case, then we can substitute that mofo in it's place
                            if (stmt_cache.predicates.containsKey(catalog_col)) {
                                for (Pair<ExpressionType, CatalogType> pair : stmt_cache.predicates.get(catalog_col)) {
                                    if (trace.val)
                                        LOG.trace(String.format("Linking %s to predicate %s because of %s",
                                                  other_col.fullName(), pair, catalog_col.fullName()));
                                   
                                    ExpressionType expType = pair.getFirst();
                                    CatalogType param = pair.getSecond();
                                    stmt_cache.put(other_col, param, expType, (Table)other_col.getParent());
                                    frag_cache.put(other_col, param, expType, (Table)other_col.getParent());
                                } // FOR (StmtParameter.Index)
                            }
                        } // FOR (Column)
                    } // FOR (Column)
                }
                if (trace.val)
                    LOG.trace(frag_cache.toString());

                // Loop through all of our tables and make sure that there is an entry in the PlanFragment CacheEntrry
                // If there isn't, then that means there was no predicate on the table and therefore the PlanFragment
                // must be broadcast to all partitions (unless it is replicated)
                for (Table catalog_tbl : frag_tables) {
                    if (!frag_cache.hasTable(catalog_tbl)) {
                        if (trace.val)
                            LOG.trace(String.format("No column predicate for %s. Marking as broadcast for %s: %s",
                                      catalog_tbl.fullName(), catalog_frag.fullName(), frag_cache.getTables()));
                        frag_cache.markAsBroadcast(catalog_tbl);
                        stmt_cache.markAsBroadcast(catalog_tbl);
                    }
                } // FOR

                // Store the Fragment cache and update the Table xref mapping
                this.cache_fragmentEntries.put(frag_key, frag_cache);
                this.addTableCacheXref(frag_cache, frag_tables);
            } // FOR (fragment)

            // Then for updates we need to look to see whether they are updating an attribute
            // that they are partitioned on. If so, then it gets dicey because we need to
            // know the value...
            if (stmt_type == QueryType.UPDATE) {
                List<Table> tables = new ArrayList<Table>();
                PredicatePairs update_cset = new PredicatePairs();
                for (Table catalog_tbl : CatalogUtil.getReferencedTables(catalog_stmt)) {
                    update_cset.clear();
                    tables.clear();
                    tables.add(catalog_tbl);
                    AbstractPlanNode root_node = PlanNodeUtil.getRootPlanNodeForStatement(catalog_stmt, true);
                    CatalogUtil.extractUpdatePredicates(catalog_stmt, catalogContext.database, update_cset, root_node, true, tables);

                    boolean found = false;
                    for (CatalogPair pair : update_cset) {
                        Column catalog_col = null;
                        CatalogType catalog_param = null;

                        // For now we only care up look-ups using StmtParameters or ConstantValues
                        if (pair.getFirst() instanceof StmtParameter || pair.getFirst() instanceof ConstantValue) {
                            catalog_col = (Column) pair.getSecond();
View Full Code Here

        assert (!catalog_tbl.getIsreplicated()) : "Trying to partition replicated table: " + catalog_tbl;
        if (debug.val)
            LOG.debug("Calculating partition for VoltTableRow from " + catalog_tbl);

        int partition = -1;
        Column catalog_col = this.cache_tablePartitionColumns.get(catalog_tbl);
        assert (catalog_col != null) : "Null partition column: " + catalog_tbl;
        assert ((catalog_col instanceof VerticalPartitionColumn) == false) : "Invalid partitioning column: " + catalog_col.fullName();

        // Multi-Column Partitioning
        if (catalog_col instanceof MultiColumn) {
            MultiColumn mc = (MultiColumn) catalog_col;
            if (debug.val)
                LOG.debug(catalog_tbl.getName() + " MultiColumn: " + mc);

            Object values[] = new Object[mc.size()];
            for (int i = 0; i < values.length; i++) {
                Column inner = mc.get(i);
                VoltType type = VoltType.get(inner.getType());
                values[i] = row.get(inner.getIndex(), type);
            } // FOR
            partition = this.hasher.multiValueHash(values);

            // Single-Column Partitioning
        } else {
View Full Code Here

                for (Table catalog_tbl : cache_entry.getTables()) {
                    if (catalog_tbl.getMaterializer() != null) {
                        catalog_tbl = catalog_tbl.getMaterializer();
                    }
                    Column partition_col = catalog_tbl.getPartitioncolumn();
                    if (partition_col instanceof MultiColumn) {
                        if (debug.val)
                            LOG.warn(String.format("%s references %s, which is partitioned on %s. " +
                                 "Cannot be used for fast look-ups",
                                 catalog_frag.fullName(), catalog_tbl.getName(), partition_col.fullName()));
                        return (null);
                    }
                    else if (partition_col != null && cache_entry.predicates.containsKey(partition_col)) {
                        for (Pair<ExpressionType, CatalogType> pair : cache_entry.predicates.get(partition_col)) {
                            if (pair.getFirst() == ExpressionType.COMPARE_EQUAL &&
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.