graphdatascience 2.0a2__py3-none-any.whl → 2.0a3__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/authenticated_flight_client.py +25 -4
- graphdatascience/arrow_client/server_health_check.py +10 -0
- graphdatascience/procedure_surface/api/catalog/__init__.py +10 -0
- graphdatascience/procedure_surface/api/catalog/catalog_endpoints.py +23 -1
- graphdatascience/procedure_surface/api/catalog/node_property_endpoints.py +68 -0
- graphdatascience/procedure_surface/api/catalog/relationship_properties_endpoints.py +114 -0
- graphdatascience/procedure_surface/api/catalog/relationship_property_endpoints.py +61 -0
- graphdatascience/procedure_surface/api/community/hdbscan_endpoints.py +5 -5
- graphdatascience/procedure_surface/arrow/catalog/node_properties_arrow_endpoints.py +4 -1
- graphdatascience/procedure_surface/arrow/catalog/relationship_arrow_endpoints.py +2 -1
- graphdatascience/procedure_surface/arrow/catalog/scale_properties_arrow_endpoints.py +1 -4
- graphdatascience/procedure_surface/arrow/community/conductance_arrow_endpoints.py +1 -5
- graphdatascience/procedure_surface/arrow/community/modularity_arrow_endpoints.py +1 -3
- graphdatascience/procedure_surface/arrow/endpoints_helper_base.py +11 -3
- graphdatascience/procedure_surface/arrow/pathfinding/all_shortest_path_arrow_endpoints.py +1 -4
- graphdatascience/procedure_surface/arrow/pathfinding/bfs_arrow_endpoints.py +2 -1
- graphdatascience/procedure_surface/arrow/pathfinding/dfs_arrow_endpoints.py +2 -1
- graphdatascience/procedure_surface/arrow/pathfinding/dijkstra_arrow_endpoints.py +1 -4
- graphdatascience/procedure_surface/arrow/pathfinding/longest_path_arrow_endpoints.py +1 -5
- graphdatascience/procedure_surface/arrow/pathfinding/max_flow_arrow_endpoints.py +1 -6
- graphdatascience/procedure_surface/arrow/pathfinding/max_flow_min_cost_arrow_endpoints.py +1 -6
- graphdatascience/procedure_surface/arrow/pathfinding/prize_steiner_tree_arrow_endpoints.py +1 -4
- graphdatascience/procedure_surface/arrow/pathfinding/single_source_bellman_ford_arrow_endpoints.py +0 -2
- graphdatascience/procedure_surface/arrow/pathfinding/single_source_delta_arrow_endpoints.py +1 -5
- graphdatascience/procedure_surface/arrow/pathfinding/single_source_dijkstra_arrow_endpoints.py +1 -5
- graphdatascience/procedure_surface/arrow/pathfinding/source_target_astar_arrow_endpoints.py +1 -5
- graphdatascience/procedure_surface/arrow/pathfinding/source_target_dijkstra_arrow_endpoints.py +1 -4
- graphdatascience/procedure_surface/arrow/pathfinding/source_target_yens_arrow_endpoints.py +1 -5
- graphdatascience/procedure_surface/arrow/pathfinding/spanning_tree_arrow_endpoints.py +1 -4
- graphdatascience/procedure_surface/arrow/pathfinding/steiner_tree_arrow_endpoints.py +1 -4
- graphdatascience/procedure_surface/arrow/pathfinding/topological_sort_arrow_endpoints.py +1 -5
- graphdatascience/procedure_surface/arrow/pipeline/link_prediction_predict_arrow_endpoints.py +5 -1
- graphdatascience/procedure_surface/arrow/similarity/knn_arrow_endpoints.py +1 -5
- graphdatascience/procedure_surface/arrow/similarity/knn_filtered_arrow_endpoints.py +1 -5
- graphdatascience/procedure_surface/arrow/similarity/node_similarity_arrow_endpoints.py +1 -5
- graphdatascience/procedure_surface/arrow/similarity/node_similarity_filtered_arrow_endpoints.py +1 -5
- graphdatascience/procedure_surface/arrow/stream_result_mapper.py +21 -0
- graphdatascience/procedure_surface/cypher/catalog/catalog_cypher_endpoints.py +9 -1
- graphdatascience/procedure_surface/cypher/catalog/graph_backend_cypher.py +4 -0
- graphdatascience/procedure_surface/cypher/catalog/node_properties_cypher_endpoints.py +8 -1
- graphdatascience/procedure_surface/cypher/catalog/relationship_cypher_endpoints.py +11 -12
- graphdatascience/procedure_surface/cypher/model/model_catalog_cypher_endpoints.py +17 -2
- graphdatascience/procedure_surface/cypher/pipeline/pipeline_catalog_cypher_endpoints.py +9 -1
- graphdatascience/procedure_surface/utils/result_utils.py +16 -0
- graphdatascience/session/aura_api.py +129 -8
- graphdatascience/session/aura_api_responses.py +12 -0
- graphdatascience/session/aura_graph_data_science.py +1 -0
- graphdatascience/session/endpoint_mappings.py +0 -6
- graphdatascience/session/gds_sessions.py +2 -2
- graphdatascience/session/session_lifecycle_manager.py +38 -4
- graphdatascience/version.py +1 -1
- {graphdatascience-2.0a2.dist-info → graphdatascience-2.0a3.dist-info}/METADATA +1 -1
- {graphdatascience-2.0a2.dist-info → graphdatascience-2.0a3.dist-info}/RECORD +56 -52
- {graphdatascience-2.0a2.dist-info → graphdatascience-2.0a3.dist-info}/WHEEL +0 -0
- {graphdatascience-2.0a2.dist-info → graphdatascience-2.0a3.dist-info}/licenses/LICENSE +0 -0
- {graphdatascience-2.0a2.dist-info → graphdatascience-2.0a3.dist-info}/top_level.txt +0 -0
|
@@ -5,7 +5,7 @@ import logging
|
|
|
5
5
|
import platform
|
|
6
6
|
from dataclasses import dataclass
|
|
7
7
|
from types import TracebackType
|
|
8
|
-
from typing import Any, Iterator, Type
|
|
8
|
+
from typing import Any, Callable, Iterator, Type, TypeVar
|
|
9
9
|
|
|
10
10
|
import certifi
|
|
11
11
|
from pyarrow import Schema, flight
|
|
@@ -22,6 +22,7 @@ from pyarrow.flight import (
|
|
|
22
22
|
)
|
|
23
23
|
|
|
24
24
|
from graphdatascience.arrow_client.arrow_authentication import ArrowAuthentication
|
|
25
|
+
from graphdatascience.arrow_client.server_health_check import ServerHealthCheck
|
|
25
26
|
from graphdatascience.retry_utils.retry_config import ExponentialWaitConfig, RetryConfigV2, StopConfig
|
|
26
27
|
|
|
27
28
|
from ..version import __version__
|
|
@@ -29,6 +30,8 @@ from .arrow_client_options_util import TLS_ROOT_CERTS_OPTION, set_tls_root_certs
|
|
|
29
30
|
from .middleware.auth_middleware import AuthFactory, AuthMiddleware
|
|
30
31
|
from .middleware.user_agent_middleware import UserAgentFactory
|
|
31
32
|
|
|
33
|
+
T = TypeVar("T")
|
|
34
|
+
|
|
32
35
|
|
|
33
36
|
class AuthenticatedArrowClient:
|
|
34
37
|
def __init__(
|
|
@@ -40,6 +43,7 @@ class AuthenticatedArrowClient:
|
|
|
40
43
|
user_agent: str | None = None,
|
|
41
44
|
advertised_listen_address: tuple[str, int] | None = None,
|
|
42
45
|
retry_config: RetryConfigV2 | None = None,
|
|
46
|
+
health_check: ServerHealthCheck | None = None,
|
|
43
47
|
):
|
|
44
48
|
"""Creates a new AuthenticatedArrowClient instance.
|
|
45
49
|
|
|
@@ -59,6 +63,9 @@ class AuthenticatedArrowClient:
|
|
|
59
63
|
The retry configuration to use for the Arrow requests send by the client.
|
|
60
64
|
advertised_listen_address
|
|
61
65
|
The advertised listen address of the GDS Arrow server. This will be used by remote projection and writeback operations.
|
|
66
|
+
health_check
|
|
67
|
+
Optional health check consulted when the server could not be reached, after all retries were
|
|
68
|
+
exhausted. It is expected to raise a more descriptive error if it can explain the failure (such as out-of-memory error) and to return without raising otherwise.
|
|
62
69
|
"""
|
|
63
70
|
|
|
64
71
|
if isinstance(connection_info, str):
|
|
@@ -86,6 +93,7 @@ class AuthenticatedArrowClient:
|
|
|
86
93
|
self._user_agent = user_agent
|
|
87
94
|
self._logger = logging.getLogger("gds_arrow_client")
|
|
88
95
|
self._retry_config = retry_config
|
|
96
|
+
self._health_check = health_check
|
|
89
97
|
if auth:
|
|
90
98
|
self._auth_middleware = AuthMiddleware(auth)
|
|
91
99
|
self.advertised_listen_address = advertised_listen_address
|
|
@@ -139,7 +147,7 @@ class AuthenticatedArrowClient:
|
|
|
139
147
|
raise
|
|
140
148
|
|
|
141
149
|
if self._auth:
|
|
142
|
-
auth_with_retry
|
|
150
|
+
self._diagnose_connection_failure(auth_with_retry)
|
|
143
151
|
return self._auth_middleware.token()
|
|
144
152
|
else:
|
|
145
153
|
return "IGNORED"
|
|
@@ -163,7 +171,7 @@ class AuthenticatedArrowClient:
|
|
|
163
171
|
self._reconnect()
|
|
164
172
|
raise
|
|
165
173
|
|
|
166
|
-
return run_with_retry
|
|
174
|
+
return self._diagnose_connection_failure(run_with_retry)
|
|
167
175
|
|
|
168
176
|
def list_actions(self) -> set[ActionType]:
|
|
169
177
|
return self._flight_client.list_actions() # type: ignore
|
|
@@ -179,7 +187,19 @@ class AuthenticatedArrowClient:
|
|
|
179
187
|
self._reconnect()
|
|
180
188
|
raise
|
|
181
189
|
|
|
182
|
-
return run_with_retry
|
|
190
|
+
return self._diagnose_connection_failure(run_with_retry)
|
|
191
|
+
|
|
192
|
+
def _diagnose_connection_failure(self, operation: Callable[[], T]) -> T:
|
|
193
|
+
"""
|
|
194
|
+
Runs the given operation and, if the server could not be reached, gives the health check
|
|
195
|
+
the chance to raise a more descriptive error.
|
|
196
|
+
"""
|
|
197
|
+
try:
|
|
198
|
+
return operation()
|
|
199
|
+
except (FlightTimedOutError, FlightUnavailableError, FlightInternalError):
|
|
200
|
+
if self._health_check:
|
|
201
|
+
self._health_check.raise_if_unhealthy()
|
|
202
|
+
raise
|
|
183
203
|
|
|
184
204
|
def __enter__(self) -> AuthenticatedArrowClient:
|
|
185
205
|
return self
|
|
@@ -230,6 +250,7 @@ class AuthenticatedArrowClient:
|
|
|
230
250
|
|
|
231
251
|
def __setstate__(self, state: dict[str, Any]) -> None:
|
|
232
252
|
self.__dict__.update(state)
|
|
253
|
+
self.__dict__.setdefault("_health_check", None)
|
|
233
254
|
self._flight_client = self._instantiate_flight_client()
|
|
234
255
|
|
|
235
256
|
def _reconnect(self) -> None:
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from typing import Protocol
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ServerHealthCheck(Protocol):
|
|
5
|
+
def raise_if_unhealthy(self) -> None:
|
|
6
|
+
"""
|
|
7
|
+
Raises a descriptive error if the server is known to be in an unhealthy state,
|
|
8
|
+
and returns without raising if the state could not be determined.
|
|
9
|
+
"""
|
|
10
|
+
...
|
|
@@ -29,6 +29,13 @@ from graphdatascience.procedure_surface.api.catalog.node_properties_endpoints im
|
|
|
29
29
|
NodePropertiesWriteResult,
|
|
30
30
|
NodePropertySpec,
|
|
31
31
|
)
|
|
32
|
+
from graphdatascience.procedure_surface.api.catalog.node_property_endpoints import NodePropertyEndpoints
|
|
33
|
+
from graphdatascience.procedure_surface.api.catalog.relationship_properties_endpoints import (
|
|
34
|
+
RelationshipPropertiesEndpoints,
|
|
35
|
+
)
|
|
36
|
+
from graphdatascience.procedure_surface.api.catalog.relationship_property_endpoints import (
|
|
37
|
+
RelationshipPropertyEndpoints,
|
|
38
|
+
)
|
|
32
39
|
from graphdatascience.procedure_surface.api.catalog.relationships_data_frame import RelationshipsDataFrame
|
|
33
40
|
from graphdatascience.procedure_surface.api.catalog.relationships_endpoints import (
|
|
34
41
|
Aggregation,
|
|
@@ -67,7 +74,10 @@ __all__ = [
|
|
|
67
74
|
"NodePropertiesDropResult",
|
|
68
75
|
"NodePropertiesEndpoints",
|
|
69
76
|
"NodePropertiesWriteResult",
|
|
77
|
+
"NodePropertyEndpoints",
|
|
70
78
|
"NodePropertySpec",
|
|
79
|
+
"RelationshipPropertiesEndpoints",
|
|
80
|
+
"RelationshipPropertyEndpoints",
|
|
71
81
|
"RelationshipPropertySpec",
|
|
72
82
|
"RelationshipsDataFrame",
|
|
73
83
|
"RelationshipsDropResult",
|
|
@@ -15,6 +15,13 @@ from graphdatascience.procedure_surface.api.catalog.graph_export_endpoints impor
|
|
|
15
15
|
from graphdatascience.procedure_surface.api.catalog.graph_sampling_endpoints import GraphSamplingEndpoints
|
|
16
16
|
from graphdatascience.procedure_surface.api.catalog.node_label_endpoints import NodeLabelEndpoints
|
|
17
17
|
from graphdatascience.procedure_surface.api.catalog.node_properties_endpoints import NodePropertiesEndpoints
|
|
18
|
+
from graphdatascience.procedure_surface.api.catalog.node_property_endpoints import NodePropertyEndpoints
|
|
19
|
+
from graphdatascience.procedure_surface.api.catalog.relationship_properties_endpoints import (
|
|
20
|
+
RelationshipPropertiesEndpoints,
|
|
21
|
+
)
|
|
22
|
+
from graphdatascience.procedure_surface.api.catalog.relationship_property_endpoints import (
|
|
23
|
+
RelationshipPropertyEndpoints,
|
|
24
|
+
)
|
|
18
25
|
from graphdatascience.procedure_surface.api.catalog.relationships_endpoints import RelationshipsEndpoints
|
|
19
26
|
|
|
20
27
|
|
|
@@ -245,15 +252,30 @@ class CatalogEndpoints(ABC):
|
|
|
245
252
|
@property
|
|
246
253
|
@abstractmethod
|
|
247
254
|
def node_properties(self) -> NodePropertiesEndpoints:
|
|
248
|
-
"""Endpoints for node
|
|
255
|
+
"""Endpoints for node property operations."""
|
|
249
256
|
pass
|
|
250
257
|
|
|
258
|
+
@property
|
|
259
|
+
def node_property(self) -> NodePropertyEndpoints:
|
|
260
|
+
"""Endpoints for streaming a single node property."""
|
|
261
|
+
return NodePropertyEndpoints(self.node_properties)
|
|
262
|
+
|
|
251
263
|
@property
|
|
252
264
|
@abstractmethod
|
|
253
265
|
def relationships(self) -> RelationshipsEndpoints:
|
|
254
266
|
"""Endpoints for relationship operations."""
|
|
255
267
|
pass
|
|
256
268
|
|
|
269
|
+
@property
|
|
270
|
+
def relationship_property(self) -> RelationshipPropertyEndpoints:
|
|
271
|
+
"""Endpoints for streaming a single relationship property."""
|
|
272
|
+
return RelationshipPropertyEndpoints(self.relationships)
|
|
273
|
+
|
|
274
|
+
@property
|
|
275
|
+
def relationship_properties(self) -> RelationshipPropertiesEndpoints:
|
|
276
|
+
"""Endpoints for streaming several relationship properties."""
|
|
277
|
+
return RelationshipPropertiesEndpoints(self.relationships)
|
|
278
|
+
|
|
257
279
|
|
|
258
280
|
class GraphFilterResult(BaseResult):
|
|
259
281
|
graph_name: str
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pandas import DataFrame
|
|
4
|
+
|
|
5
|
+
from graphdatascience.graph.graph_api import Graph
|
|
6
|
+
from graphdatascience.procedure_surface.api.catalog.node_properties_endpoints import NodePropertiesEndpoints
|
|
7
|
+
from graphdatascience.procedure_surface.api.default_values import ALL_LABELS
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class NodePropertyEndpoints:
|
|
11
|
+
def __init__(self, node_properties_endpoints: NodePropertiesEndpoints) -> None:
|
|
12
|
+
self._node_properties_endpoints = node_properties_endpoints
|
|
13
|
+
|
|
14
|
+
def stream(
|
|
15
|
+
self,
|
|
16
|
+
G: Graph,
|
|
17
|
+
node_property: str,
|
|
18
|
+
*,
|
|
19
|
+
list_node_labels: bool | None = False,
|
|
20
|
+
node_labels: list[str] = ALL_LABELS,
|
|
21
|
+
concurrency: int | None = None,
|
|
22
|
+
sudo: bool = False,
|
|
23
|
+
log_progress: bool = True,
|
|
24
|
+
username: str | None = None,
|
|
25
|
+
db_node_properties: list[str] | None = None,
|
|
26
|
+
) -> DataFrame:
|
|
27
|
+
"""
|
|
28
|
+
Streams the specified node property from the graph.
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
G
|
|
33
|
+
Graph object to use
|
|
34
|
+
node_property : str
|
|
35
|
+
The node property to stream
|
|
36
|
+
list_node_labels : boolean | None, default=None
|
|
37
|
+
Whether to include node labels in the stream
|
|
38
|
+
node_labels
|
|
39
|
+
Filter the graph using the given node labels. Nodes with any of the given labels will be included.
|
|
40
|
+
concurrency
|
|
41
|
+
Number of concurrent threads to use.
|
|
42
|
+
sudo
|
|
43
|
+
Disable the memory guard.
|
|
44
|
+
log_progress
|
|
45
|
+
Display progress logging.
|
|
46
|
+
username
|
|
47
|
+
As an administrator, impersonate a different user for accessing their graphs.
|
|
48
|
+
db_node_properties : list[str] | None, default=None
|
|
49
|
+
Retrieves additional node properties from the database and attaches them to the stream.
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
DataFrame
|
|
53
|
+
The streamed node property as `nodeId` and `propertyValue` columns, plus a `nodeLabels` column
|
|
54
|
+
if `list_node_labels` is set and one column per requested `db_node_properties`.
|
|
55
|
+
"""
|
|
56
|
+
result = self._node_properties_endpoints.stream(
|
|
57
|
+
G,
|
|
58
|
+
node_property,
|
|
59
|
+
list_node_labels=list_node_labels,
|
|
60
|
+
node_labels=node_labels,
|
|
61
|
+
concurrency=concurrency,
|
|
62
|
+
sudo=sudo,
|
|
63
|
+
log_progress=log_progress,
|
|
64
|
+
username=username,
|
|
65
|
+
db_node_properties=db_node_properties,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
return result.rename(columns={node_property: "propertyValue"})
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from graphdatascience.graph.graph_api import Graph
|
|
4
|
+
from graphdatascience.procedure_surface.api.catalog.relationships_data_frame import RelationshipsDataFrame
|
|
5
|
+
from graphdatascience.procedure_surface.api.catalog.relationships_endpoints import (
|
|
6
|
+
RelationshipsEndpoints,
|
|
7
|
+
RelationshipsWriteResult,
|
|
8
|
+
)
|
|
9
|
+
from graphdatascience.procedure_surface.api.default_values import ALL_TYPES
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class RelationshipPropertiesEndpoints:
|
|
13
|
+
def __init__(self, relationships_endpoints: RelationshipsEndpoints) -> None:
|
|
14
|
+
self._relationships_endpoints = relationships_endpoints
|
|
15
|
+
|
|
16
|
+
def stream(
|
|
17
|
+
self,
|
|
18
|
+
G: Graph,
|
|
19
|
+
relationship_properties: list[str],
|
|
20
|
+
relationship_types: list[str] = ALL_TYPES,
|
|
21
|
+
*,
|
|
22
|
+
concurrency: int | None = None,
|
|
23
|
+
sudo: bool = False,
|
|
24
|
+
log_progress: bool = True,
|
|
25
|
+
username: str | None = None,
|
|
26
|
+
) -> RelationshipsDataFrame:
|
|
27
|
+
"""
|
|
28
|
+
Streams the specified relationship properties for all relationships of the specified types.
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
G
|
|
33
|
+
Graph object to use
|
|
34
|
+
relationship_properties : list[str]
|
|
35
|
+
The relationship properties to stream
|
|
36
|
+
relationship_types
|
|
37
|
+
Filter the graph using the given relationship types. Relationships with any of the given types will be included.
|
|
38
|
+
concurrency
|
|
39
|
+
Number of concurrent threads to use.
|
|
40
|
+
sudo
|
|
41
|
+
Disable the memory guard.
|
|
42
|
+
log_progress
|
|
43
|
+
Display progress logging.
|
|
44
|
+
username
|
|
45
|
+
As an administrator, impersonate a different user for accessing their graphs.
|
|
46
|
+
Returns
|
|
47
|
+
-------
|
|
48
|
+
RelationshipsDataFrame
|
|
49
|
+
The streamed relationships [sourceNodeId, targetNodeId, relationshipType], followed by one column per
|
|
50
|
+
streamed relationship property. Offers a ``by_rel_type()`` method to reshape the relationships by
|
|
51
|
+
relationship type.
|
|
52
|
+
"""
|
|
53
|
+
return self._relationships_endpoints.stream(
|
|
54
|
+
G,
|
|
55
|
+
relationship_types,
|
|
56
|
+
relationship_properties,
|
|
57
|
+
concurrency=concurrency,
|
|
58
|
+
sudo=sudo,
|
|
59
|
+
log_progress=log_progress,
|
|
60
|
+
username=username,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def write(
|
|
64
|
+
self,
|
|
65
|
+
G: Graph,
|
|
66
|
+
relationship_type: str,
|
|
67
|
+
relationship_properties: list[str],
|
|
68
|
+
*,
|
|
69
|
+
concurrency: int | None = None,
|
|
70
|
+
write_concurrency: int | None = None,
|
|
71
|
+
sudo: bool = False,
|
|
72
|
+
log_progress: bool = True,
|
|
73
|
+
username: str | None = None,
|
|
74
|
+
job_id: str | None = None,
|
|
75
|
+
) -> RelationshipsWriteResult:
|
|
76
|
+
"""
|
|
77
|
+
Writes the specified relationship properties of the given relationship type from the graph to the database.
|
|
78
|
+
|
|
79
|
+
Parameters
|
|
80
|
+
----------
|
|
81
|
+
G
|
|
82
|
+
Graph object to use
|
|
83
|
+
relationship_type : str
|
|
84
|
+
The relationship type to write to the database
|
|
85
|
+
relationship_properties : list[str]
|
|
86
|
+
The relationship properties to write
|
|
87
|
+
concurrency
|
|
88
|
+
Number of concurrent threads to use.
|
|
89
|
+
write_concurrency
|
|
90
|
+
Number of concurrent threads to use for writing.
|
|
91
|
+
sudo
|
|
92
|
+
Disable the memory guard.
|
|
93
|
+
log_progress
|
|
94
|
+
Display progress logging.
|
|
95
|
+
username
|
|
96
|
+
As an administrator, impersonate a different user for accessing their graphs.
|
|
97
|
+
job_id
|
|
98
|
+
Identifier for the computation.
|
|
99
|
+
Returns
|
|
100
|
+
-------
|
|
101
|
+
RelationshipsWriteResult
|
|
102
|
+
Execution metrics and statistics
|
|
103
|
+
"""
|
|
104
|
+
return self._relationships_endpoints.write(
|
|
105
|
+
G,
|
|
106
|
+
relationship_type,
|
|
107
|
+
relationship_properties,
|
|
108
|
+
concurrency=concurrency,
|
|
109
|
+
write_concurrency=write_concurrency,
|
|
110
|
+
sudo=sudo,
|
|
111
|
+
log_progress=log_progress,
|
|
112
|
+
username=username,
|
|
113
|
+
job_id=job_id,
|
|
114
|
+
)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from graphdatascience.graph.graph_api import Graph
|
|
4
|
+
from graphdatascience.procedure_surface.api.catalog.relationships_data_frame import RelationshipsDataFrame
|
|
5
|
+
from graphdatascience.procedure_surface.api.catalog.relationships_endpoints import RelationshipsEndpoints
|
|
6
|
+
from graphdatascience.procedure_surface.api.default_values import ALL_TYPES
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RelationshipPropertyEndpoints:
|
|
10
|
+
"""Endpoints for streaming a single relationship property, delegating to the relationships endpoints."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, relationships_endpoints: RelationshipsEndpoints) -> None:
|
|
13
|
+
self._relationships_endpoints = relationships_endpoints
|
|
14
|
+
|
|
15
|
+
def stream(
|
|
16
|
+
self,
|
|
17
|
+
G: Graph,
|
|
18
|
+
relationship_property: str,
|
|
19
|
+
relationship_types: list[str] = ALL_TYPES,
|
|
20
|
+
*,
|
|
21
|
+
concurrency: int | None = None,
|
|
22
|
+
sudo: bool = False,
|
|
23
|
+
log_progress: bool = True,
|
|
24
|
+
username: str | None = None,
|
|
25
|
+
) -> RelationshipsDataFrame:
|
|
26
|
+
"""
|
|
27
|
+
Streams the specified relationship property for all relationships of the specified types.
|
|
28
|
+
|
|
29
|
+
Parameters
|
|
30
|
+
----------
|
|
31
|
+
G
|
|
32
|
+
Graph object to use
|
|
33
|
+
relationship_property : str
|
|
34
|
+
The relationship property to stream
|
|
35
|
+
relationship_types
|
|
36
|
+
Filter the graph using the given relationship types. Relationships with any of the given types will be included.
|
|
37
|
+
concurrency
|
|
38
|
+
Number of concurrent threads to use.
|
|
39
|
+
sudo
|
|
40
|
+
Disable the memory guard.
|
|
41
|
+
log_progress
|
|
42
|
+
Display progress logging.
|
|
43
|
+
username
|
|
44
|
+
As an administrator, impersonate a different user for accessing their graphs.
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
RelationshipsDataFrame
|
|
48
|
+
The streamed relationships [sourceNodeId, targetNodeId, relationshipType, propertyValue]. Offers a
|
|
49
|
+
``by_rel_type()`` method to reshape the relationships by relationship type.
|
|
50
|
+
"""
|
|
51
|
+
result = self._relationships_endpoints.stream(
|
|
52
|
+
G,
|
|
53
|
+
relationship_types,
|
|
54
|
+
[relationship_property],
|
|
55
|
+
concurrency=concurrency,
|
|
56
|
+
sudo=sudo,
|
|
57
|
+
log_progress=log_progress,
|
|
58
|
+
username=username,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
return RelationshipsDataFrame(result.rename(columns={relationship_property: "propertyValue"}))
|
|
@@ -41,7 +41,7 @@ class HdbscanEndpoints(ABC):
|
|
|
41
41
|
G
|
|
42
42
|
Graph object to use
|
|
43
43
|
node_property : str
|
|
44
|
-
The node property to use for clustering
|
|
44
|
+
The node property to use for clustering
|
|
45
45
|
mutate_property
|
|
46
46
|
Name of the node property to store the results in.
|
|
47
47
|
leaf_size : int | None, default=None
|
|
@@ -99,7 +99,7 @@ class HdbscanEndpoints(ABC):
|
|
|
99
99
|
G
|
|
100
100
|
Graph object to use
|
|
101
101
|
node_property : str
|
|
102
|
-
The node property to use for clustering
|
|
102
|
+
The node property to use for clustering
|
|
103
103
|
leaf_size : int | None, default=None
|
|
104
104
|
The maximum leaf size of the tree structure used in the algorithm
|
|
105
105
|
samples : int | None, default=None
|
|
@@ -155,7 +155,7 @@ class HdbscanEndpoints(ABC):
|
|
|
155
155
|
G
|
|
156
156
|
Graph object to use
|
|
157
157
|
node_property : str
|
|
158
|
-
The node property to use for clustering
|
|
158
|
+
The node property to use for clustering
|
|
159
159
|
leaf_size : int | None, default=None
|
|
160
160
|
The maximum leaf size of the tree structure used in the algorithm
|
|
161
161
|
samples : int | None, default=None
|
|
@@ -210,7 +210,7 @@ class HdbscanEndpoints(ABC):
|
|
|
210
210
|
G
|
|
211
211
|
Graph object to use
|
|
212
212
|
node_property : str
|
|
213
|
-
The node property to use for clustering
|
|
213
|
+
The node property to use for clustering
|
|
214
214
|
write_property
|
|
215
215
|
Name of the node property to store the results in.
|
|
216
216
|
leaf_size : int | None, default=None
|
|
@@ -267,7 +267,7 @@ class HdbscanEndpoints(ABC):
|
|
|
267
267
|
G
|
|
268
268
|
Graph object to use or a dictionary representing the graph dimensions.
|
|
269
269
|
node_property : str
|
|
270
|
-
The node property to use for clustering
|
|
270
|
+
The node property to use for clustering
|
|
271
271
|
leaf_size : int | None, default=None
|
|
272
272
|
The maximum leaf size of the tree structure used in the algorithm
|
|
273
273
|
samples : int | None, default=None
|
|
@@ -13,6 +13,7 @@ from graphdatascience.procedure_surface.api.catalog.node_properties_endpoints im
|
|
|
13
13
|
from graphdatascience.procedure_surface.api.default_values import ALL_LABELS
|
|
14
14
|
from graphdatascience.procedure_surface.api.write_job_handle import WriteJobHandle
|
|
15
15
|
from graphdatascience.procedure_surface.arrow.node_property_endpoints import NodePropertyEndpointsHelper
|
|
16
|
+
from graphdatascience.procedure_surface.arrow.stream_result_mapper import apply_stream_mapper
|
|
16
17
|
from graphdatascience.procedure_surface.utils.config_converter import ConfigConverter
|
|
17
18
|
from graphdatascience.procedure_surface.utils.result_utils import join_db_node_properties
|
|
18
19
|
from graphdatascience.query_runner.query_runner import QueryRunner
|
|
@@ -71,7 +72,9 @@ class NodePropertiesArrowEndpoints(NodePropertiesEndpoints):
|
|
|
71
72
|
)
|
|
72
73
|
|
|
73
74
|
job_id = JobClient.run_job(self._arrow_client, "v2/graph.nodeProperties.stream", config)
|
|
74
|
-
result =
|
|
75
|
+
result = apply_stream_mapper(
|
|
76
|
+
"v2/graph.nodeProperties.stream", JobClient.stream_results(self._arrow_client, G.name(), job_id)
|
|
77
|
+
)
|
|
75
78
|
|
|
76
79
|
if has_db_properties:
|
|
77
80
|
return join_db_node_properties(result, db_node_properties, self._query_runner) # type: ignore
|
|
@@ -15,6 +15,7 @@ from graphdatascience.procedure_surface.api.catalog.relationships_endpoints impo
|
|
|
15
15
|
from graphdatascience.procedure_surface.api.default_values import ALL_LABELS, ALL_TYPES
|
|
16
16
|
from graphdatascience.procedure_surface.api.write_job_handle import WriteJobHandle
|
|
17
17
|
from graphdatascience.procedure_surface.arrow.collapse_path_arrow_endpoints import CollapsePathArrowEndpoints
|
|
18
|
+
from graphdatascience.procedure_surface.arrow.stream_result_mapper import apply_stream_mapper
|
|
18
19
|
from graphdatascience.procedure_surface.utils.config_converter import ConfigConverter
|
|
19
20
|
from graphdatascience.query_runner.termination_flag import TerminationFlag
|
|
20
21
|
from graphdatascience.session.remote_ops.write_protocols import WriteProtocol
|
|
@@ -63,7 +64,7 @@ class RelationshipArrowEndpoints(RelationshipsEndpoints):
|
|
|
63
64
|
config = ConfigConverter.convert_to_gds_config(**config_input)
|
|
64
65
|
|
|
65
66
|
job_id = JobClient.run_job(self._arrow_client, endpoint, config)
|
|
66
|
-
result = JobClient.stream_results(self._arrow_client, G.name(), job_id)
|
|
67
|
+
result = apply_stream_mapper(endpoint, JobClient.stream_results(self._arrow_client, G.name(), job_id))
|
|
67
68
|
|
|
68
69
|
return RelationshipsDataFrame(result)
|
|
69
70
|
|
|
@@ -120,10 +120,7 @@ class ScalePropertiesArrowEndpoints(ScalePropertiesEndpoints):
|
|
|
120
120
|
scaler=scaler_value,
|
|
121
121
|
)
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
result.rename(columns={"scaledProperties": "scaledProperty"}, inplace=True)
|
|
125
|
-
|
|
126
|
-
return result
|
|
123
|
+
return self._node_property_endpoints.run_job_and_stream("v2/graph.nodeProperties.scale", G, config)
|
|
127
124
|
|
|
128
125
|
def write(
|
|
129
126
|
self,
|
|
@@ -5,7 +5,6 @@ from graphdatascience.graph.graph_api import Graph
|
|
|
5
5
|
from graphdatascience.procedure_surface.api.community.conductance_endpoints import ConductanceEndpoints
|
|
6
6
|
from graphdatascience.procedure_surface.api.default_values import ALL_LABELS, ALL_TYPES
|
|
7
7
|
from graphdatascience.procedure_surface.api.job_handle import JobHandle
|
|
8
|
-
from graphdatascience.procedure_surface.arrow.stream_result_mapper import map_conductance_stream_result
|
|
9
8
|
from graphdatascience.procedure_surface.arrow.table_endpoints_helper import TableEndpointsHelper
|
|
10
9
|
|
|
11
10
|
|
|
@@ -70,7 +69,4 @@ class ConductanceArrowEndpoints(ConductanceEndpoints):
|
|
|
70
69
|
relationship_weight_property=relationship_weight_property,
|
|
71
70
|
)
|
|
72
71
|
|
|
73
|
-
|
|
74
|
-
map_conductance_stream_result(result)
|
|
75
|
-
|
|
76
|
-
return result
|
|
72
|
+
return self._endpoints_helper.run_job_and_stream("v2/community.conductance", G, config)
|
|
@@ -105,9 +105,7 @@ class ModularityArrowEndpoints(ModularityEndpoints):
|
|
|
105
105
|
relationship_weight_property=relationship_weight_property,
|
|
106
106
|
)
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return result
|
|
108
|
+
return self._endpoints_helper.run_job_and_stream("v2/community.modularity", G, config)
|
|
111
109
|
|
|
112
110
|
def estimate(
|
|
113
111
|
self,
|
|
@@ -17,6 +17,7 @@ from ..api.job_handle import JobHandle
|
|
|
17
17
|
from ..api.write_job_handle import WriteJobHandle
|
|
18
18
|
from ..utils.config_converter import ConfigConverter
|
|
19
19
|
from .mutation_runner import MutationRunner
|
|
20
|
+
from .stream_result_mapper import apply_stream_mapper
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
class EndpointsHelperBase:
|
|
@@ -67,11 +68,18 @@ class EndpointsHelperBase:
|
|
|
67
68
|
mutate_property_overwrites=mutate_property_overwrites,
|
|
68
69
|
)
|
|
69
70
|
|
|
70
|
-
def run_job_and_stream(
|
|
71
|
-
|
|
71
|
+
def run_job_and_stream(
|
|
72
|
+
self, endpoint: str, G: Graph, config: dict[str, Any], *, apply_mapping: bool = True
|
|
73
|
+
) -> DataFrame:
|
|
74
|
+
"""Run a job and return streamed results.
|
|
75
|
+
|
|
76
|
+
The endpoint-specific stream mapper is applied by default, so that the column names match those of the
|
|
77
|
+
Cypher endpoints. Pass `apply_mapping=False` if the caller maps the result itself.
|
|
78
|
+
"""
|
|
72
79
|
show_progress = config.get("logProgress", True) and self._show_progress
|
|
73
80
|
job_id = JobClient.run_job_and_wait(self._arrow_client, endpoint, config, show_progress=show_progress)
|
|
74
|
-
|
|
81
|
+
result = JobClient.stream_results(self._arrow_client, G.name(), job_id)
|
|
82
|
+
return apply_stream_mapper(endpoint, result) if apply_mapping else result
|
|
75
83
|
|
|
76
84
|
def _run_job_and_write(
|
|
77
85
|
self,
|
|
@@ -23,7 +23,6 @@ from graphdatascience.procedure_surface.arrow.pathfinding.single_source_delta_ar
|
|
|
23
23
|
from graphdatascience.procedure_surface.arrow.pathfinding.single_source_dijkstra_arrow_endpoints import (
|
|
24
24
|
SingleSourceDijkstraArrowEndpoints,
|
|
25
25
|
)
|
|
26
|
-
from graphdatascience.procedure_surface.arrow.stream_result_mapper import map_all_shortest_path_stream_result
|
|
27
26
|
from graphdatascience.procedure_surface.arrow.table_endpoints_helper import TableEndpointsHelper
|
|
28
27
|
from graphdatascience.session.remote_ops.write_protocols import WriteProtocol
|
|
29
28
|
|
|
@@ -89,9 +88,7 @@ class AllShortestPathArrowEndpoints(AllShortestPathEndpoints):
|
|
|
89
88
|
relationship_weight_property=relationship_weight_property,
|
|
90
89
|
)
|
|
91
90
|
|
|
92
|
-
|
|
93
|
-
map_all_shortest_path_stream_result(result)
|
|
94
|
-
return result
|
|
91
|
+
return self._endpoint_helper.run_job_and_stream("v2/pathfinding.allShortestPaths", G, config)
|
|
95
92
|
|
|
96
93
|
def estimate(
|
|
97
94
|
self,
|
|
@@ -84,7 +84,8 @@ class BFSArrowEndpoints(BFSEndpoints):
|
|
|
84
84
|
targetNodes=target_nodes,
|
|
85
85
|
)
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
# aggregation is done here instead of via the stream mapper, as the source node is known upfront
|
|
88
|
+
result = self._endpoints_helper.run_job_and_stream("v2/pathfinding.bfs", G, config, apply_mapping=False)
|
|
88
89
|
|
|
89
90
|
return aggregate_traversal_rels(result, source_node)
|
|
90
91
|
|
|
@@ -84,7 +84,8 @@ class DFSArrowEndpoints(DFSEndpoints):
|
|
|
84
84
|
targetNodes=target_nodes,
|
|
85
85
|
)
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
# aggregation is done here instead of via the stream mapper, as the source node is known upfront
|
|
88
|
+
result = self._endpoints_helper.run_job_and_stream("v2/pathfinding.dfs", G, config, apply_mapping=False)
|
|
88
89
|
|
|
89
90
|
return aggregate_traversal_rels(result, source_node)
|
|
90
91
|
|
|
@@ -15,7 +15,6 @@ from graphdatascience.procedure_surface.api.pathfinding.dijkstra_endpoints impor
|
|
|
15
15
|
DijkstraWriteResult,
|
|
16
16
|
)
|
|
17
17
|
from graphdatascience.procedure_surface.arrow.relationship_endpoints_helper import RelationshipEndpointsHelper
|
|
18
|
-
from graphdatascience.procedure_surface.arrow.stream_result_mapper import map_shortest_path_stream_result
|
|
19
18
|
from graphdatascience.session.remote_ops.write_protocols import WriteProtocol
|
|
20
19
|
|
|
21
20
|
|
|
@@ -88,9 +87,7 @@ class DijkstraArrowEndpoints(DijkstraEndpoints):
|
|
|
88
87
|
jobId=job_id,
|
|
89
88
|
)
|
|
90
89
|
|
|
91
|
-
|
|
92
|
-
map_shortest_path_stream_result(result)
|
|
93
|
-
return result
|
|
90
|
+
return self._endpoints_helper.run_job_and_stream("v2/pathfinding.sourceTarget.dijkstra", G, config)
|
|
94
91
|
|
|
95
92
|
def mutate(
|
|
96
93
|
self,
|
|
@@ -8,7 +8,6 @@ from graphdatascience.procedure_surface.api.default_values import ALL_LABELS, AL
|
|
|
8
8
|
from graphdatascience.procedure_surface.api.job_handle import JobHandle
|
|
9
9
|
from graphdatascience.procedure_surface.api.pathfinding.longest_path_endpoints import LongestPathEndpoints
|
|
10
10
|
from graphdatascience.procedure_surface.arrow.relationship_endpoints_helper import RelationshipEndpointsHelper
|
|
11
|
-
from graphdatascience.procedure_surface.arrow.stream_result_mapper import map_shortest_path_stream_result
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
class LongestPathArrowEndpoints(LongestPathEndpoints):
|
|
@@ -72,7 +71,4 @@ class LongestPathArrowEndpoints(LongestPathEndpoints):
|
|
|
72
71
|
jobId=job_id,
|
|
73
72
|
)
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
map_shortest_path_stream_result(result)
|
|
77
|
-
|
|
78
|
-
return result
|
|
74
|
+
return self._endpoints_helper.run_job_and_stream("v2/pathfinding.longestPath", G, config)
|