Skip to content

Commit

Permalink
Store position attribute as Array type
Browse files Browse the repository at this point in the history
The list of position attributes has now been replaced with a single
attribute, which can be an Array. Postgre will store the array directly,
SQLite will create one column for each element.

This commit also tightens the requirements for optional arguments
passed to the graph databases and simplifies the meta-data checks.

There is now also documentation on the allowed read/write modes and
checks for the passed arguments.
  • Loading branch information
funkey committed Mar 7, 2024
1 parent 0273ee9 commit c949e97
Show file tree
Hide file tree
Showing 5 changed files with 418 additions and 195 deletions.
13 changes: 6 additions & 7 deletions funlib/persistence/graphs/pgsql_graph_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class PgSQLGraphDatabase(SQLGraphDataBase):
def __init__(
self,
position_attributes: list[str],
position_attribute: str,
db_name: str,
db_host: str = "localhost",
db_user: Optional[str] = None,
Expand Down Expand Up @@ -62,8 +62,8 @@ def __init__(
self.cur = self.connection.cursor()

super().__init__(
position_attributes,
mode=mode,
position_attribute=position_attribute,
directed=directed,
total_roi=total_roi,
nodes_table=nodes_table,
Expand All @@ -86,10 +86,8 @@ def _drop_tables(self) -> None:
self._commit()

def _create_tables(self) -> None:
columns = self.position_attributes + list(self.node_attrs.keys())
types = [self.__sql_type(float) + " NOT NULL"] * len(
self.position_attributes
) + list([self.__sql_type(t) for t in self.node_attrs.values()])
columns = self.node_attrs.keys()
types = [self.__sql_type(t) for t in self.node_attrs.values()]
column_types = [f"{c} {t}" for c, t in zip(columns, types)]
self.__exec(
f"CREATE TABLE IF NOT EXISTS "
Expand All @@ -100,7 +98,7 @@ def _create_tables(self) -> None:
)
self.__exec(
f"CREATE INDEX IF NOT EXISTS pos_index ON "
f"{self.nodes_table_name}({','.join(self.position_attributes)})"
f"{self.nodes_table_name}({self.position_attribute})"
)

columns = list(self.edge_attrs.keys())
Expand Down Expand Up @@ -139,6 +137,7 @@ def _read_metadata(self) -> Optional[dict[str, Any]]:
return None

def _select_query(self, query) -> Iterable[Any]:
print(query)
self.__exec(query)
return self.cur

Expand Down
Loading

0 comments on commit c949e97

Please sign in to comment.