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
}