graphdatascience 2.0a5__py3-none-any.whl → 2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- graphdatascience/arrow_client/arrow_endpoint_version.py +3 -1
- graphdatascience/arrow_client/arrow_info.py +19 -6
- graphdatascience/arrow_client/authenticated_flight_client.py +97 -18
- graphdatascience/arrow_client/v2/job_client.py +33 -7
- graphdatascience/error/not_available_outside_aura.py +5 -0
- graphdatascience/graph/graph_info.py +9 -0
- graphdatascience/graph_data_science.py +101 -9
- graphdatascience/procedure_surface/api/base_result.py +18 -0
- graphdatascience/procedure_surface/api/catalog/catalog_endpoints.py +11 -1
- graphdatascience/procedure_surface/api/catalog/node_properties_endpoints.py +4 -4
- graphdatascience/procedure_surface/api/catalog/node_property_endpoints.py +5 -1
- graphdatascience/procedure_surface/api/catalog/relationship_properties_endpoints.py +5 -1
- graphdatascience/procedure_surface/api/catalog/relationship_property_endpoints.py +5 -1
- graphdatascience/procedure_surface/api/catalog/relationships_endpoints.py +24 -3
- graphdatascience/procedure_surface/api/centrality/closeness_endpoints.py +9 -0
- graphdatascience/procedure_surface/api/centrality/hits_endpoints.py +38 -2
- graphdatascience/procedure_surface/api/descriptions.py +3 -0
- graphdatascience/procedure_surface/api/job_handle.py +1 -1
- graphdatascience/procedure_surface/api/node_embedding/__init__.py +55 -1
- graphdatascience/procedure_surface/api/node_embedding/config.py +81 -0
- graphdatascience/procedure_surface/api/node_embedding/embedding_endpoints.py +150 -0
- graphdatascience/procedure_surface/api/node_embedding/fastpath_endpoints.py +2 -0
- graphdatascience/procedure_surface/api/node_embedding/graphsage_endpoints.py +49 -1
- graphdatascience/procedure_surface/api/node_embedding/graphsage_results.py +51 -0
- graphdatascience/procedure_surface/api/node_embedding/graphsage_supervised_endpoints.py +242 -0
- graphdatascience/procedure_surface/api/node_embedding/graphsage_supervised_model.py +193 -0
- graphdatascience/procedure_surface/api/node_embedding/graphsage_train_endpoints.py +1 -1
- graphdatascience/procedure_surface/api/node_embedding/graphsage_unsupervised_endpoints.py +233 -0
- graphdatascience/procedure_surface/api/node_embedding/graphsage_unsupervised_model.py +185 -0
- graphdatascience/procedure_surface/api/node_embedding/hashgnn_endpoints.py +4 -4
- graphdatascience/procedure_surface/api/pipeline/link_prediction_pipeline_endpoints.py +20 -0
- graphdatascience/procedure_surface/api/pipeline/node_classification_pipeline_endpoints.py +20 -0
- graphdatascience/procedure_surface/api/pipeline/node_regression_pipeline.py +1 -1
- graphdatascience/procedure_surface/api/pipeline/node_regression_pipeline_endpoints.py +20 -1
- graphdatascience/procedure_surface/api/topological_link_prediction_endpoints.py +32 -16
- graphdatascience/procedure_surface/api/write_job_handle.py +1 -1
- graphdatascience/procedure_surface/api/write_protocol.py +34 -0
- graphdatascience/procedure_surface/arrow/catalog/catalog_arrow_endpoints.py +9 -8
- graphdatascience/procedure_surface/arrow/catalog/node_properties_arrow_endpoints.py +2 -2
- graphdatascience/procedure_surface/arrow/catalog/relationship_arrow_endpoints.py +10 -2
- graphdatascience/procedure_surface/arrow/centrality/closeness_arrow_endpoints.py +11 -0
- graphdatascience/procedure_surface/arrow/centrality/hits_arrow_endpoints.py +253 -0
- graphdatascience/procedure_surface/arrow/node_embedding/embedding_arrow_endpoints.py +105 -0
- graphdatascience/procedure_surface/arrow/node_embedding/fastpath_arrow_endpoints.py +4 -0
- graphdatascience/procedure_surface/arrow/node_embedding/graphsage_supervised_arrow_endpoints.py +205 -0
- graphdatascience/procedure_surface/arrow/node_embedding/graphsage_train_arrow_endpoints.py +4 -1
- graphdatascience/procedure_surface/arrow/node_embedding/graphsage_unsupervised_arrow_endpoints.py +182 -0
- graphdatascience/procedure_surface/arrow/pipeline/link_prediction_pipeline_arrow_endpoints.py +11 -0
- graphdatascience/procedure_surface/arrow/pipeline/node_classification_pipeline_arrow_endpoints.py +11 -0
- graphdatascience/procedure_surface/arrow/pipeline/node_regression_pipeline_arrow_endpoints.py +10 -0
- graphdatascience/procedure_surface/arrow/stream_result_mapper.py +11 -0
- graphdatascience/procedure_surface/cypher/catalog/catalog_cypher_endpoints.py +10 -12
- graphdatascience/procedure_surface/cypher/catalog/node_properties_cypher_endpoints.py +4 -3
- graphdatascience/procedure_surface/cypher/catalog/projection_cypher_endpoints.py +11 -2
- graphdatascience/procedure_surface/cypher/catalog/relationship_cypher_endpoints.py +7 -5
- graphdatascience/procedure_surface/cypher/centrality/closeness_cypher_endpoints.py +8 -0
- graphdatascience/procedure_surface/cypher/centrality/hits_cypher_endpoints.py +28 -0
- graphdatascience/procedure_surface/cypher/pipeline/link_prediction_pipeline_cypher_endpoints.py +13 -0
- graphdatascience/procedure_surface/cypher/pipeline/node_classification_pipeline_cypher_endpoints.py +13 -0
- graphdatascience/procedure_surface/cypher/pipeline/node_regression_pipeline_cypher_endpoints.py +12 -1
- graphdatascience/procedure_surface/cypher/topological_link_prediction_cypher_endpoints.py +8 -6
- graphdatascience/query_runner/db_environment_resolver.py +2 -2
- graphdatascience/query_runner/neo4j_query_runner.py +12 -0
- graphdatascience/query_runner/query_mode.py +24 -3
- graphdatascience/query_runner/query_runner.py +11 -0
- graphdatascience/session/aura_api.py +16 -0
- graphdatascience/session/aura_api_responses.py +13 -0
- graphdatascience/session/aura_graph_data_science.py +127 -11
- graphdatascience/session/endpoint_mappings.py +0 -6
- graphdatascience/session/gds_sessions.py +10 -9
- graphdatascience/session/remote_ops/project_protocols.py +5 -1
- graphdatascience/session/remote_ops/write_protocols.py +44 -43
- graphdatascience/version.py +1 -1
- {graphdatascience-2.0a5.dist-info → graphdatascience-2.1.dist-info}/METADATA +56 -19
- {graphdatascience-2.0a5.dist-info → graphdatascience-2.1.dist-info}/RECORD +78 -65
- graphdatascience/procedure_surface/arrow/topological_link_prediction_arrow_endpoints.py +0 -65
- {graphdatascience-2.0a5.dist-info → graphdatascience-2.1.dist-info}/WHEEL +0 -0
- {graphdatascience-2.0a5.dist-info → graphdatascience-2.1.dist-info}/licenses/LICENSE +0 -0
- {graphdatascience-2.0a5.dist-info → graphdatascience-2.1.dist-info}/top_level.txt +0 -0
|
@@ -19,7 +19,9 @@ class ArrowEndpointVersion(Enum):
|
|
|
19
19
|
def check_version_compatibility(
|
|
20
20
|
compatible_versions: set[ArrowEndpointVersion], arrow_client: AuthenticatedArrowClient
|
|
21
21
|
) -> None:
|
|
22
|
-
supported_server_versions = {
|
|
22
|
+
supported_server_versions = {
|
|
23
|
+
action.type.split("/")[0].lower() for action in arrow_client.list_actions_with_retry()
|
|
24
|
+
}
|
|
23
25
|
for version in compatible_versions:
|
|
24
26
|
if version.version() in supported_server_versions:
|
|
25
27
|
return
|
|
@@ -2,6 +2,8 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from dataclasses import dataclass
|
|
4
4
|
|
|
5
|
+
from neo4j.exceptions import Neo4jError
|
|
6
|
+
|
|
5
7
|
from graphdatascience.query_runner.query_runner import QueryRunner
|
|
6
8
|
from graphdatascience.query_runner.query_type import QueryType
|
|
7
9
|
|
|
@@ -15,12 +17,17 @@ class ArrowInfo:
|
|
|
15
17
|
|
|
16
18
|
@staticmethod
|
|
17
19
|
def create(query_runner: QueryRunner) -> ArrowInfo:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
try:
|
|
21
|
+
procResult = query_runner.call_procedure(
|
|
22
|
+
endpoint="gds.debug.arrow",
|
|
23
|
+
query_type=QueryType.SYSTEM,
|
|
24
|
+
custom_error=False,
|
|
25
|
+
yields=["listenAddress", "enabled", "running", "versions"],
|
|
26
|
+
).iloc[0]
|
|
27
|
+
except Neo4jError as e:
|
|
28
|
+
if ArrowInfo._procedure_not_registered(e):
|
|
29
|
+
return ArrowInfo(listenAddress="", enabled=False, running=False, versions=[])
|
|
30
|
+
raise
|
|
24
31
|
|
|
25
32
|
return ArrowInfo(
|
|
26
33
|
listenAddress=procResult["listenAddress"],
|
|
@@ -28,3 +35,9 @@ class ArrowInfo:
|
|
|
28
35
|
running=procResult["running"],
|
|
29
36
|
versions=procResult.get("versions", []),
|
|
30
37
|
)
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def _procedure_not_registered(e: Neo4jError) -> bool:
|
|
41
|
+
return e.code == "Neo.ClientError.Procedure.ProcedureNotFound" or (
|
|
42
|
+
"no procedure with the name `gds.debug.arrow`" in e.message
|
|
43
|
+
)
|
|
@@ -2,7 +2,9 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
4
|
import logging
|
|
5
|
+
import math
|
|
5
6
|
import platform
|
|
7
|
+
import socket
|
|
6
8
|
from dataclasses import dataclass
|
|
7
9
|
from types import TracebackType
|
|
8
10
|
from typing import Any, Callable, Iterator, Type, TypeVar
|
|
@@ -13,6 +15,7 @@ from pyarrow import __version__ as arrow_version
|
|
|
13
15
|
from pyarrow.flight import (
|
|
14
16
|
Action,
|
|
15
17
|
ActionType,
|
|
18
|
+
FlightCallOptions,
|
|
16
19
|
FlightInternalError,
|
|
17
20
|
FlightStreamReader,
|
|
18
21
|
FlightTimedOutError,
|
|
@@ -32,6 +35,31 @@ from .middleware.user_agent_middleware import UserAgentFactory
|
|
|
32
35
|
|
|
33
36
|
T = TypeVar("T")
|
|
34
37
|
|
|
38
|
+
FLIGHT_TRANSIENT_EXCEPTIONS = (
|
|
39
|
+
FlightTimedOutError,
|
|
40
|
+
FlightUnavailableError,
|
|
41
|
+
FlightInternalError,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
DEFAULT_MAX_ATTEMPTS = 5
|
|
45
|
+
DEFAULT_CALL_TIMEOUT = 30.0
|
|
46
|
+
# Sum of the backoff waits between DEFAULT_MAX_ATTEMPTS attempts under the default
|
|
47
|
+
# wait config `ExponentialWaitConfig(multiplier=1, min=1, max=10)`: 1 + 2 + 4 + 8.
|
|
48
|
+
DEFAULT_BACKOFF_TOTAL = 15
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _default_retry_config(call_timeout: float | None) -> RetryConfigV2:
|
|
52
|
+
# The delay budget must fit all attempts even when every single one runs into the
|
|
53
|
+
# per-call deadline, plus the backoff waits in between. Otherwise one
|
|
54
|
+
# `Deadline Exceeded` exhausts the budget and no retry ever happens.
|
|
55
|
+
budget_timeout = call_timeout if call_timeout is not None else DEFAULT_CALL_TIMEOUT
|
|
56
|
+
after_delay = math.ceil(DEFAULT_MAX_ATTEMPTS * budget_timeout + DEFAULT_BACKOFF_TOTAL)
|
|
57
|
+
return RetryConfigV2(
|
|
58
|
+
retryable_exceptions=list(FLIGHT_TRANSIENT_EXCEPTIONS),
|
|
59
|
+
stop_config=StopConfig(after_delay=after_delay, after_attempt=DEFAULT_MAX_ATTEMPTS),
|
|
60
|
+
wait_config=ExponentialWaitConfig(multiplier=1, min=1, max=10),
|
|
61
|
+
)
|
|
62
|
+
|
|
35
63
|
|
|
36
64
|
class AuthenticatedArrowClient:
|
|
37
65
|
"""Arrow Flight client used to communicate with the GDS Arrow server."""
|
|
@@ -58,11 +86,15 @@ class AuthenticatedArrowClient:
|
|
|
58
86
|
encrypted
|
|
59
87
|
A flag that indicates whether the connection should be encrypted (default is False)
|
|
60
88
|
arrow_client_options
|
|
61
|
-
Additional options
|
|
89
|
+
Additional options for the Arrow Flight client. The key ``call_timeout`` sets the
|
|
90
|
+
per-call RPC timeout in seconds (default 30s); all other keys are forwarded to
|
|
91
|
+
``pyarrow.flight.FlightClient``.
|
|
62
92
|
user_agent
|
|
63
93
|
The user agent string to use for the connection. (default is `neo4j-graphdatascience-v[VERSION] pyarrow-v[PYARROW_VERSION]`)
|
|
64
94
|
retry_config
|
|
65
95
|
The retry configuration to use for the Arrow requests send by the client.
|
|
96
|
+
(default: up to 5 attempts with a total delay budget derived from the
|
|
97
|
+
per-call ``call_timeout`` so that timed-out calls are actually retried)
|
|
66
98
|
advertised_listen_address
|
|
67
99
|
The advertised listen address of the GDS Arrow server. This will be used by remote projection and writeback operations.
|
|
68
100
|
health_check
|
|
@@ -76,28 +108,25 @@ class AuthenticatedArrowClient:
|
|
|
76
108
|
else:
|
|
77
109
|
host, port = connection_info
|
|
78
110
|
|
|
111
|
+
options_copy = dict(arrow_client_options) if arrow_client_options else {}
|
|
112
|
+
call_timeout = options_copy.pop("call_timeout", DEFAULT_CALL_TIMEOUT)
|
|
113
|
+
|
|
79
114
|
if retry_config is None:
|
|
80
|
-
retry_config =
|
|
81
|
-
retryable_exceptions=[
|
|
82
|
-
FlightTimedOutError,
|
|
83
|
-
FlightUnavailableError,
|
|
84
|
-
FlightInternalError,
|
|
85
|
-
],
|
|
86
|
-
stop_config=StopConfig(after_delay=10, after_attempt=5),
|
|
87
|
-
wait_config=ExponentialWaitConfig(multiplier=1, min=1, max=10),
|
|
88
|
-
)
|
|
115
|
+
retry_config = _default_retry_config(call_timeout)
|
|
89
116
|
|
|
90
117
|
self._host = host
|
|
91
118
|
self._port = int(port)
|
|
92
119
|
self._auth = auth
|
|
93
120
|
self._encrypted = encrypted
|
|
94
|
-
self._arrow_client_options =
|
|
121
|
+
self._arrow_client_options = options_copy or None
|
|
95
122
|
self._user_agent = user_agent
|
|
96
123
|
self._logger = logging.getLogger("gds_arrow_client")
|
|
97
124
|
self._retry_config = retry_config
|
|
98
125
|
self._health_check = health_check
|
|
99
126
|
if auth:
|
|
100
127
|
self._auth_middleware = AuthMiddleware(auth)
|
|
128
|
+
self._call_timeout = call_timeout
|
|
129
|
+
self._call_options = self._build_call_options()
|
|
101
130
|
self.advertised_listen_address = advertised_listen_address
|
|
102
131
|
self._flight_client: flight.FlightClient = self._instantiate_flight_client()
|
|
103
132
|
|
|
@@ -143,8 +172,8 @@ class AuthenticatedArrowClient:
|
|
|
143
172
|
client = self._flight_client
|
|
144
173
|
if self._auth:
|
|
145
174
|
auth_pair = self._auth.auth_pair()
|
|
146
|
-
client.authenticate_basic_token(auth_pair[0], auth_pair[1])
|
|
147
|
-
except
|
|
175
|
+
client.authenticate_basic_token(auth_pair[0], auth_pair[1], self._call_options)
|
|
176
|
+
except FLIGHT_TRANSIENT_EXCEPTIONS:
|
|
148
177
|
self._reconnect()
|
|
149
178
|
raise
|
|
150
179
|
|
|
@@ -160,7 +189,7 @@ class AuthenticatedArrowClient:
|
|
|
160
189
|
def do_action(self, endpoint: str, payload: bytes | dict[str, Any]) -> Iterator[Result]:
|
|
161
190
|
payload_bytes = payload if isinstance(payload, bytes) else json.dumps(payload).encode("utf-8")
|
|
162
191
|
|
|
163
|
-
return self._flight_client.do_action(Action(endpoint, payload_bytes)) # type: ignore
|
|
192
|
+
return self._flight_client.do_action(Action(endpoint, payload_bytes), self._call_options) # type: ignore
|
|
164
193
|
|
|
165
194
|
def do_action_with_retry(self, endpoint: str, payload: bytes | dict[str, Any]) -> list[Result]:
|
|
166
195
|
@self._retry_config.decorator(operation_name="Send action", logger=self._logger)
|
|
@@ -169,14 +198,25 @@ class AuthenticatedArrowClient:
|
|
|
169
198
|
# the Flight response error code is only checked on iterator consumption
|
|
170
199
|
# we eagerly collect iterator here to trigger retry in case of an error
|
|
171
200
|
return list(self.do_action(endpoint, payload))
|
|
172
|
-
except
|
|
201
|
+
except FLIGHT_TRANSIENT_EXCEPTIONS:
|
|
173
202
|
self._reconnect()
|
|
174
203
|
raise
|
|
175
204
|
|
|
176
205
|
return self._diagnose_connection_failure(run_with_retry)
|
|
177
206
|
|
|
178
207
|
def list_actions(self) -> set[ActionType]:
|
|
179
|
-
return self._flight_client.list_actions() # type: ignore
|
|
208
|
+
return self._flight_client.list_actions(self._call_options) # type: ignore
|
|
209
|
+
|
|
210
|
+
def list_actions_with_retry(self) -> set[ActionType]:
|
|
211
|
+
@self._retry_config.decorator(operation_name="List actions", logger=self._logger)
|
|
212
|
+
def run_with_retry() -> set[ActionType]:
|
|
213
|
+
try:
|
|
214
|
+
return self.list_actions()
|
|
215
|
+
except (FlightTimedOutError, FlightUnavailableError, FlightInternalError):
|
|
216
|
+
self._reconnect()
|
|
217
|
+
raise
|
|
218
|
+
|
|
219
|
+
return self._diagnose_connection_failure(run_with_retry)
|
|
180
220
|
|
|
181
221
|
def do_put_with_retry(
|
|
182
222
|
self, descriptor: flight.FlightDescriptor, schema: Schema
|
|
@@ -185,7 +225,7 @@ class AuthenticatedArrowClient:
|
|
|
185
225
|
def run_with_retry() -> tuple[flight.FlightStreamWriter, flight.FlightMetadataReader]:
|
|
186
226
|
try:
|
|
187
227
|
return self._flight_client.do_put(descriptor, schema) # type: ignore
|
|
188
|
-
except
|
|
228
|
+
except FLIGHT_TRANSIENT_EXCEPTIONS:
|
|
189
229
|
self._reconnect()
|
|
190
230
|
raise
|
|
191
231
|
|
|
@@ -198,11 +238,42 @@ class AuthenticatedArrowClient:
|
|
|
198
238
|
"""
|
|
199
239
|
try:
|
|
200
240
|
return operation()
|
|
201
|
-
except
|
|
241
|
+
except FLIGHT_TRANSIENT_EXCEPTIONS as e:
|
|
202
242
|
if self._health_check:
|
|
203
243
|
self._health_check.raise_if_unhealthy()
|
|
244
|
+
self._raise_if_grpc_dns_resolver_failed(e)
|
|
204
245
|
raise
|
|
205
246
|
|
|
247
|
+
def _raise_if_grpc_dns_resolver_failed(self, error: Exception) -> None:
|
|
248
|
+
"""
|
|
249
|
+
gRPC uses the c-ares DNS resolver that talks directly to the configured nameserver.
|
|
250
|
+
Behind local DNS proxies such as Cloudflare WARP or some VPN clients those queries go unanswered
|
|
251
|
+
while the OS resolver works fine. If gRPC failed to resolve the host but the OS resolver can,
|
|
252
|
+
point the user at the `GRPC_DNS_RESOLVER=native` workaround.
|
|
253
|
+
"""
|
|
254
|
+
if not isinstance(error, FlightUnavailableError):
|
|
255
|
+
return
|
|
256
|
+
message = str(error)
|
|
257
|
+
if "address lookup failed" not in message and "errors resolving" not in message:
|
|
258
|
+
return
|
|
259
|
+
if not self._os_resolver_can_resolve_host():
|
|
260
|
+
return
|
|
261
|
+
|
|
262
|
+
raise ConnectionError(
|
|
263
|
+
f"gRPC could not resolve the Arrow server host `{self._host}`, but the operating system resolver can. "
|
|
264
|
+
"This usually happens when a local DNS proxy (e.g. Cloudflare WARP or a VPN client) does not answer "
|
|
265
|
+
"the queries of gRPC's built-in resolver. "
|
|
266
|
+
"Set the environment variable `GRPC_DNS_RESOLVER=native` before importing `graphdatascience` "
|
|
267
|
+
"(for example via `os.environ['GRPC_DNS_RESOLVER'] = 'native'`) to make gRPC use the operating system resolver."
|
|
268
|
+
) from error
|
|
269
|
+
|
|
270
|
+
def _os_resolver_can_resolve_host(self) -> bool:
|
|
271
|
+
try:
|
|
272
|
+
socket.getaddrinfo(self._host, self._port)
|
|
273
|
+
return True
|
|
274
|
+
except OSError:
|
|
275
|
+
return False
|
|
276
|
+
|
|
206
277
|
def __enter__(self) -> AuthenticatedArrowClient:
|
|
207
278
|
return self
|
|
208
279
|
|
|
@@ -218,6 +289,9 @@ class AuthenticatedArrowClient:
|
|
|
218
289
|
if self._flight_client:
|
|
219
290
|
self._flight_client.close()
|
|
220
291
|
|
|
292
|
+
def _build_call_options(self) -> FlightCallOptions | None:
|
|
293
|
+
return FlightCallOptions(timeout=self._call_timeout) if self._call_timeout is not None else None
|
|
294
|
+
|
|
221
295
|
def _instantiate_flight_client(self) -> flight.FlightClient:
|
|
222
296
|
location = (
|
|
223
297
|
flight.Location.for_grpc_tls(self._host, self._port)
|
|
@@ -248,11 +322,16 @@ class AuthenticatedArrowClient:
|
|
|
248
322
|
# Remove the FlightClient as it isn't serializable
|
|
249
323
|
if "_flight_client" in state:
|
|
250
324
|
del state["_flight_client"]
|
|
325
|
+
# FlightCallOptions is also not serializable
|
|
326
|
+
if "_call_options" in state:
|
|
327
|
+
del state["_call_options"]
|
|
251
328
|
return state
|
|
252
329
|
|
|
253
330
|
def __setstate__(self, state: dict[str, Any]) -> None:
|
|
254
331
|
self.__dict__.update(state)
|
|
255
332
|
self.__dict__.setdefault("_health_check", None)
|
|
333
|
+
self.__dict__.setdefault("_call_timeout", DEFAULT_CALL_TIMEOUT)
|
|
334
|
+
self.__dict__.setdefault("_call_options", self._build_call_options())
|
|
256
335
|
self._flight_client = self._instantiate_flight_client()
|
|
257
336
|
|
|
258
337
|
def _reconnect(self) -> None:
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import logging
|
|
3
|
+
import uuid
|
|
2
4
|
from typing import Any
|
|
3
5
|
|
|
4
6
|
from pandas import ArrowDtype, DataFrame
|
|
7
|
+
from pyarrow import ArrowKeyError
|
|
5
8
|
from pyarrow.flight import Ticket
|
|
6
|
-
from tenacity import Retrying, retry_if_result
|
|
9
|
+
from tenacity import Retrying, retry_if_exception, retry_if_result, stop_after_attempt, wait_fixed
|
|
7
10
|
|
|
8
|
-
from graphdatascience.arrow_client.authenticated_flight_client import
|
|
11
|
+
from graphdatascience.arrow_client.authenticated_flight_client import (
|
|
12
|
+
FLIGHT_TRANSIENT_EXCEPTIONS,
|
|
13
|
+
AuthenticatedArrowClient,
|
|
14
|
+
)
|
|
9
15
|
from graphdatascience.arrow_client.v2.api_types import JobIdConfig, JobStatus
|
|
10
16
|
from graphdatascience.arrow_client.v2.data_mapper_utils import deserialize_single
|
|
11
17
|
from graphdatascience.progress.progress_bar import TqdmProgressBar
|
|
12
18
|
from graphdatascience.query_runner.termination_flag import TerminationFlag
|
|
13
|
-
from graphdatascience.retry_utils.retry_utils import job_wait_strategy
|
|
19
|
+
from graphdatascience.retry_utils.retry_utils import before_log, job_wait_strategy
|
|
14
20
|
|
|
15
21
|
JOB_STATUS_ENDPOINT = "v2/jobs.status"
|
|
16
22
|
JOBS_CANCEL_ENDPOINT = "v2/jobs.cancel"
|
|
@@ -31,10 +37,30 @@ class JobClient:
|
|
|
31
37
|
|
|
32
38
|
@staticmethod
|
|
33
39
|
def run_job(client: AuthenticatedArrowClient, endpoint: str, config: dict[str, Any]) -> str:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
job_id: str = config.setdefault("jobId", str(uuid.uuid4()))
|
|
41
|
+
logger = logging.getLogger(__name__)
|
|
42
|
+
|
|
43
|
+
for attempt in Retrying(
|
|
44
|
+
stop=stop_after_attempt(3),
|
|
45
|
+
wait=wait_fixed(2),
|
|
46
|
+
retry=retry_if_exception(lambda e: isinstance(e, FLIGHT_TRANSIENT_EXCEPTIONS)),
|
|
47
|
+
before=before_log(f"run_job ({endpoint})", logger, logging.DEBUG),
|
|
48
|
+
reraise=True,
|
|
49
|
+
):
|
|
50
|
+
with attempt:
|
|
51
|
+
try:
|
|
52
|
+
res = client.do_action_with_retry(endpoint, config)
|
|
53
|
+
return JobIdConfig(**deserialize_single(res)).job_id
|
|
54
|
+
except FLIGHT_TRANSIENT_EXCEPTIONS as e:
|
|
55
|
+
try:
|
|
56
|
+
JobClient.get_job_status(client, job_id)
|
|
57
|
+
logger.debug(f"Job '{job_id}' already started, recovering job_id.")
|
|
58
|
+
return job_id
|
|
59
|
+
except ArrowKeyError:
|
|
60
|
+
logger.debug(f"Job '{job_id}' not found on server, will retry run_job.")
|
|
61
|
+
raise e
|
|
62
|
+
|
|
63
|
+
raise RuntimeError("unreachable due to retry logic above")
|
|
38
64
|
|
|
39
65
|
def wait_for_job(
|
|
40
66
|
self,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import math
|
|
3
4
|
import re
|
|
4
5
|
from datetime import datetime
|
|
5
6
|
from typing import Any
|
|
@@ -24,6 +25,14 @@ class GraphInfo(BaseResult):
|
|
|
24
25
|
graph_schema: dict[str, Any] = Field(alias="schemaWithOrientation")
|
|
25
26
|
density: float
|
|
26
27
|
|
|
28
|
+
@field_validator("memory_usage", mode="before")
|
|
29
|
+
@classmethod
|
|
30
|
+
def coerce_nan_to_none(cls, value: Any) -> Any:
|
|
31
|
+
# pandas transforms the memory_usage column with a null value to NaN
|
|
32
|
+
if isinstance(value, float) and math.isnan(value):
|
|
33
|
+
return None
|
|
34
|
+
return value
|
|
35
|
+
|
|
27
36
|
@field_validator("creation_time", "modification_time", mode="before")
|
|
28
37
|
@classmethod
|
|
29
38
|
def strip_timezone(cls, value: Any) -> Any:
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import warnings
|
|
4
4
|
from types import TracebackType
|
|
5
|
-
from typing import Any, Type
|
|
5
|
+
from typing import Any, Literal, Type
|
|
6
6
|
|
|
7
7
|
import neo4j
|
|
8
8
|
from neo4j import Driver
|
|
@@ -183,6 +183,7 @@ from graphdatascience.query_runner.query_mode import QueryMode
|
|
|
183
183
|
from graphdatascience.versions import ServerVersion
|
|
184
184
|
|
|
185
185
|
from .arrow_client.arrow_authentication import UsernamePasswordAuthentication
|
|
186
|
+
from .arrow_client.arrow_client_options_util import disable_server_verification
|
|
186
187
|
from .arrow_client.arrow_endpoint_version import ArrowEndpointVersion
|
|
187
188
|
from .arrow_client.arrow_info import ArrowInfo
|
|
188
189
|
from .arrow_client.authenticated_flight_client import AuthenticatedArrowClient
|
|
@@ -272,8 +273,15 @@ class GraphDataScience:
|
|
|
272
273
|
|
|
273
274
|
self._arrow_client: GdsArrowClient | None = None
|
|
274
275
|
|
|
275
|
-
|
|
276
|
-
|
|
276
|
+
if isinstance(arrow, str):
|
|
277
|
+
listen_address: str | None = arrow
|
|
278
|
+
elif arrow:
|
|
279
|
+
arrow_info = ArrowInfo.create(self._query_runner)
|
|
280
|
+
listen_address = arrow_info.listenAddress if arrow_info.enabled else None
|
|
281
|
+
else:
|
|
282
|
+
listen_address = None
|
|
283
|
+
|
|
284
|
+
if listen_address is not None:
|
|
277
285
|
arrow_auth = None
|
|
278
286
|
if auth is not None:
|
|
279
287
|
username, password = auth
|
|
@@ -287,14 +295,14 @@ class GraphDataScience:
|
|
|
287
295
|
"Falling back to use Cypher for GDS. To use Arrow, you must explicitly provide the `auth` parameter."
|
|
288
296
|
)
|
|
289
297
|
else:
|
|
290
|
-
listen_address = arrow if isinstance(arrow, str) else arrow_info.listenAddress
|
|
291
|
-
|
|
292
298
|
self._arrow_client = GdsArrowClient(
|
|
293
299
|
AuthenticatedArrowClient(
|
|
294
300
|
listen_address,
|
|
295
301
|
auth=arrow_auth,
|
|
296
302
|
encrypted=self._query_runner.encrypted(),
|
|
297
|
-
arrow_client_options=
|
|
303
|
+
arrow_client_options=GraphDataScience._derive_arrow_client_options(
|
|
304
|
+
endpoint, arrow_client_options
|
|
305
|
+
),
|
|
298
306
|
)
|
|
299
307
|
)
|
|
300
308
|
|
|
@@ -425,6 +433,13 @@ class GraphDataScience:
|
|
|
425
433
|
"""
|
|
426
434
|
return BetweennessCypherEndpoints(self._query_runner)
|
|
427
435
|
|
|
436
|
+
@property
|
|
437
|
+
def betweenness(self) -> BetweennessEndpoints:
|
|
438
|
+
"""
|
|
439
|
+
Return endpoints for the betweenness centrality algorithm.
|
|
440
|
+
"""
|
|
441
|
+
return self.betweenness_centrality
|
|
442
|
+
|
|
428
443
|
@property
|
|
429
444
|
def bridges(self) -> BridgesEndpoints:
|
|
430
445
|
"""
|
|
@@ -460,6 +475,13 @@ class GraphDataScience:
|
|
|
460
475
|
"""
|
|
461
476
|
return ClosenessCypherEndpoints(self._query_runner)
|
|
462
477
|
|
|
478
|
+
@property
|
|
479
|
+
def closeness(self) -> ClosenessEndpoints:
|
|
480
|
+
"""
|
|
481
|
+
Return endpoints for the closeness centrality algorithm.
|
|
482
|
+
"""
|
|
483
|
+
return self.closeness_centrality
|
|
484
|
+
|
|
463
485
|
@property
|
|
464
486
|
def dag(self) -> DagCypherEndpoints:
|
|
465
487
|
"""
|
|
@@ -474,6 +496,13 @@ class GraphDataScience:
|
|
|
474
496
|
"""
|
|
475
497
|
return DegreeCypherEndpoints(self._query_runner)
|
|
476
498
|
|
|
499
|
+
@property
|
|
500
|
+
def degree(self) -> DegreeEndpoints:
|
|
501
|
+
"""
|
|
502
|
+
Return endpoints for the degree centrality algorithm.
|
|
503
|
+
"""
|
|
504
|
+
return self.degree_centrality
|
|
505
|
+
|
|
477
506
|
@property
|
|
478
507
|
def eigenvector_centrality(self) -> EigenvectorEndpoints:
|
|
479
508
|
"""
|
|
@@ -481,6 +510,13 @@ class GraphDataScience:
|
|
|
481
510
|
"""
|
|
482
511
|
return EigenvectorCypherEndpoints(self._query_runner)
|
|
483
512
|
|
|
513
|
+
@property
|
|
514
|
+
def eigenvector(self) -> EigenvectorEndpoints:
|
|
515
|
+
"""
|
|
516
|
+
Return endpoints for the eigenvector centrality algorithm.
|
|
517
|
+
"""
|
|
518
|
+
return self.eigenvector_centrality
|
|
519
|
+
|
|
484
520
|
@property
|
|
485
521
|
def fast_rp(self) -> FastRPEndpoints:
|
|
486
522
|
"""
|
|
@@ -513,6 +549,13 @@ class GraphDataScience:
|
|
|
513
549
|
"""
|
|
514
550
|
return ClosenessHarmonicCypherEndpoints(self._query_runner)
|
|
515
551
|
|
|
552
|
+
@property
|
|
553
|
+
def harmonic(self) -> ClosenessHarmonicEndpoints:
|
|
554
|
+
"""
|
|
555
|
+
Return endpoints for the harmonic centrality algorithm.
|
|
556
|
+
"""
|
|
557
|
+
return self.harmonic_centrality
|
|
558
|
+
|
|
516
559
|
@property
|
|
517
560
|
def hash_gnn(self) -> HashGNNEndpoints:
|
|
518
561
|
"""
|
|
@@ -548,6 +591,13 @@ class GraphDataScience:
|
|
|
548
591
|
"""
|
|
549
592
|
return KCoreCypherEndpoints(self._query_runner)
|
|
550
593
|
|
|
594
|
+
@property
|
|
595
|
+
def kcore(self) -> KCoreEndpoints:
|
|
596
|
+
"""
|
|
597
|
+
Return endpoints for the K-core decomposition algorithm.
|
|
598
|
+
"""
|
|
599
|
+
return self.k_core_decomposition
|
|
600
|
+
|
|
551
601
|
@property
|
|
552
602
|
def kmeans(self) -> KMeansEndpoints:
|
|
553
603
|
"""
|
|
@@ -808,7 +858,8 @@ class GraphDataScience:
|
|
|
808
858
|
query: str,
|
|
809
859
|
params: dict[str, Any] | None = None,
|
|
810
860
|
database: str | None = None,
|
|
811
|
-
mode: QueryMode = QueryMode.WRITE,
|
|
861
|
+
mode: QueryMode | Literal["READ", "WRITE"] = QueryMode.WRITE,
|
|
862
|
+
auto_commit: bool = False,
|
|
812
863
|
) -> DataFrame:
|
|
813
864
|
"""
|
|
814
865
|
Run a Cypher query
|
|
@@ -821,8 +872,10 @@ class GraphDataScience:
|
|
|
821
872
|
parameters to the query
|
|
822
873
|
database: str
|
|
823
874
|
the database on which to run the query
|
|
824
|
-
mode
|
|
825
|
-
the query mode to use
|
|
875
|
+
mode
|
|
876
|
+
the query mode to use. Set based on the operation performed in the query.
|
|
877
|
+
auto_commit: bool
|
|
878
|
+
run the query in an auto-commit transaction. This is required for queries using `CALL { ... } IN TRANSACTIONS`.
|
|
826
879
|
|
|
827
880
|
Returns
|
|
828
881
|
-------
|
|
@@ -831,6 +884,11 @@ class GraphDataScience:
|
|
|
831
884
|
"""
|
|
832
885
|
query_type = QueryType.USER_DIRECTED
|
|
833
886
|
|
|
887
|
+
mode = QueryMode.of(mode)
|
|
888
|
+
|
|
889
|
+
if auto_commit:
|
|
890
|
+
return self._query_runner.run_cypher(query, query_type, params, database, mode, custom_error=False)
|
|
891
|
+
|
|
834
892
|
return self._query_runner.run_retryable_cypher(
|
|
835
893
|
query, query_type, params, database, custom_error=False, mode=mode
|
|
836
894
|
)
|
|
@@ -846,6 +904,23 @@ class GraphDataScience:
|
|
|
846
904
|
"""
|
|
847
905
|
return self._query_runner.driver_config()
|
|
848
906
|
|
|
907
|
+
def db_driver(self) -> neo4j.Driver:
|
|
908
|
+
"""
|
|
909
|
+
Get the Neo4j driver used by this client to communicate with the Neo4j DBMS.
|
|
910
|
+
|
|
911
|
+
This is mainly useful when the `run_cypher()` API is too simple for a use case,
|
|
912
|
+
as the driver allows full control over sessions and transactions.
|
|
913
|
+
|
|
914
|
+
The driver is closed by `close()` if the client created it itself, after which it is
|
|
915
|
+
unusable; a driver supplied at construction is never closed by this client.
|
|
916
|
+
|
|
917
|
+
Returns
|
|
918
|
+
-------
|
|
919
|
+
neo4j.Driver
|
|
920
|
+
The Neo4j driver used by this client.
|
|
921
|
+
"""
|
|
922
|
+
return self._query_runner.db_driver()
|
|
923
|
+
|
|
849
924
|
@staticmethod
|
|
850
925
|
def _derive_aura_ds(endpoint: str, auth: neo4j.Auth | None, database: str | None) -> bool:
|
|
851
926
|
# Whether a database is hosted in Aura can only be determined by connecting to it,
|
|
@@ -858,6 +933,23 @@ class GraphDataScience:
|
|
|
858
933
|
finally:
|
|
859
934
|
detection_runner.close()
|
|
860
935
|
|
|
936
|
+
@staticmethod
|
|
937
|
+
def _derive_arrow_client_options(
|
|
938
|
+
endpoint: str | Driver | QueryRunner, arrow_client_options: dict[str, Any] | None
|
|
939
|
+
) -> dict[str, Any] | None:
|
|
940
|
+
if not isinstance(endpoint, str):
|
|
941
|
+
return arrow_client_options
|
|
942
|
+
|
|
943
|
+
scheme = endpoint.split("://")[0].lower()
|
|
944
|
+
if not scheme.endswith("+ssc"):
|
|
945
|
+
return arrow_client_options
|
|
946
|
+
|
|
947
|
+
options = dict(arrow_client_options) if arrow_client_options else {}
|
|
948
|
+
if "disable_server_verification" in options:
|
|
949
|
+
return options
|
|
950
|
+
|
|
951
|
+
return disable_server_verification(options)
|
|
952
|
+
|
|
861
953
|
@staticmethod
|
|
862
954
|
def _validate_endpoint(endpoint: str | Driver | QueryRunner) -> None:
|
|
863
955
|
if isinstance(endpoint, str):
|
|
@@ -7,3 +7,21 @@ from pydantic.alias_generators import to_camel
|
|
|
7
7
|
class BaseResult(BaseModel, alias_generator=to_camel, populate_by_name=True):
|
|
8
8
|
def __getitem__(self, item: str) -> Any:
|
|
9
9
|
return getattr(self, item)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class StatsResult(BaseResult):
|
|
13
|
+
compute_millis: int
|
|
14
|
+
pre_processing_millis: int
|
|
15
|
+
configuration: dict[str, Any]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class MutateResult(StatsResult):
|
|
19
|
+
mutate_millis: int
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class WriteResult(StatsResult):
|
|
23
|
+
write_millis: int
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class NodeResult(BaseResult):
|
|
27
|
+
node_properties_written: int
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from abc import ABC, abstractmethod
|
|
4
4
|
from types import TracebackType
|
|
5
|
-
from typing import Any, NamedTuple, Type
|
|
5
|
+
from typing import Any, List, NamedTuple, Type
|
|
6
6
|
|
|
7
7
|
from pandas import DataFrame
|
|
8
8
|
from pydantic import field_validator
|
|
@@ -289,6 +289,16 @@ class CatalogEndpoints(ABC):
|
|
|
289
289
|
return RelationshipPropertiesEndpoints(self.relationships)
|
|
290
290
|
|
|
291
291
|
|
|
292
|
+
def normalize_graph_names(G: Graph | str | List[Graph | str]) -> List[str]:
|
|
293
|
+
match G:
|
|
294
|
+
case Graph() as graph:
|
|
295
|
+
return [graph.name()]
|
|
296
|
+
case str(name):
|
|
297
|
+
return [name]
|
|
298
|
+
case list(seq):
|
|
299
|
+
return [name for e in seq for name in normalize_graph_names(e)]
|
|
300
|
+
|
|
301
|
+
|
|
292
302
|
class GraphFilterResult(BaseResult):
|
|
293
303
|
graph_name: str
|
|
294
304
|
from_graph_name: str
|
|
@@ -113,7 +113,7 @@ class NodePropertiesEndpoints(ABC):
|
|
|
113
113
|
G: Graph,
|
|
114
114
|
node_properties: list[str],
|
|
115
115
|
*,
|
|
116
|
-
fail_if_missing: bool
|
|
116
|
+
fail_if_missing: bool = True,
|
|
117
117
|
concurrency: int | None = None,
|
|
118
118
|
username: str | None = None,
|
|
119
119
|
) -> NodePropertiesDropResult:
|
|
@@ -123,11 +123,11 @@ class NodePropertiesEndpoints(ABC):
|
|
|
123
123
|
Parameters
|
|
124
124
|
----------
|
|
125
125
|
G
|
|
126
|
-
|
|
126
|
+
Graph object to use
|
|
127
127
|
node_properties
|
|
128
128
|
The node properties to drop
|
|
129
|
-
fail_if_missing
|
|
130
|
-
Whether to fail if any of the node properties are missing
|
|
129
|
+
fail_if_missing
|
|
130
|
+
Whether to fail if any of the node properties are missing.
|
|
131
131
|
concurrency
|
|
132
132
|
Number of concurrent threads to use.
|
|
133
133
|
username
|