Examples of PredicatePairs


Examples of edu.brown.utils.PredicatePairs

        //
        // ColumnSet
        //
        JPanel columnSetPanel = new JPanel(new BorderLayout());
        if (edge.hasAttribute(AccessGraph.EdgeAttributes.COLUMNSET.name())) {
            PredicatePairs cset = (PredicatePairs)edge.getAttribute(AccessGraph.EdgeAttributes.COLUMNSET.name());
           
            this.columnSetTable = new JTable(new ColumnSetTableModel(cset));
            this.columnSetTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
            this.columnSetTable.setFillsViewportHeight(true);
            this.columnSetTable.setDragEnabled(false);
View Full Code Here

Examples of edu.brown.utils.PredicatePairs

            agraph.addVertex(v);
        } // FOR

        for (DesignerEdge e : orig_agraph.getEdges()) {
            // Split up the ColumnSet into separate edges, one per entry
            PredicatePairs cset = e.getAttribute(EdgeAttributes.COLUMNSET);
            assert (cset != null);
            Collection<DesignerVertex> vertices = orig_agraph.getIncidentVertices(e);
            DesignerVertex v0 = CollectionUtil.first(vertices);
            DesignerVertex v1 = v0;
            if (vertices.size() > 1)
                v1 = CollectionUtil.get(vertices, 1);
            assert (v1 != null);

            Table catalog_tbl0 = v0.getCatalogItem();
            assert (catalog_tbl0 != null);
            Table catalog_tbl1 = v1.getCatalogItem();
            assert (catalog_tbl1 != null);

            if (d)
                LOG.debug(String.format("%s <-> %s\n%s", v0, v1, cset));

            for (CatalogPair entry : cset) {
                DesignerEdge new_e = entry_edges.get(entry);
                if (new_e == null) {
                    PredicatePairs new_cset = new PredicatePairs(cset.getStatements());
                    new_cset.add(entry);
                    new_e = new DesignerEdge(agraph, e);
                    new_e.setAttribute(EdgeAttributes.COLUMNSET, new_cset);
                    entry_edges.put(entry, new_e);

                    CatalogType parent0 = entry.getFirst().getParent();
View Full Code Here

Examples of edu.brown.utils.PredicatePairs

            // --------------------------------------------------------------
            // (1) Add an edge from table0 to all other tables in the query
            // --------------------------------------------------------------
            for (int ctr2 = ctr + 1; ctr2 < cnt; ctr2++) {
                Table table1 = tables.get(ctr2);
                PredicatePairs cset = CatalogUtil.extractStatementPredicates(catalog_stmt, true, table0, table1);
                if (debug_table)
                    LOG.trace("Creating join edge between " + table0 + "<->" + table1 + " for " + catalog_stmt);
                this.addEdge(agraph, AccessType.SQL_JOIN, cset, agraph.getVertex(table0), agraph.getVertex(table1), catalog_stmt);
            } // FOR
              // --------------------------------------------------------------

            // --------------------------------------------------------------
            // (2) Add a self-referencing edge for table0 if it is used in
            // a filter predicate using a variable or an input parameter
            // --------------------------------------------------------------
            if (debug_table)
                LOG.trace("Looking for scan ColumnSet on table '" + table0.getName() + "'");
            PredicatePairs cset = CatalogUtil.extractStatementPredicates(catalog_stmt, true, table0);
            if (!cset.isEmpty()) {
                if (debug_table)
                    LOG.trace("Creating scan edge to " + table0 + " for " + catalog_stmt);
                // if (debug) if (d) LOG.debug("Scan Column SET[" +
                // table0.getName() + "]: " + cset.debug());
                DesignerVertex vertex = agraph.getVertex(table0);
View Full Code Here

Examples of edu.brown.utils.PredicatePairs

            Set<Column> columns0 = new HashSet<Column>();
            Set<Column> columns1 = new HashSet<Column>();

            if (this.stmt_edge_xref.containsKey(catalog_stmt0)) {
                for (DesignerEdge edge : this.stmt_edge_xref.get(catalog_stmt0)) {
                    PredicatePairs cset = (PredicatePairs) edge.getAttribute(EdgeAttributes.COLUMNSET.name());
                    columns0.addAll(cset.findAllForOther(Column.class, param));
                } // FOR
            }
            if (this.stmt_edge_xref.containsKey(catalog_stmt1)) {
                for (DesignerEdge edge : this.stmt_edge_xref.get(catalog_stmt1)) {
                    PredicatePairs cset = (PredicatePairs) edge.getAttribute(EdgeAttributes.COLUMNSET.name());
                    columns1.addAll(cset.findAllForOther(Column.class, param));
                } // FOR
            }

            // Partition the columns into sets based on their Table. This is
            // necessary
            // so that we can have specific edges between vertices
            Map<Table, Set<Column>> table_column_xref0 = new HashMap<Table, Set<Column>>();
            Map<Table, Set<Column>> table_column_xref1 = new HashMap<Table, Set<Column>>();
            for (CatalogType ctype : columns0) {
                Column col = (Column) ctype;
                Table tbl = (Table) col.getParent();
                if (!table_column_xref0.containsKey(tbl)) {
                    table_column_xref0.put(tbl, new HashSet<Column>());
                }
                table_column_xref0.get(tbl).add(col);
            } // FOR
            for (CatalogType ctype : columns1) {
                Column col = (Column) ctype;
                Table tbl = (Table) col.getParent();
                if (!table_column_xref1.containsKey(tbl)) {
                    table_column_xref1.put(tbl, new HashSet<Column>());
                }
                table_column_xref1.get(tbl).add(col);
            } // FOR

            // if (debug) {
            // StringBuilder buffer = new StringBuilder();
            // buffer.append("table_column_xref0:\n");
            // for (Table table : table_column_xref0.keySet()) {
            // buffer.append("  ").append(table).append(": ").append(table_column_xref0.get(table)).append("\n");
            // }
            // if (d) LOG.debug(buffer.toString());
            //
            // buffer = new StringBuilder();
            // buffer.append("table_column_xref1:\n");
            // for (Table table : table_column_xref1.keySet()) {
            // buffer.append("  ").append(table).append(": ").append(table_column_xref1.get(table)).append("\n");
            // }
            // if (d) LOG.debug(buffer.toString());
            // }

            // Now create a cross product of the two sets based on tables --
            // Nasty!!
            for (Table table0 : table_column_xref0.keySet()) {
                for (Table table1 : table_column_xref1.keySet()) {
                    if (table0 == table1)
                        continue;
                    Pair<CatalogType, CatalogType> table_pair = CatalogUtil.pair(table0, table1);
                    PredicatePairs cset = null;
                    if (table_csets.containsKey(table_pair)) {
                        cset = table_csets.get(table_pair);
                    } else {
                        cset = new PredicatePairs();
                    }
                    for (Column column0 : table_column_xref0.get(table0)) {
                        for (Column column1 : table_column_xref1.get(table1)) {
                            // TODO: Enforce foreign key dependencies
                            // TODO: Set real ComparisionExpression attribute
                            cset.add(column0, column1, ExpressionType.COMPARE_EQUAL);
                        } // FOR
                    } // FOR
                    table_csets.put(table_pair, cset);
                } // FOR
            } // FOR
        } // FOR

        // Now create the edges between the vertices
        for (Pair<CatalogType, CatalogType> table_pair : table_csets.keySet()) {
            DesignerVertex vertex0 = agraph.getVertex((Table) table_pair.getFirst());
            DesignerVertex vertex1 = agraph.getVertex((Table) table_pair.getSecond());
            PredicatePairs cset = table_csets.get(table_pair);

            if (t) {
                LOG.trace("Vertex0: " + vertex0.getCatalogKey());
                LOG.trace("Vertex1: " + vertex0.getCatalogKey());
                LOG.trace("ColumnSet:\n" + cset.debug() + "\n");
            }

            DesignerEdge edge = this.addEdge(agraph, AccessType.PARAM_JOIN, cset, vertex0, vertex1);
            if (!this.multi_stmt_edge_xref.containsKey(edge)) {
                this.multi_stmt_edge_xref.put(edge, new HashSet<Set<Statement>>());
            }
            Set<Statement> new_set = new HashSet<Statement>();
            new_set.add(catalog_stmt0);
            new_set.add(catalog_stmt1);
            this.multi_stmt_edge_xref.get(edge).add(new_set);

            cset.getStatements().add(catalog_stmt0);
            cset.getStatements().add(catalog_stmt1);
        } // FOR tablepair columnsets
    }
View Full Code Here

Examples of edu.brown.utils.PredicatePairs

        Collection<DesignerEdge> scanEdges = agraph.getIncidentEdges(vertex,
                                                                 AccessGraph.EdgeAttributes.ACCESSTYPE.name(),
                                                                 AccessType.SCAN);
        if (t) LOG.trace("\t" + catalog_tbl.getName() + " Incident Edges: " + scanEdges);
        for (DesignerEdge edge : scanEdges) {
            PredicatePairs scan_cset = (PredicatePairs) edge.getAttribute(AccessGraph.EdgeAttributes.COLUMNSET.name());
            if (t) LOG.trace("\tSCAN EDGE: " + edge); // + "\n" +
                                                   // scan_cset.debug());

            // For each table that our foreign keys reference, will construct a
            // ColumnSet mapping
            Map<Table, PredicatePairs> fkey_column_xrefs = new HashMap<Table, PredicatePairs>();
            if (t) LOG.trace("\tOUR COLUMNS: " + scan_cset.findAllForParent(Column.class, catalog_tbl));
            for (Column catalog_col : scan_cset.findAllForParent(Column.class, catalog_tbl)) {
                // Get the foreign key constraint for this column and then add
                // it to the ColumnSet
                Collection<Constraint> catalog_consts = CatalogUtil.getConstraints(catalog_col.getConstraints());
                catalog_consts = CatalogUtil.findAll(catalog_consts, "type", ConstraintType.FOREIGN_KEY.getValue());
                if (!catalog_consts.isEmpty()) {
                    assert (catalog_consts.size() == 1) : CatalogUtil.getDisplayName(catalog_col) + " has " + catalog_consts.size() + " foreign key constraints: " + catalog_consts;
                    Constraint catalog_const = CollectionUtil.first(catalog_consts);
                    Table catalog_fkey_tbl = catalog_const.getForeignkeytable();
                    assert (catalog_fkey_tbl != null);

                    // Important! We only want to include tables that are
                    // actually referenced in this procedure
                    if (proc_tables.contains(catalog_fkey_tbl)) {
                        Column catalog_fkey_col = CollectionUtil.first(catalog_const.getForeignkeycols()).getColumn();
                        assert (catalog_fkey_col != null);

                        // TODO: Use real ExpressionType from the entry
                        if (!fkey_column_xrefs.containsKey(catalog_fkey_tbl)) {
                            fkey_column_xrefs.put(catalog_fkey_tbl, new PredicatePairs());
                        }
                        // if (debug) System.err.println("Foreign Keys: " +
                        // CollectionUtil.getFirst(catalog_const.getForeignkeycols()).getColumn());
                        // if (debug) System.err.println("catalog_fkey_tbl: " +
                        // catalog_fkey_tbl);
                        // if (debug) System.err.println("catalog_col: " +
                        // catalog_col);
                        // if (debug) System.err.println("catalog_fkey_col: " +
                        // catalog_fkey_col);
                        // if (debug) System.err.println("fkey_column_xrefs: " +
                        // fkey_column_xrefs.get(catalog_fkey_tbl));
                        fkey_column_xrefs.get(catalog_fkey_tbl).add(catalog_col, catalog_fkey_col, ExpressionType.COMPARE_EQUAL);
                    } else {
                        if (t) LOG.trace("\tSkipping Implict Reference Join for " + catalog_fkey_tbl + " because it is not used in " + this.catalog_proc);
                    }
                } else if (t) {
                    LOG.warn("\tNo foreign keys found for " + catalog_col.fullName());
                }
            } // FOR

            // Now for each table create an edge from our table to the table
            // referenced in the foreign
            // key using all the columdns referenced by in the SCAN predicates
            for (Table catalog_fkey_tbl : fkey_column_xrefs.keySet()) {
                DesignerVertex other_vertex = agraph.getVertex(catalog_fkey_tbl);
                PredicatePairs implicit_cset = fkey_column_xrefs.get(catalog_fkey_tbl);
                if (t)
                    LOG.trace("\t" + catalog_tbl + "->" + catalog_fkey_tbl + "\n" + implicit_cset.debug());
                Collection<DesignerEdge> edges = agraph.findEdgeSet(vertex, other_vertex);
                if (edges.isEmpty()) {
                    this.addEdge(agraph, AccessType.IMPLICIT_JOIN, implicit_cset, vertex, other_vertex, catalog_stmt0);
                    // Even though we don't need to create a new edge, we still
                    // need to know that
View Full Code Here

Examples of edu.brown.utils.PredicatePairs

        // We need to first check whether we already have an edge representing
        // this ColumnSet
        DesignerEdge new_edge = null;
        for (DesignerEdge edge : agraph.getEdges()) {
            Collection<DesignerVertex> vertices = agraph.getIncidentVertices(edge);
            PredicatePairs other_cset = (PredicatePairs) edge.getAttribute(EdgeAttributes.COLUMNSET.name());
            if (vertices.contains(v0) && vertices.contains(v1) && cset.equals(other_cset)) {
                if (t)
                    LOG.trace("FOUND DUPLICATE COLUMN SET: " + other_cset.debug() + "\n" + cset.toString() + "\n[" + edge.hashCode() + "] + " + cset.size() + " == " + other_cset.size() + "\n");
                new_edge = edge;
                break;
            }
        } // FOR
        if (new_edge == null) {
View Full Code Here

Examples of edu.brown.utils.PredicatePairs

                Table catalog_fkey_table = catalog_const.getForeignkeytable();
                DesignerVertex other_vertex = graph.getVertex(catalog_fkey_table);
                if (other_vertex == null) {
                    throw new Exception("ERROR: The constraint '" + catalog_const + "' on '" + vertex + "' uses an unknown table '" + catalog_fkey_table.getName() + "'");
                }
                PredicatePairs cset = new PredicatePairs();
                // FIXME cset.add(catalog_const.getFkeycolumn, catalog_col);
                DesignerEdge edge = new DesignerEdge(graph);
                edge.setAttribute(DependencyGraph.EdgeAttributes.CONSTRAINT.name(), catalog_const);
                edge.setAttribute(DependencyGraph.EdgeAttributes.COLUMNSET.name(), cset);
                graph.addEdge(edge, other_vertex, vertex, EdgeType.DIRECTED);
View Full Code Here

Examples of edu.brown.utils.PredicatePairs

                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) {
View Full Code Here

Examples of edu.brown.utils.PredicatePairs

                    //
                    // Find the edge that links parent to this child
                    // If no edge exists, then the child can't be linked to the
                    // parent
                    //
                    PredicatePairs cset = (PredicatePairs) edge.getAttribute(AccessGraph.EdgeAttributes.COLUMNSET.name());
                    Collection<Column> entries = cset.findAllForOther(Column.class, parent_attribute);
                    if (!entries.isEmpty()) {
                        next_to_visit.add(child);
                        assert (entries.size() == 1) : "Multiple entries from " + parent + " to " + child + ": " + entries;
                        try {
                            if (!ptree.containsVertex(parent))
                                ptree.addVertex(parent);

                            DesignerEdge new_edge = ptree.createEdge(parent, child, edge);
                            LOG.debug("Creating new edge " + new_edge + " in PartitionTree");
                            LOG.debug(new_edge.debug(ptree));

                            child.setAttribute(ptree, PartitionTree.VertexAttributes.ATTRIBUTE.name(), CollectionUtil.first(entries));
                            child.setAttribute(ptree, PartitionTree.VertexAttributes.METHOD.name(), PartitionMethodType.MAP);

                            //
                            // For now we can only link ourselves to the
                            // parent's attribute
                            //
                            child.setAttribute(ptree, PartitionTree.VertexAttributes.PARENT_ATTRIBUTE.name(), parent.getAttribute(ptree, PartitionTree.VertexAttributes.ATTRIBUTE.name()));

                            // if
                            // (parent.getTable().getName().equals("DISTRICT"))
                            // {
                            // System.out.println(parent.getTable().getName() +
                            // "." + parent_attribute.getName() + " -> " +
                            // child.getTable().getName() + "." +
                            // CollectionUtil.getFirst(entries).getName());
                            // System.exit(1);
                            // }
                        } catch (Exception ex) {
                            LOG.fatal(ex.getMessage());
                            ex.printStackTrace();
                            System.exit(1);
                        }
                        break;
                    }
                } // FOR
            } // FOR
            for (DesignerVertex child : next_to_visit) {
                this.buildPartitionTree(ptree, child, agraph, hints);
            }
            //
            // If the current parent doesn't have any children, then we
            // we need to decide how to partition it based on the
            // self-referencing edges
            //
        } else if (is_root || !ptree.containsVertex(parent)) {
            LOG.debug("Parent " + parent + " does not have any children");
            DesignerEdge partition_edge = null;
            double max_weight = 0;
            for (DesignerEdge edge : agraph.getIncidentEdges(parent)) {
                AccessGraph.AccessType type = (AccessGraph.AccessType) edge.getAttribute(AccessGraph.EdgeAttributes.ACCESSTYPE.name());
                if (type != AccessGraph.AccessType.SCAN)
                    continue;
                Double weight = 0.0d; // FIXME
                                      // (Double)edge.getAttribute(AccessGraph.EdgeAttributes.WEIGHT.name());
                if (weight > max_weight) {
                    partition_edge = edge;
                    max_weight = weight;
                }
            } // FOR
            if (partition_edge != null) {
                PredicatePairs cset = (PredicatePairs) partition_edge.getAttribute(AccessGraph.EdgeAttributes.COLUMNSET.name());
                Collection<Column> attributes = cset.findAllForParent(Column.class, parent_table);
                parent.setAttribute(ptree, PartitionTree.VertexAttributes.ATTRIBUTE.name(), CollectionUtil.first(attributes));
                parent.setAttribute(ptree, PartitionTree.VertexAttributes.METHOD.name(), PartitionMethodType.HASH);
                LOG.debug(parent + parent.debug(ptree));
            } else {
                LOG.debug("Removing " + parent + " from PartitionTree because it does not contain an edge");
View Full Code Here

Examples of edu.brown.utils.PredicatePairs

    public boolean add(Table child_table, DesignerEdge edge) {
        //
        // We first need to convert the ColumnSet into a set of attributes
        // that "connect" the child table with the parent
        //
        PredicatePairs cset = null;
        Entry entry = new Entry();
        if (this.parent_table == child_table) {
            cset = (PredicatePairs) edge.getAttribute(AccessGraph.EdgeAttributes.COLUMNSET.name());
            entry.addAll(cset.findAllForParent(Column.class, child_table));
        } else {
            cset = ((PredicatePairs) edge.getAttribute(AccessGraph.EdgeAttributes.COLUMNSET.name())).createPredicatePairsForParent(Column.class, child_table);
            entry.addAll(cset.findAllForOtherParent(Column.class, child_table));
        }
        double weight = (Double) edge.getAttribute(Members.WEIGHTS.name());
        entry.weight = weight;
        // System.out.println(cset + " Weight=" + entry.weight);

        //
        // Check whether we already contain this AttributeSet
        // If we do, then we need to add the weight of the one we're being given
        // to the one that we already have in there
        //
        boolean found = false;
        for (Entry aset : this) {
            if (aset.equals(entry)) {
                found = true;
                aset.weight += weight;
                entry = aset;
                break;
            }
        } // FOR
        if (!found)
            super.add(entry);

        //
        // Build our various index structures. We probably should probably think
        // this through
        // a bit more than just making anything we want here...
        //

        //
        // Table -> ColumnSets
        //
        if (!entry.table_cset_xref.containsKey(child_table)) {
            entry.table_cset_xref.put(child_table, new HashSet<PredicatePairs>());
        }
        entry.table_cset_xref.get(child_table).add(cset);

        //
        // Table -> Entry
        //
        if (!this.table_entry_xref.containsKey(child_table)) {
            this.table_entry_xref.put(child_table, new HashSet<Entry>());
        }
        this.table_entry_xref.get(child_table).add(entry);

        //
        // ColumnSet -> AttributeSet
        //
        this.cset_entry_xref.put(cset, entry);

        //
        // Child Table -> Edges
        //
        if (!entry.table_edge_xref.containsKey(child_table)) {
            entry.table_edge_xref.put(child_table, new HashSet<DesignerEdge>());
        }
        entry.table_edge_xref.get(child_table).add(edge);

        //
        // Child Table -> Attributes
        //
        if (entry.table_partition_xref.containsKey(child_table)) {
            LOG.fatal("The AttributeSet for parent table '" + this.parent_table + "' " + "already contains attributes for child table '" + child_table + "'");
            return (false);
        }
        entry.table_partition_xref.put(child_table, cset.findAllForOtherParent(Column.class, this.parent_table));

        return (true);
    }
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.