15from typing
import Iterable, List, Literal, Optional, Sequence, Tuple
31 client: NebulaBaseExecutor,
32 scan_type: Literal[
"node",
"edge"],
36 properties_list: Sequence[str],
37 batch_size: int = 1024,
40 Scan nodes/edges on graph in a given storage partition.
43 client: The client to use for the scan.
44 scan_type: The type of the scan. "node" or "edge".
45 partition_id: The partition id to scan.
46 graph_name: Filter the name of the graph.
47 type_name: Filter the name of the node/edge type.
48 properties_list: Return the properties of the node/edge.
49 batch_size: The batch size when scanning the nodes/edges.
52 An iterable of records.
54 if scan_type ==
"node":
55 query =
"CALL cursor_node_scan({{graph_name}}, {{type_name}}, {{properties_list}}, {{partition_id}}, {{cursor}}, {{batch_size}}) RETURN *"
56 elif scan_type ==
"edge":
57 query =
"CALL cursor_edge_scan({{graph_name}}, {{type_name}}, {{properties_list}}, {{partition_id}}, {{cursor}}, {{batch_size}}) RETURN *"
63 raise ValueError(f
"Invalid scan type: {scan_type}")
67 result = client.execute_py(
70 "graph_name": graph_name,
71 "type_name": type_name,
72 "properties_list": properties_list,
73 "partition_id": partition_id,
74 "batch_size": batch_size,
80 cursor = result.extra_info.cursor
86 client: NebulaBaseExecutor,
87 scan_type: Literal[
"node",
"edge"],
88 graph_name: str |
None =
None,
89 type_name: str |
None =
None,
90 graph_type_name: Optional[str] =
None,
91 properties_list: Optional[Sequence[str]] =
None,
92 batch_size: int = 1024,
95 Scan nodes/edges on graph.
98 client: The client to use for the scan.
99 scan_type: The type of the scan. "node" or "edge".
100 graph_name: Filter the name of the graph.
101 type_name: Filter the name of the node/edge type.
102 graph_type_name: Filter the name of the graph type.
103 properties_list: Return the properties of the node/edge. Default to None means all properties.
104 batch_size: The batch size when scanning the nodes/edges.
107 An iterable of records.
109 graph_name = graph_name
or get_home_graph_name(client)
111 raise ValueError(
"type_name is required for scan")
112 graph_type_name = graph_type_name
or get_graph_type_name(client, graph_name)
115 if properties_list
is not None
117 list(get_node_type(client, type_name, graph_type_name).properties.keys())
118 if scan_type ==
"node"
120 get_edge_type(client, type_name, graph_type_name).properties.keys()
124 partitions: List[int] = client.execute_py(
125 "CALL show_partitions() RETURN partition_id"
126 ).as_primitive_by_column()[
"partition_id"]
129 partitions = [p
for p
in partitions
if p != 0]
131 for partition_id
in partitions:
132 for record
in _scan_partition(
135 partition_id=partition_id,
136 graph_name=graph_name,
138 properties_list=properties_list,
139 batch_size=batch_size,
145 client: NebulaBaseExecutor,
147 graph_name: str |
None =
None,
149 graph_type_name: Optional[str] =
None,
150 properties_list: Optional[Sequence[str]] =
None,
151 batch_size: int = 1024,
153 graph_name = graph_name
or get_home_graph_name(client)
155 raise ValueError(
"type_name is required for scan_nodes")
156 graph_type_name = graph_type_name
or get_graph_type_name(client, graph_name)
159 if properties_list
is not None
162 for k, v
in get_node_type(
163 client, type_name, graph_type_name
165 if not v.data_type.startswith(
171 TODO: scan with vector properties will cause error.
172 CREATE GRAPH TYPE test_scan_type {
173 NODE node1 ({n STRING PRIMARY KEY, emb1 VECTOR<3, FLOAT>})
175CREATE GRAPH test_scan test_scan_type
176SESSION SET GRAPH test_scan
177INSERT (@node1 {n: "foo", emb1: VECTOR<3, FLOAT>([1.0, 2.0, 3.0])})
179CALL {CALL show_partitions() RETURN collect(partition_id) AS parts GROUP BY ()}
181CALL cursor_node_scan("test_scan", "node1", ["n", "emb1"], part, "", 999) RETURN *
186 graph_name=graph_name,
188 graph_type_name=graph_type_name,
189 properties_list=properties_list,
190 batch_size=batch_size,
192 yield record[
"node"].as_node()
196 client: NebulaBaseExecutor,
197 graph_name: str |
None =
None,
198 type_name: str |
None =
None,
199 graph_type_name: Optional[str] =
None,
200 properties_list: Optional[Sequence[str]] =
None,
201 batch_size: int = 1024,
202) -> Iterable[Tuple[Node, Edge, Node]]:
203 graph_name = graph_name
or get_home_graph_name(client)
205 raise ValueError(
"type_name is required for scan_edges")
206 graph_type_name = graph_type_name
or get_graph_type_name(client, graph_name)
209 if properties_list
is not None
212 for k, v
in get_edge_type(
213 client, type_name, graph_type_name
215 if not v.data_type.startswith(
223 graph_name=graph_name,
225 graph_type_name=graph_type_name,
226 properties_list=properties_list,
227 batch_size=batch_size,
230 record[
"src"].as_node(),
231 record[
"edge"].as_edge(),
232 record[
"dst"].as_node(),