Skip to content

Commit 59b6e69

Browse files
committed
Reduce path duplicates
1 parent 463657e commit 59b6e69

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

text_2_sql/data_dictionary/data_dictionary_creator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ def pivot(self):
5353

5454
def add_foreign_key(self, foreign_key: ForeignKeyRelationship):
5555
"""A method to add a foreign key to the entity relationship."""
56+
57+
for existing_foreign_key in self.foreign_keys:
58+
if (
59+
existing_foreign_key.column == foreign_key.column
60+
and existing_foreign_key.foreign_column == foreign_key.foreign_column
61+
):
62+
return
63+
5664
self.foreign_keys.append(foreign_key)
5765

5866
@classmethod
@@ -328,6 +336,11 @@ def get_entity_relationships_from_graph(
328336
successors_not_visited = [
329337
successor for successor in successors if successor not in visited
330338
]
339+
340+
if len(path) == 1 and entity in successors:
341+
# We can do a self join on the entity in this case but we don't want to propagate this
342+
result.append(f"{entity} -> {entity}")
343+
331344
if len(successors_not_visited) == 0 and len(path) > 1:
332345
# Add the complete path to the result as a string
333346
result.append(" -> ".join(path))

0 commit comments

Comments
 (0)