Package edu.brown.designer

Examples of edu.brown.designer.DependencyGraph


     * @throws CycleInDagException
     */
    public static Table[] sortTables() throws CycleInDagException
    {
        CatalogContext cc = new CatalogContext(s_cat.getCatalog());
        DependencyGraph dgraph = DependencyGraphGenerator.generate(cc);

        int size = dgraph.getVertexCount();

        Table[] ret = new Table[size];

        // zero_list: vertices whose in-degree is zero
        List<DesignerVertex> zero_list = new LinkedList<DesignerVertex>();
        List<DesignerVertex> non_zero_list = new LinkedList<DesignerVertex>();

        // initialize two lists
        for (DesignerVertex v : dgraph.getVertices())
        {
            if (dgraph.getPredecessorCount(v) == 0)
            {
                zero_list.add(v);
                // System.out.println("To zero_list: " + v);
            }
            else
            {
                non_zero_list.add(v);
                // System.out.println("To non_zero_list: " + v);
            }
        }

        int cnt = 0;
        while (true)
        {
            if (zero_list.isEmpty() && non_zero_list.isEmpty())
                break;

            if (zero_list.isEmpty())
            {
                throw new CycleInDagException();
            }

            DesignerVertex cur = zero_list.remove(0);
            ret[cnt++] = (Table) (cur.getCatalogItem());

            // System.out.println("Next ver: " + cur);

            Collection<DesignerVertex> successors = dgraph.getSuccessors(cur);
            dgraph.removeVertex(cur);

            for (DesignerVertex successor : successors)
            {
                if (dgraph.getPredecessorCount(successor) == 0)
                {
                    non_zero_list.remove(successor);
                    zero_list.add(successor);
                    // System.out.println("Move " + successor +
                    // " from non_zero to zero");
View Full Code Here


   
    /**
     * testExportDependencyGraph
     */
    public void testExportDependencyGraph() throws Exception {
        DependencyGraph graph = DependencyGraphGenerator.generate(catalogContext);
        assertNotNull(graph);
        assertTrue(graph.getVertexCount() > 0);
        assertTrue(graph.getEdgeCount() > 0);
       
        GraphvizExport<DesignerVertex, DesignerEdge> graphviz = new GraphvizExport<DesignerVertex, DesignerEdge>(graph);
        String output = graphviz.export("tm1");
        for (Table catalog_tbl : catalogContext.getDataTables()) {
            if (catalog_tbl.getSystable()) continue;
View Full Code Here

    /**
     * testRemoveDuplicateEdges
     */
    public void testRemoveDuplicateEdges() throws Exception {
        final int num_edges = 5;
        DependencyGraph dgraph = new DependencyGraph(catalogContext.database);
        DesignerVertex vertices[] = new DesignerVertex[TABLE_NAMES.length];
        for (int i = 0; i < vertices.length; i++) {
            Table catalog_tbl = this.getTable(TABLE_NAMES[i]);
            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());
            }
        } // FOR
       
        GraphUtil.removeDuplicateEdges(dgraph);
        for (int i = 1; i < vertices.length; i++) {
            Collection<DesignerEdge> edges = dgraph.findEdgeSet(vertices[i-1], vertices[i]);
            assertNotNull(edges);
            assertEquals(1, edges.size());
        } // FOR
    }
View Full Code Here

                protected void populate_children(VertexTreeWalker.Children<DesignerVertex> children, DesignerVertex element) {
                    // For the current element, look at all of its children and
                    // count up the total
                    // weight of all the edges to each child
                    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)) {
View Full Code Here

        menuItem.getAccessibleContext().setAccessibleDescription("Quit Program");
        menuItem.addActionListener(this.menuHandler);
        menuItem.putClientProperty(MenuHandler.MENU_ID, MenuHandler.MENU_QUIT);
        menu.add(menuItem);
       
        DependencyGraph dgraph = new DependencyGraph(this.args.catalog_db);
        try {
            new DependencyGraphGenerator(new DesignerInfo(args.catalogContext, args.workload, args.stats)).generate(dgraph);
            this.graph_panel = GraphVisualizationPanel.factory(dgraph);
        } catch (Exception ex) {
            ex.printStackTrace();
View Full Code Here

     *
     * @param catalog_db
     * @return
     */
    public static DependencyGraph generate(CatalogContext catalogContext) {
        DependencyGraph dgraph = new DependencyGraph(catalogContext.database);
        DesignerInfo info = new DesignerInfo(catalogContext, new Workload(catalogContext.catalog));
        try {
            new DependencyGraphGenerator(info).generate(dgraph);
        } catch (Exception ex) {
            ex.printStackTrace();
View Full Code Here

   
    public static void main(String[] vargs) throws Exception {
        ArgumentsParser args = ArgumentsParser.load(vargs);
        args.require(ArgumentsParser.PARAM_CATALOG);
       
        DependencyGraph dgraph = DependencyGraphGenerator.generate(args.catalogContext);
        GraphUtil.removeDuplicateEdges(dgraph);
       
        // Any optional parameters are tables we should ignore
        // To do that we need to just remove them from the DependencyGraph
        for (String opt : args.getOptParams()) {
            for (String tableName : opt.split(",")) {
                Table catalog_tbl = args.catalog_db.getTables().getIgnoreCase(tableName);
                if (catalog_tbl == null) {
                    LOG.warn("Unknown table '" + tableName + "'");
                    continue;
                }
                DesignerVertex v = dgraph.getVertex(catalog_tbl);
                assert(v != null) : "Failed to get vertex for " + catalog_tbl;
                dgraph.removeVertex(v);
            } // FOR
        } // FOR
       
        GraphvizExport<DesignerVertex, DesignerEdge> gvx = new GraphvizExport<DesignerVertex, DesignerEdge>(dgraph);
       
        // Enable full edge labels
        if (args.getBooleanParam(ArgumentsParser.PARAM_CATALOG_LABELS, false)) {
            gvx.setEdgeLabels(true);
            DependencyUtil dependUtil = DependencyUtil.singleton(args.catalog_db);
            for (DesignerEdge e : dgraph.getEdges()) {
                Table tbl0 = dgraph.getSource(e).getCatalogItem();
                Table tbl1 = dgraph.getDest(e).getCatalogItem();
                String label = "";
                for (Column col0 : CatalogUtil.getSortedCatalogItems(tbl0.getColumns(), "index")) {
                    for (Column col1 : dependUtil.getDescendants(col0)) {
                        if (col1.getParent().equals(tbl1) == false) continue;
                        if (label.isEmpty() == false) label += "\n";
View Full Code Here

     * for it is dependent on the number of tuples of the other table
     *
     * @return
     */
    private DependencyGraph generateDependencyGraph() {
        DependencyGraph dgraph = new DependencyGraph(this.catalog_db);

        for (Table catalog_tbl : this.table_profiles.keySet()) {
            dgraph.addVertex(new DesignerVertex(catalog_tbl));
        } // FOR

        for (Entry<Table, TableProfile> e : this.table_profiles.entrySet()) {
            Table catalog_tbl = e.getKey();
            TableProfile profile = e.getValue();
            DesignerVertex v = dgraph.getVertex(catalog_tbl);

            for (Table other_tbl : profile.getDependentTables()) {
                boolean ret = dgraph.addEdge(new DesignerEdge(dgraph), dgraph.getVertex(other_tbl), v, EdgeType.DIRECTED);
                assert (ret) : "Failed to add edge from " + other_tbl + " to " + catalog_tbl;
            } // FOR
        } // FOR
        return (dgraph);
    }
View Full Code Here

        final String f = "%-30s %-15d [%.2fGB]"; // TableName -> TupleCount
                                                 // TableSize
        final double gb = 1073741824d;

        // First we need to generate a DependencyGraph
        final DependencyGraph dgraph = this.generateDependencyGraph();
        assert (dgraph.getVertexCount() == this.table_profiles.size());
        // GraphVisualizationPanel.createFrame(dgraph).setVisible(true);

        // Now loop through and generate our TableStatistics
        final Map<Table, TableStatistics> stats = new HashMap<Table, TableStatistics>();

        // First generate all the TableStatistics for tables without any
        // dependencies
        for (Entry<Table, TableProfile> e : this.table_profiles.entrySet()) {
            Table catalog_tbl = e.getKey();
            TableProfile profile = e.getValue();

            if (profile.hasDependencies())
                continue;
            LOG.debug("Generating FIXED TableStatistics for " + e.getKey());

            // There's not much we can do here other than this...
            // If the table is not fixed, then modify the number of tuples by
            // the scale factor
            TableStatistics ts = new TableStatistics(catalog_tbl);
            ts.tuple_count_total = Math.round(profile.tuple_count / (profile.is_fixed ? 1.0 : this.scale_factor));
            ts.tuple_size_max = ts.tuple_size_min = ts.tuple_size_avg = MemoryEstimator.estimateTupleSize(catalog_tbl);
            ts.tuple_size_total = ts.tuple_size_avg * ts.tuple_count_total;
            stats.put(catalog_tbl, ts);
            LOG.info(String.format(f, catalog_tbl.getName(), ts.tuple_count_total, ts.tuple_size_total / gb));
        } // FOR

        // Now traverse the DependencyGraph and generate the rest of the tables
        for (DesignerVertex root : dgraph.getRoots()) {
            new VertexTreeWalker<DesignerVertex, DesignerEdge>(dgraph, TraverseOrder.LONGEST_PATH) {
                protected boolean hasVisited(DesignerVertex element) {
                    return (super.hasVisited(element) || stats.containsKey(element.getCatalogItem()));
                };

View Full Code Here

TOP

Related Classes of edu.brown.designer.DependencyGraph

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.