Package edu.brown.designer

Examples of edu.brown.designer.DesignerEdge


        };
        DesignerVertex v0 = agraph.getVertex(expected[0]);
        assertNotNull("Missing vertex: " + expected[0], v0);
        DesignerVertex v1 = agraph.getVertex(expected[1]);
        assertNotNull("Missing vertex: " + expected[1], v1);
        assert (agraph.addEdge(new DesignerEdge(agraph), v0, v1));
        for (DesignerEdge e : agraph.findEdgeSet(v0, v1)) {
            e.addToWeight(0, 10000000);
        } // FOR
//        for (Edge e : agraph.getEdges()) {
//            System.err.println(e + " [" + e.getTotalWeight() + "]");
View Full Code Here


        this.graph.addVertex(this.root);
       
        for (int i = 1; i < TABLE_NAMES.length; i++) {
            String table_name = TABLE_NAMES[i];
            DesignerVertex child = new DesignerVertex(this.getTable(table_name));
            this.graph.addEdge(new DesignerEdge(this.graph), this.root, child);
        } // FOR
    }
View Full Code Here

            vertices[i] = new DesignerVertex(catalog_tbl);
            dgraph.addVertex(vertices[i]);
           
            if (i > 0) {
                for (int j = 0; j < num_edges; j++) {
                    dgraph.addEdge(new DesignerEdge(dgraph), vertices[i-1], vertices[i]);
                } // FOR
                Collection<DesignerEdge> edges = dgraph.findEdgeSet(vertices[i-1], vertices[i]);
                assertNotNull(edges);
                assertEquals(num_edges, edges.size());
            }
View Full Code Here

            DesignerVertex v1_0  = agraph1.getVertex(vertices0.get(0).getCatalogKey());
            assertNotNull("Missing vertex " + vertices0.get(0), v1_0);
            DesignerVertex v1_1  = agraph1.getVertex(vertices0.get(1).getCatalogKey());
            assertNotNull("Missing vertex " + vertices0.get(1), v1_1);
           
            DesignerEdge e1 = agraph1.findEdge(v1_0, v1_1);
            assertNotNull("Missing edge " + e0, e1);
           
            assertEquals(e0.getIntervalCount(), e1.getIntervalCount());
            for (int i = 0, cnt = e0.getIntervalCount(); i < cnt; i++) {
                assertEquals("Mismatched weights for " + e0 + " [" + i + "]", e0.getWeight(i), e1.getWeight(i));
            } // FOR
        } // FOR
    }
View Full Code Here

       
        Table tbl1 = this.getTable("ORDER_LINE");
        DesignerVertex v1 = this.agraph.getVertex(tbl1);
        assertNotNull(v1);
       
        DesignerEdge edge = this.agraph.findEdge(v0, v1);
        assertNotNull("No edge exists between " + tbl0 + " and " + tbl1, edge);
    }
View Full Code Here

            DesignerVertex v0 = agraph.getVertex(search.getFirst());
            assertNotNull("[" + i + "]: " + search.toString(), v0);
            DesignerVertex v1 = agraph.getVertex(search.getSecond());
            assertNotNull("[" + i + "]: " + search.toString(), v1);

            DesignerEdge found = agraph.findEdge(v0, v1);
            assertNotNull("[" + i + "]: " + search.toString() + "\n", found);
//            System.err.println("REMOVED: " + search + " [" + found + "]");
            agraph.removeEdge(found);
        } // FOR
    }
