Skip to content

Commit

Permalink
feat: improve table and column neighbors (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna authored Feb 1, 2024
1 parent 0b86a65 commit fb2dfc6
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions bd_api/apps/api/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ def get_date_time(date_times):
)


def get_unique_list(lst: list[dict]):
"""Get unique list of dicts"""
return [dict(t) for t in {tuple(d.items()) for d in lst}]


class UUIDHiddenIdForm(forms.ModelForm):
"""Form to include UUID in inline formes (Table, Column and Coverage)"""

Expand Down Expand Up @@ -1101,21 +1106,23 @@ def neighbors(self):
all_neighbors = []
for column in self.columns.all():
for neighbor in column.neighbors:
all_neighbors.append((neighbor.table, neighbor))
all_neighbors.append(neighbor)
return all_neighbors

def get_graphql_neighbors(self) -> list[dict]:
all_neighbors = []
for table, column in self.neighbors:
for column, table, dataset in self.neighbors:
all_neighbors.append(
{
"table_id": str(table.id),
"table_name": table.name,
"column_id": str(column.id),
"column_name": column.name,
"table_id": str(table.id),
"table_name": table.name,
"dataset_id": str(dataset.id),
"dataset_name": dataset.name,
}
)
return all_neighbors
return get_unique_list(all_neighbors)

def clean(self):
"""
Expand Down Expand Up @@ -1317,22 +1324,36 @@ def neighbors(self):
"""
if not self.directory_primary_key:
return []
return (
all_columns = (
Column.objects.filter(directory_primary_key=self.directory_primary_key)
.exclude(id=self.id)
.all()
)
all_neighbors = []
for column in all_columns:
all_neighbors.append(
(
column,
column.table,
column.table.dataset,
)
)
return all_neighbors

def get_graphql_neighbors(self) -> list[dict]:
all_neighbors = []
for column in self.neighbors:
for column, table, dataset in self.neighbors:
all_neighbors.append(
{
"column_id": str(column.id),
"column_name": column.name,
"table_id": str(table.id),
"table_name": table.name,
"dataset_id": str(dataset.id),
"dataset_name": dataset.name,
}
)
return all_neighbors
return get_unique_list(all_neighbors)


class ColumnOriginalName(BaseModel):
Expand Down

0 comments on commit fb2dfc6

Please sign in to comment.