Skip to content

Commit 3e44cc4

Browse files
Merge pull request #374 from soerenreichardt/arrow-remote-projection-test2
Add test for remote projection
2 parents 20ac789 + cb10fcb commit 3e44cc4

File tree

7 files changed

+93
-5
lines changed

7 files changed

+93
-5
lines changed
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
from typing import Any
1+
from typing import Any, Tuple
22

33
from pandas import Series
44

55
from graphdatascience.error.illegal_attr_checker import IllegalAttrChecker
6+
from graphdatascience.graph.graph_object import Graph
67
from graphdatascience.server_version.compatible_with import compatible_with
78
from graphdatascience.server_version.server_version import ServerVersion
89

910

1011
class GraphAlphaProjectRunner(IllegalAttrChecker):
1112
@compatible_with("remote", min_inclusive=ServerVersion(2, 4, 0))
12-
def remote(self, graph_name: str, query: str, remote_database: str, **config: Any) -> "Series[Any]":
13+
def remote(self, graph_name: str, query: str, remote_database: str, **config: Any) -> Tuple[Graph, "Series[Any]"]:
1314
self._namespace += ".remote"
14-
query = f"CALL {self._namespace}($graph_name, $query, $token, $host, $remote_database, $config)"
15+
procedure_query = f"CALL {self._namespace}($graph_name, $query, $token, $host, $remote_database, $config)"
1516
params = {"graph_name": graph_name, "query": query, "remote_database": remote_database, "config": config}
16-
return self._query_runner.run_query(query, params).squeeze() # type: ignore
17+
result = self._query_runner.run_query(procedure_query, params).squeeze()
18+
return Graph(graph_name, self._query_runner, self._server_version), result

graphdatascience/query_runner/aura_db_arrow_query_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def run_query(
6464
token, aura_db_arrow_endpoint = self._get_or_request_auth_pair()
6565
params["token"] = token
6666
params["host"] = aura_db_arrow_endpoint
67+
params["config"] = {"useEncryption": False}
6768

6869
return self._fallback_query_runner.run_query(query, params, database, custom_error)
6970

graphdatascience/tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ def pytest_addoption(parser: Any) -> None:
1313
)
1414
parser.addoption("--target-aura", action="store_true", help="the database targeted is an AuraDS instance")
1515
parser.addoption("--include-ogb", action="store_true", help="include tests requiring the ogb dependency")
16+
parser.addoption(
17+
"--include-cloud-architecture", action="store_true", help="include tests resuiring a cloud architecture setup"
18+
)

graphdatascience/tests/integration/conftest.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import os
22
from pathlib import Path
3-
from typing import Any, Generator
3+
from typing import Any, Generator, Optional
44

55
import pytest
66
from neo4j import Driver, GraphDatabase
77

88
from graphdatascience.graph_data_science import GraphDataScience
9+
from graphdatascience.query_runner.aura_db_arrow_query_runner import (
10+
AuraDbConnectionInfo,
11+
)
912
from graphdatascience.query_runner.neo4j_query_runner import Neo4jQueryRunner
1013

1114
URI = os.environ.get("NEO4J_URI", "bolt://localhost:7687")
@@ -20,6 +23,9 @@
2023

2124
DB = os.environ.get("NEO4J_DB", "neo4j")
2225

26+
AURA_DB_URI = os.environ.get("NEO4J_AURA_DB_URI", "bolt://localhost:7689")
27+
AURA_DB_AUTH = ("neo4j", "password")
28+
2329

2430
@pytest.fixture(scope="package")
2531
def neo4j_driver() -> Generator[Driver, None, None]:
@@ -38,6 +44,16 @@ def runner(neo4j_driver: Driver) -> Neo4jQueryRunner:
3844
return _runner
3945

4046

47+
@pytest.fixture(scope="package", autouse=False)
48+
def auradb_runner() -> Neo4jQueryRunner:
49+
driver = GraphDatabase.driver(AURA_DB_URI, auth=AURA_DB_AUTH)
50+
51+
_runner = Neo4jQueryRunner(driver)
52+
_runner.set_database(DB)
53+
54+
return _runner
55+
56+
4157
@pytest.fixture(scope="package")
4258
def gds() -> GraphDataScience:
4359
_gds = GraphDataScience(URI, auth=AUTH)
@@ -74,6 +90,18 @@ def gds_without_arrow() -> GraphDataScience:
7490
return _gds
7591

7692