View Full Code Here

                    if (!child_root.equals(parent_root)) {
                        LOG.debug("Skipping " + vertex + " because it's in a different partition tree (" + child_root + "<->" + parent_root + ")");
                        continue;
                    }

                    DesignerEdge orig_edge = null;
                    Double max_weight = null;
                    try {
                        orig_edge = ptree.findEdge(vertex_orig_parent, vertex);
                        // TODO: Need to think about whether it makes sense to
                        // take the total weight
                        // or whether we need to consider
                        max_weight = orig_edge.getTotalWeight();
                    } catch (Exception ex) {
                        LOG.error(vertex + " => " + vertex_orig_parent);
                        if (orig_edge != null) {
                            LOG.error(orig_edge.debug());
                        } else {
                            LOG.error("ORIG EDGE: null");
                        }
                        ex.printStackTrace();
                        System.exit(1);
                    }
                    DesignerEdge max_edge = orig_edge;
                    for (DesignerEdge candidate_edge : agraph.findEdgeSet(parent, vertex)) {
                        Double candidate_weight = (Double) candidate_edge.getAttribute(PartitionTree.EdgeAttributes.WEIGHT.name());
                        if (candidate_weight > max_weight) {
                            max_edge = candidate_edge;
                            max_weight = candidate_weight;
                        }
                    } // FOR
                      //
                      // If the edge has changed, then we need to add it to our
                      // list of next vertices to visit.
                      // What if there isn't an AttributeSet that matches up
                      // with the parent? Then
                      // we just broke up the graph for no good reason
                      //
                    if (!force && max_edge.equals(orig_edge)) {
                        LOG.debug("Skipping " + vertex + " because there was not an edge with a greater weight than what it currently has in the PartitionTree");
                        continue;
                    } else {
                        //
                        // Check whether this child was our parent before, then
                        // we need to make sure that
                        // we switch ourselves to the HASH partition method
                        // instead of MAP
                        //
                        if (ptree.getParent(parent) != null && ptree.getParent(parent).equals(vertex)) {
                            parent.setAttribute(ptree, PartitionTree.VertexAttributes.METHOD.name(), PartitionMethodType.HASH);
                        }
                        LOG.debug("Remove existing child " + vertex + " from PartitionTree");
                        ptree.removeChild(vertex);
                    }
                }
            }
            LOG.debug("Adding " + vertex + " to the list of the next nodes to visit");
            next.add(vertex);
        } // FOR

        // --------------------------------------------------------
        // STEP #2: Selecting Partitioning Attribute
        // --------------------------------------------------------

        if (!next.isEmpty()) {

            //
            // If we're the root, then we need to select our partitioning
            // attribute
            //
            if (is_root) {
                TablePartitionSets attributes = new TablePartitionSets((Table) parent.getCatalogItem());
                boolean debug = parent.getCatalogItem().getName().equals("STOCK");
                for (DesignerVertex child : next) {
                    //
                    // We now need to pick what edge from the AccessGraph to use
                    // as the dependency edge
                    // in our partition mapping
                    //
                    Table catalog_child_tbl = child.getCatalogItem();
                    LOG.debug("Looking for edge between " + parent + " and " + child + ": " + agraph.findEdgeSet(parent, child));
                    for (DesignerEdge edge : agraph.findEdgeSet(parent, child)) {
                        LOG.debug("Creating AttributeSet entry for " + edge);
                        //
                        // We only want to use edges that are used in joins.
                        //
                        AccessGraph.AccessType type = (AccessGraph.AccessType) edge.getAttribute(AccessGraph.EdgeAttributes.ACCESSTYPE.name());
                        if (!AccessGraph.AccessType.JOINS.contains(type))
                            continue;
                        attributes.add(catalog_child_tbl, edge);
                    } // FOR
                } // FOR
                if (debug) {
                    LOG.debug(attributes.debug());
                    LOG.debug("---------------------");
                }
                if (attributes.size() > 1)
                    attributes.generateSubSets();
                if (debug) {
                    LOG.debug(attributes.debug());
                    LOG.debug("---------------------");
                }

                //
                // Now get the list of AttributeSets that have the highest
                // weights
                //
                Set<TablePartitionSets.Entry> asets = attributes.getMaxWeightAttributes();
                if (debug) {
                    System.out.println(asets);
                }

                TablePartitionSets.Entry aset = null;
                if (asets.isEmpty()) {
                    LOG.debug("Skipping vertex " + parent + " because no attributes to its children were found");
                    return; // throw new
                            // Exception("ERROR: Failed to generate AttributeSets for parent '"
                            // + parent + "'");
                } else if (asets.size() > 1) {
                    //
                    // XXX: Pick the attribute with the longest path to a root
                    // in the dependency graph
                    //
                    TablePartitionSets.Entry best_entry = null;
                    int best_length = Integer.MIN_VALUE;
                    for (TablePartitionSets.Entry entry : asets) {
                        for (Column catalog_col : entry) {
                            List<Column> ancestors = info.dependencies.getAncestors(catalog_col);
                            int length = ancestors.size();
                            LOG.debug(catalog_col + " ==> " + ancestors + " [length=" + length + "]");
                            if (length > best_length) {
                                best_entry = entry;
                                best_length = length;
                            }
                        } // FOR
                    } // FOR
                    if (best_entry == null) {
                        LOG.fatal("Unable to handle more than one AttributeSet for parent '" + parent + "' [" + asets.size() + "]");
                        System.exit(1);
                    }
                    LOG.debug("Choose PartitionSet.Entry " + best_entry + " because it has a path length of " + best_length);
                    aset = best_entry;
                } else {
                    aset = CollectionUtil.first(asets);
                }

                //
                // We need to figure out which attribute to select if there are
                // multiple ones
                // Well, one way is to pick one that
                parent.setAttribute(ptree, PartitionTree.VertexAttributes.ATTRIBUTE.name(), CollectionUtil.first(aset));
            } // is_root

            //
            // This AttributeSet determines how we want to partition the parent
            // 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
                    // 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 {
View Full Code Here

                            // If this vertex is a dependent on a parent, then
                            // we also need to get the
                            // mapping of columns
                            //
                            if (parent != null) {
                                DesignerEdge edge = ptree.findEdge(parent, element);
                                if (edge == null) {
                                    LOG.fatal("Failed to find edge between parent '" + parent + "' and child '" + element + "'");
                                    this.stop();
                                    return;
                                }
View Full Code Here

        this.edgesCombo.setFont(AbstractViewer.value_font);
        this.edgesCombo.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    DesignerEdge edge = (DesignerEdge)VertexInfoPanel.this.edgesCombo.getSelectedItem();
                    VertexInfoPanel.this.parent.getCurrentVisualizer().selectEdge(edge);
                }
            }
        });
        c.gridx = 1;
