Skip to content

Commit 1dc045c

Browse files
committed
Add tests for mixed type arrow tables
1 parent a655e4d commit 1dc045c

2 files changed

Lines changed: 131 additions & 0 deletions

File tree

test/capi_xfails.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"test/test_arrow_memory_backed_table.py::test_arrow_memory_backed_table_with_pyarrow",
1717
"test/test_arrow_memory_backed_table.py::test_arrow_memory_backed_table_empty_result",
1818
"test/test_arrow_memory_backed_table.py::test_arrow_memory_backed_table_count",
19+
"test/test_arrow_memory_backed_table.py::test_arrow_memory_backed_arrow_node_and_rel_table",
20+
"test/test_arrow_memory_backed_table.py::test_arrow_memory_backed_native_node_and_arrow_rel_table",
1921
"test/test_async_connection.py::test_async_scan_df",
2022
"test/test_blob_parameter.py::test_bytes_param_udf",
2123
"test/test_df.py::test_to_df",

test/test_arrow_memory_backed_table.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,132 @@ def test_arrow_memory_backed_table_count(conn_db_empty: ConnDB) -> None:
273273

274274
# Clean up
275275
conn.drop_arrow_table("transactions")
276+
277+
278+
def test_arrow_memory_backed_arrow_node_and_rel_table(conn_db_empty: ConnDB) -> None:
279+
"""Test an Arrow memory-backed relationship over Arrow-backed nodes."""
280+
conn, _ = conn_db_empty
281+
282+
pa = pytest.importorskip("pyarrow")
283+
284+
people = pa.Table.from_arrays(
285+
[
286+
pa.array([1, 2, 3], type=pa.int64()),
287+
pa.array(["Alice", "Bob", "Carol"], type=pa.string()),
288+
],
289+
names=["id", "name"],
290+
)
291+
conn.create_arrow_table("arrow_people", people)
292+
293+
knows = pa.Table.from_arrays(
294+
[
295+
pa.array([1, 1, 2], type=pa.int64()),
296+
pa.array([2, 3, 3], type=pa.int64()),
297+
pa.array([10, 20, 30], type=pa.int64()),
298+
],
299+
names=["from", "to", "weight"],
300+
)
301+
conn.create_arrow_rel_table("arrow_knows", knows, "arrow_people", "arrow_people")
302+
303+
result = conn.execute(
304+
"MATCH (a:arrow_people)-[r:arrow_knows]->(b:arrow_people) "
305+
"RETURN a.name, b.name, r.weight ORDER BY a.id, b.id"
306+
)
307+
rows = []
308+
while result.has_next():
309+
rows.append(result.get_next())
310+
311+
assert rows == [
312+
["Alice", "Bob", 10],
313+
["Alice", "Carol", 20],
314+
["Bob", "Carol", 30],
315+
]
316+
317+
result = conn.execute(
318+
"MATCH (:arrow_people)-[r:arrow_knows]->(:arrow_people) "
319+
"RETURN COUNT(*), SUM(r.weight)"
320+
)
321+
assert result.get_next() == [3, 60]
322+
assert not result.has_next()
323+
324+
result = conn.execute(
325+
"MATCH (a:arrow_people)-[r:arrow_knows]->(b:arrow_people) "
326+
"WHERE r.weight >= 20 "
327+
"RETURN a.name, b.name, r.weight ORDER BY r.weight"
328+
)
329+
rows = []
330+
while result.has_next():
331+
rows.append(result.get_next())
332+
333+
assert rows == [
334+
["Alice", "Carol", 20],
335+
["Bob", "Carol", 30],
336+
]
337+
338+
conn.drop_arrow_table("arrow_knows")
339+
conn.drop_arrow_table("arrow_people")
340+
341+
342+
def test_arrow_memory_backed_native_node_and_arrow_rel_table(
343+
conn_db_empty: ConnDB,
344+
) -> None:
345+
"""Test an Arrow memory-backed relationship over native node tables."""
346+
conn, _ = conn_db_empty
347+
348+
pa = pytest.importorskip("pyarrow")
349+
350+
conn.execute(
351+
"CREATE NODE TABLE native_people(id INT64, name STRING, PRIMARY KEY(id));"
352+
"CREATE (:native_people {id: 1, name: 'Alice'});"
353+
"CREATE (:native_people {id: 2, name: 'Bob'});"
354+
"CREATE (:native_people {id: 3, name: 'Carol'});"
355+
)
356+
357+
knows = pa.Table.from_arrays(
358+
[
359+
pa.array([1, 1, 2], type=pa.int64()),
360+
pa.array([2, 3, 3], type=pa.int64()),
361+
pa.array([10, 20, 30], type=pa.int64()),
362+
],
363+
names=["from", "to", "weight"],
364+
)
365+
conn.create_arrow_rel_table(
366+
"native_people_arrow_knows", knows, "native_people", "native_people"
367+
)
368+
369+
result = conn.execute(
370+
"MATCH (a:native_people)-[r:native_people_arrow_knows]->(b:native_people) "
371+
"RETURN a.name, b.name, r.weight ORDER BY a.id, b.id"
372+
)
373+
rows = []
374+
while result.has_next():
375+
rows.append(result.get_next())
376+
377+
assert rows == [
378+
["Alice", "Bob", 10],
379+
["Alice", "Carol", 20],
380+
["Bob", "Carol", 30],
381+
]
382+
383+
result = conn.execute(
384+
"MATCH (:native_people)-[r:native_people_arrow_knows]->(:native_people) "
385+
"RETURN COUNT(*), SUM(r.weight)"
386+
)
387+
assert result.get_next() == [3, 60]
388+
assert not result.has_next()
389+
390+
result = conn.execute(
391+
"MATCH (a:native_people)-[r:native_people_arrow_knows]->(b:native_people) "
392+
"WHERE r.weight >= 20 "
393+
"RETURN a.name, b.name, r.weight ORDER BY r.weight"
394+
)
395+
rows = []
396+
while result.has_next():
397+
rows.append(result.get_next())
398+
399+
assert rows == [
400+
["Alice", "Carol", 20],
401+
["Bob", "Carol", 30],
402+
]
403+
404+
conn.drop_arrow_table("native_people_arrow_knows")

0 commit comments

Comments
 (0)