93+
@pytest.fixture(scope="package", autouse=False)
94+
def gds_with_cloud_setup(request: pytest.FixtureRequest) -> Optional[GraphDataScience]:
95+
if "cloud_architecture" not in request.keywords:
96+
_gds = GraphDataScience(
97+
URI, auth=AUTH, arrow=True, aura_db_connection_info=AuraDbConnectionInfo(AURA_DB_URI, AURA_DB_AUTH)
98+
)
99+
_gds.set_database(DB)
100+
101+
return _gds
102+
return None
103+
104+
77105
@pytest.fixture(autouse=True)
78106
def clean_up(gds: GraphDataScience) -> Generator[None, None, None]:
79107
yield
@@ -139,6 +167,12 @@ def pytest_collection_modifyitems(config: Any, items: Any) -> None:
139167
if "model_store_location" in item.keywords:
140168
item.add_marker(skip_stored_models)
141169

170+
if not config.getoption("--include-cloud-architecture"):
171+
skip_on_prem = pytest.mark.skip(reason="need --include-cloud-architecture option to run")
172+
for item in items:
173+
if "cloud_architecture" in item.keywords:
174+
item.add_marker(skip_on_prem)
175+
142176
try:
143177
server_version = GraphDataScience(URI, auth=AUTH)._server_version
144178
except Exception as e:
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from typing import Generator
2+
3+
import pytest
4+
5+
from graphdatascience import GraphDataScience
6+
from graphdatascience.query_runner.neo4j_query_runner import Neo4jQueryRunner
7+
from graphdatascience.server_version.server_version import ServerVersion
8+
9+
GRAPH_NAME = "g"
10+
11+
12+
@pytest.fixture(autouse=True, scope="class")
13+
def run_around_tests(
14+
auradb_runner: Neo4jQueryRunner, gds_with_cloud_setup: GraphDataScience
15+
) -> Generator[None, None, None]:
16+
# Runs before each test
17+
auradb_runner.run_query(
18+
"""
19+
CREATE
20+
(a: Node {x: 1, y: 2, z: [42], name: "nodeA"}),
21+
(b: Node {x: 2, y: 3, z: [1337], name: "nodeB"}),
22+
(c: Node {x: 3, y: 4, z: [9], name: "nodeC"}),
23+
(a)-[:REL {relX: 4, relY: 5}]->(b),
24+
(a)-[:REL {relX: 5, relY: 6}]->(c),
25+
(b)-[:REL {relX: 6, relY: 7}]->(c),
26+
(b)-[:REL2]->(c)
27+
"""
28+
)
29+
30+
yield # Test runs here
31+
32+
# Runs after each test
33+
auradb_runner.run_query("MATCH (n) DETACH DELETE n")
34+
gds_with_cloud_setup._query_runner.run_query(f"CALL gds.graph.drop('{GRAPH_NAME}', false)")
35+
36+
37+
@pytest.mark.cloud_architecture
38+
@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 4, 0))
39+
def test_remote_projection(gds_with_cloud_setup: GraphDataScience) -> None:
40+
G, result = gds_with_cloud_setup.alpha.graph.project.remote(
41+
GRAPH_NAME, "MATCH (n)-->(m) RETURN n as sourceNode, m as targetNode", "neo4j"
42+
)
43+
44+
assert G.name() == GRAPH_NAME
45+
assert result["nodeCount"] == 3

graphdatascience/tests/pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ markers =
77
skip_on_aura: mark a test to not be run when targeting an AuraDS instance
88
only_on_aura: mark a test to be run only when targeting an AuraDS instance
99
ogb: mark a test as requiring the ogb dependency
10+
cloud_architecture: mark a test to require a cloud setup like environment

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ passenv =
2828
NEO4J_USER
2929
NEO4J_PASSWORD
3030
NEO4J_DB
31+
NEO4J_AURA_DB_URI
3132
allowlist_externals =
3233
ruby
3334
bash
@@ -55,6 +56,7 @@ commands =
5556
aura: pytest graphdatascience/tests --include-enterprise --target-aura -Werror
5657
ogb: pytest graphdatascience/tests --include-enterprise --include-ogb -Werror
5758
nx: bash -ec 'pytest graphdatascience/tests/*/test_nx_loader.py --include-enterprise -Werror && ruby ./doc/tests/test_docs.rb python3 -n test_networkx'
59+
cloud-architecture: pytest graphdatascience/tests --include-cloud-architecture -Werror
5860
rm -rf {envdir}/lib
5961

6062
[testenv:jupyter-notebook-ci]

0 commit comments

Comments
 (0)