View Full Code Here

            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();
                    CatalogType parent1 = entry.getSecond().getParent();

                    if (parent0 == null && parent1 == null) {
                        if (d)
                            LOG.debug(String.format("Skipping %s ===> %s, %s", entry, v0, v1));
                        continue;

                        // Check whether this is a self-referencing edge
                    } else if ((parent0 == null && parent1.equals(catalog_tbl0)) || (parent1 == null && parent0.equals(catalog_tbl0))) {
                        if (d)
                            LOG.debug(String.format("Self-referencing edge %s ===> %s, %s", entry, v0, v0));
                        agraph.addEdge(new_e, v0, v0);

                    } else if ((parent0 == null && parent1.equals(catalog_tbl1)) || (parent1 == null && parent0.equals(catalog_tbl1))) {
                        if (d)
                            LOG.debug(String.format("Self-referencing edge %s ===> %s, %s", entry, v1, v1));
                        agraph.addEdge(new_e, v1, v1);

                    } else if ((parent0.equals(catalog_tbl0) && parent1.equals(catalog_tbl1) == false) || (parent1.equals(catalog_tbl0) && parent0.equals(catalog_tbl1) == false)
                            || (parent0.equals(catalog_tbl0) && parent1.equals(catalog_tbl0))) {
                        if (d)
                            LOG.debug(String.format("Self-referencing edge %s ===> %s, %s", entry, v0, v0));
                        agraph.addEdge(new_e, v0, v0);

                    } else if ((parent0.equals(catalog_tbl1) && parent1.equals(catalog_tbl0) == false) || (parent1.equals(catalog_tbl1) && parent0.equals(catalog_tbl0) == false)
                            || (parent0.equals(catalog_tbl0) && parent1.equals(catalog_tbl0))) {
                        if (d)
                            LOG.debug(String.format("Self-referencing edge %s ===> %s, %s", entry, v1, v1));
                        agraph.addEdge(new_e, v1, v1);

                    } else {
                        if (d)
                            LOG.debug(String.format("New edge %s ===> %s, %s", entry, v0, v1));
                        agraph.addEdge(new_e, v0, v1);

                    }
                }
                // Add weights from original edge to this new edge
                new_e.addToWeight(e);
            } // FOR (entry)

            if (d)
                LOG.debug("=====================================================================");
        } // FOR
View Full Code Here

TOP

Related Classes of edu.brown.designer.DesignerEdge

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.