* @throws Exception
*/
protected void createImplicitEdges(AccessGraph agraph, Collection<Table> proc_tables, Statement catalog_stmt0, Table catalog_tbl) throws Exception {
// For each SCAN edge for this vertex, check whether the column has a
// foreign key
DesignerVertex vertex = agraph.getVertex(catalog_tbl);
if (d) LOG.debug("Creating Implicit Edges for " + catalog_tbl);
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()) {