From 3384fb1d621ce8af1e141ce0cc51f353f8b40f3c Mon Sep 17 00:00:00 2001 From: Anthony Mahanna Date: Thu, 18 Jan 2024 21:29:27 -0500 Subject: [PATCH 1/4] optimize `__fetch_adb_docs` --- adbnx_adapter/adapter.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/adbnx_adapter/adapter.py b/adbnx_adapter/adapter.py index 44612d2..e871000 100644 --- a/adbnx_adapter/adapter.py +++ b/adbnx_adapter/adapter.py @@ -144,7 +144,7 @@ def arangodb_to_networkx( # 1. Fetch ArangoDB vertices v_col_cursor, v_col_size = self.__fetch_adb_docs( - v_col, atribs, explicit_metagraph, **adb_export_kwargs + v_col, False, atribs, explicit_metagraph, **adb_export_kwargs ) # 2. Process ArangoDB vertices @@ -167,7 +167,7 @@ def arangodb_to_networkx( # 1. Fetch ArangoDB edges e_col_cursor, e_col_size = self.__fetch_adb_docs( - e_col, atribs, explicit_metagraph, **adb_export_kwargs + e_col, True, atribs, explicit_metagraph, **adb_export_kwargs ) # 2. Process ArangoDB edges @@ -421,6 +421,7 @@ def networkx_to_arangodb( def __fetch_adb_docs( self, col: str, + is_edge: bool, attributes: Set[str], explicit_metagraph: bool, **adb_export_kwargs: Any, @@ -429,6 +430,8 @@ def __fetch_adb_docs( :param col: The ArangoDB collection. :type col: str + :param is_edge: True if **col** is an edge collection. + :type is_edge: bool :param attributes: The set of document attributes. :type attributes: Set[str] :param explicit_metagraph: If True, only return the set of **attributes** @@ -443,11 +446,11 @@ def __fetch_adb_docs( """ aql_return_value = "doc" if explicit_metagraph: + edge_keys = "_from: doc._from, _to: doc._to" if is_edge else "" aql_return_value = f""" MERGE( KEEP(doc, {list(attributes)}), - {{"_id": doc._id}}, - doc._from ? {{"_from": doc._from, "_to": doc._to}}: {{}} + {{"_id": doc._id, {edge_keys}}} ) """ From 4b398b221fdd3d2f086b51eabb202ecc4c46d5db Mon Sep 17 00:00:00 2001 From: Anthony Mahanna Date: Thu, 18 Jan 2024 21:29:35 -0500 Subject: [PATCH 2/4] set `continue-on-error` --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6cb9065..b105d83 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,7 @@ env: jobs: build: runs-on: ubuntu-latest + continue-on-error: true strategy: matrix: python: ["3.8", "3.9", "3.10", "3.11", "3.12"] From d65598c4087232fb0df48a928888db662f73f99f Mon Sep 17 00:00:00 2001 From: Anthony Mahanna Date: Thu, 18 Jan 2024 21:55:15 -0500 Subject: [PATCH 3/4] fix: set metagraph `edgeCollections` as optional not sure why anyone would want this, but still technically possible nevertheless.. --- adbnx_adapter/adapter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adbnx_adapter/adapter.py b/adbnx_adapter/adapter.py index e871000..58b4cef 100644 --- a/adbnx_adapter/adapter.py +++ b/adbnx_adapter/adapter.py @@ -162,7 +162,7 @@ def arangodb_to_networkx( # Edge Collections # #################### - for e_col, atribs in metagraph["edgeCollections"].items(): + for e_col, atribs in metagraph.get("edgeCollections", {}).items(): logger.debug(f"Preparing '{e_col}' edges") # 1. Fetch ArangoDB edges From c9537c5e40c531fd35b7adc3ea3cd2ee4a3db380 Mon Sep 17 00:00:00 2001 From: Anthony Mahanna Date: Fri, 19 Jan 2024 09:29:56 -0500 Subject: [PATCH 4/4] cleanup: `aql_return_value` --- adbnx_adapter/adapter.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/adbnx_adapter/adapter.py b/adbnx_adapter/adapter.py index 58b4cef..4fc75f8 100644 --- a/adbnx_adapter/adapter.py +++ b/adbnx_adapter/adapter.py @@ -446,13 +446,9 @@ def __fetch_adb_docs( """ aql_return_value = "doc" if explicit_metagraph: - edge_keys = "_from: doc._from, _to: doc._to" if is_edge else "" - aql_return_value = f""" - MERGE( - KEEP(doc, {list(attributes)}), - {{"_id": doc._id, {edge_keys}}} - ) - """ + default_keys = ["_id", "_key"] + default_keys += ["_from", "_to"] if is_edge else [] + aql_return_value = f"KEEP(doc, {list(attributes) + default_keys})" col_size: int = self.__db.collection(col).count()