Skip to content

Commit 7067127

Browse files
authored
Merge pull request #5317 from DarthMax/client_arrow_documentation
Document graph construction in python client
2 parents 98a713a + 48dc230 commit 7067127

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

doc/asciidoc/management-ops/graph-catalog/graph-project-apache-arrow.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Given an example node such as `(:Pokemon { weight: 8.5, height: 0.6, hp: 39 })`,
100100
[[arrow-node-schema]]
101101
[opts=header,cols="1,1,1,1,1"]
102102
|===
103-
| node_id | label | weight | height | hp
103+
| nodeId | label | weight | height | hp
104104
| 0 | "Pokemon" | 8.5 | 0.6 | 39
105105
|===
106106

@@ -110,7 +110,7 @@ The following table describes the node columns with reserved names.
110110
[opts=header,cols="1m,1,1,1,1"]
111111
|===
112112
| Name | Type | Optional | Nullable | Description
113-
| node_id | Integer | No | No | Unique 64-bit node identifiers for the in-memory graph. Must be positive values.
113+
| nodeId | Integer | No | No | Unique 64-bit node identifiers for the in-memory graph. Must be positive values.
114114
| label | String or Integer | Yes | No | Single node label. Either a string literal or a dictionary encoded number.
115115
|===
116116

@@ -159,7 +159,7 @@ For example, given the relationship `(a)-[:EVOLVES_TO { at_level: 16 }]->(b)` an
159159
[[arrow-relationship-schema]]
160160
[opts=header,cols="1,1,1,1"]
161161
|===
162-
| source_id | target_id | type | at_level
162+
| sourceId | targetId | type | at_level
163163
| 0 | 1 | "EVOLVES_TO" | 16
164164
|===
165165

@@ -169,8 +169,8 @@ The following table describes the node columns with reserved names.
169169
[opts=header,cols="1m,1,1,1,1"]
170170
|===
171171
| Name | Type | Optional | Nullable | Description
172-
| source_id | Integer | No | No | Unique 64-bit source node identifiers. Must be positive values and present in the imported nodes.
173-
| target_id | Integer | No | No | Unique 64-bit target node identifiers. Must be positive values and present in the imported nodes.
172+
| sourceId | Integer | No | No | Unique 64-bit source node identifiers. Must be positive values and present in the imported nodes.
173+
| targetId | Integer | No | No | Unique 64-bit target node identifiers. Must be positive values and present in the imported nodes.
174174
| type | String or Integer | Yes | No | Single relationship type. Either a string literal or a dictionary encoded number.
175175
|===
176176

doc/asciidoc/pythonclient/python-client-graph-object.adoc

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Additionally, the `Graph` objects have convenience methods allowing for inspecti
1111
include::python-client-gds-object.adoc[]
1212

1313

14-
== Constructing a graph object
14+
== Projecting a graph object
1515

16-
There are several ways of constructing a graph object.
16+
There are several ways of projecting a graph object.
1717
The simplest way is to do a <<graph-project-native-syntax, native projection>>:
1818

1919
[source,python]
@@ -41,14 +41,64 @@ To get a graph object that represents a graph that has already been projected in
4141
G = gds.graph.get("my-graph")
4242
----
4343

44-
In addition to those aforementioned there are three more methods that construct graph objects:
44+
In addition to those aforementioned there are three more methods that create graph objects:
4545

4646
* `gds.graph.project.cypher`
4747
* `gds.beta.graph.subgraph`
4848
* `gds.beta.graph.generate`
4949

5050
Their Cypher signatures map to Python in much the same way as `gds.graph.project` above.
5151

52+
[.enterprise-edition]
53+
== Constructing a graph
54+
55+
Instead of projecting a graph from the Neo4j database it is also possible to construct new graphs using pandas `DataFrames` from the client.
56+
57+
NOTE: To use this feature the <<installation-apache-arrow, Arrow Flight Server>> needs to be enabled.
58+
59+
[source,python]
60+
----
61+
nodes = pandas.DataFrame(
62+
"nodeId": [0, 1, 2, 3],
63+
"label": ["A", "B", "C", "A"],
64+
"prop1": [42, 1337, 8, 0],
65+
"otherProperty": [0.1, 0.2, 0.3, 0.4]
66+
)
67+
68+
relationships = pandas.DataFrame(
69+
"sourceId": [0, 1, 2, 3],
70+
"targetId": [1, 2, 3, 0],
71+
"type": ["REL", "REL", "REL", "REL"],
72+
"weight": [0.0, 0.0, 0.1, 42.0]
73+
)
74+
75+
G = gds.alpha.graph.construct(
76+
"my-graph", # Graph name
77+
nodes, # One or more dataframes containing node data
78+
relationships # One or more dataframes containing relationship data
79+
)
80+
----
81+
82+
The above example creates a simple graph using one node and one relationship `DataFrame`.
83+
The created graph is equivalent to a graph created by the following Cypher query:
84+
85+
[source, cypher]
86+
----
87+
CREATE
88+
(a:A {prop1: 42, otherProperty: 0.1),
89+
(b:B {prop1: 1337, otherProperty: 0.2),
90+
(c:C {prop1: 8, otherProperty: 0.3),
91+
(d:A {prop1: 0, otherProperty: 0.4),
92+
(a)-[:REL {weight: 0.0}]->(b),
93+
(b)-[:REL {weight: 0.0}]->(c),
94+
(c)-[:REL {weight: 0.1}]->(d),
95+
(d)-[:REL {weight: 42.0}]->(a),
96+
----
97+
98+
It is possible to supply more than one data frame, both for nodes and relationships.
99+
If multiple node dataframes are used, they need to contain distinct node ids across all node data frames.
100+
The supported format for the node data frames is described in <<arrow-node-columns, Arrow node schema>> and the format for the relationship data frames is described in <<arrow-relationship-columns, Arrow relationship schema>>.
101+
52102

53103
== Inspecting a graph object
54104

0 commit comments

Comments
 (0)