Skip to content

Commit 5502db1

Browse files
authored
Features/gql apis (#2350)
* impl nodes select filtering in gql * change semantics of filters in gql, add missing filter apis in edges, fix all tests * add more edge filter tests * add filtering to path from node, add tests * fix apply views * rename filter-iter to select * add select as args * impl window filter (#2359) * impl window filter * impl window filter in python, add tests * impl gql window filter, add tests * ref * impl review suggestions * fixes * fix py and gql * add review suggestions
1 parent bd833e6 commit 5502db1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3469
-1874
lines changed

python/python/raphtory/filter/__init__.pyi

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ __all__ = [
3131
"Edge",
3232
"ExplodedEdge",
3333
"FilterOps",
34+
"PropertyFilterOps",
35+
"NodeWindow",
36+
"EdgeWindow",
37+
"ExplodedEdgeWindow",
3438
]
3539

3640
class FilterExpr(object):
@@ -84,6 +88,8 @@ class Node(object):
8488

8589
@staticmethod
8690
def property(name): ...
91+
@staticmethod
92+
def window(py_start, py_end): ...
8793

8894
class EdgeFilterOp(object):
8995
def __eq__(self, value):
@@ -125,12 +131,16 @@ class Edge(object):
125131
def property(name): ...
126132
@staticmethod
127133
def src(): ...
134+
@staticmethod
135+
def window(py_start, py_end): ...
128136

129137
class ExplodedEdge(object):
130138
@staticmethod
131139
def metadata(name): ...
132140
@staticmethod
133141
def property(name): ...
142+
@staticmethod
143+
def window(py_start, py_end): ...
134144

135145
class FilterOps(object):
136146
def __eq__(self, value):
@@ -169,3 +179,18 @@ class FilterOps(object):
169179
def not_contains(self, value): ...
170180
def starts_with(self, value): ...
171181
def sum(self): ...
182+
183+
class PropertyFilterOps(FilterOps):
184+
def temporal(self): ...
185+
186+
class NodeWindow(object):
187+
def metadata(self, name): ...
188+
def property(self, name): ...
189+
190+
class EdgeWindow(object):
191+
def metadata(self, name): ...
192+
def property(self, name): ...
193+
194+
class ExplodedEdgeWindow(object):
195+
def metadata(self, name): ...
196+
def property(self, name): ...

python/tests/test_base_install/test_filters/test_node_property_filter.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,3 +1104,38 @@ def check(graph):
11041104
graph.filter(filter_expr).nodes.id
11051105

11061106
return check
1107+
1108+
1109+
@with_disk_variants(create_test_graph, variants=("graph", "persistent_graph"))
1110+
def test_filter_nodes_temporal_window_sum_ge():
1111+
def check(graph):
1112+
expr = filter.Node.window(1, 2).property("prop5").temporal().last().sum() >= 12
1113+
assert sorted(graph.filter(expr).nodes.id) == ["c"]
1114+
1115+
expr = filter.Node.window(1, 2).property("prop5").temporal().last().sum() >= 6
1116+
assert sorted(graph.filter(expr).nodes.id) == ["a", "c"]
1117+
1118+
return check
1119+
1120+
1121+
@with_disk_variants(create_test_graph, variants=("graph", "persistent_graph"))
1122+
def test_filter_nodes_two_windows_and():
1123+
def check(graph):
1124+
filter1 = (
1125+
filter.Node.window(1, 2).property("prop5").temporal().first().sum() == 6
1126+
)
1127+
filter2 = (
1128+
filter.Node.window(2, 3).property("prop6").temporal().last().sum() == 12
1129+
)
1130+
assert sorted(graph.filter(filter1 & filter2).nodes.id) == ["a"]
1131+
1132+
return check
1133+
1134+
1135+
@with_disk_variants(create_test_graph, variants=("graph", "persistent_graph"))
1136+
def test_filter_nodes_window_out_of_range_is_empty():
1137+
def check(graph):
1138+
expr = filter.Node.window(10, 20).property("prop5").temporal().sum() >= 0
1139+
assert list(graph.filter(expr).nodes.id) == []
1140+
1141+
return check

python/tests/test_base_install/test_graphql/test_apply_views.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,13 @@ def test_apply_view_a_lot_of_views():
16491649
"graph": {
16501650
"nodes": {
16511651
"applyViews": {
1652-
"list": [{"history": [1735689600000, 1735776000000], "name": "1"}]
1652+
"list": [
1653+
{"history": [1735689600000], "name": "1"},
1654+
{"history": [], "name": "2"},
1655+
{"history": [], "name": "3"},
1656+
{"history": [], "name": "6"},
1657+
{"history": [], "name": "7"},
1658+
]
16531659
}
16541660
}
16551661
}

python/tests/test_base_install/test_graphql/test_filters/test_edge_filter_gql.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_filter_edges_with_str_ids_for_node_id_eq_gql(graph):
1212
query = """
1313
query {
1414
graph(path: "g") {
15-
edgeFilter(filter: {
15+
filterEdges(expr: {
1616
src: {
1717
field: NODE_ID
1818
where: { eq: { str: "3" } }
@@ -30,7 +30,7 @@ def test_filter_edges_with_str_ids_for_node_id_eq_gql(graph):
3030
"""
3131
expected_output = {
3232
"graph": {
33-
"edgeFilter": {
33+
"filterEdges": {
3434
"edges": {
3535
"list": [
3636
{"dst": {"name": "1"}, "src": {"name": "3"}},
@@ -52,7 +52,7 @@ def test_filter_edges_with_num_ids_for_node_id_eq_gql(graph):
5252
query = """
5353
query {
5454
graph(path: "g") {
55-
edgeFilter(filter: {
55+
filterEdges(expr: {
5656
src: {
5757
field: NODE_ID
5858
where: { eq: { u64: 1 } }
@@ -70,9 +70,39 @@ def test_filter_edges_with_num_ids_for_node_id_eq_gql(graph):
7070
"""
7171
expected_output = {
7272
"graph": {
73-
"edgeFilter": {
73+
"filterEdges": {
7474
"edges": {"list": [{"src": {"name": "1"}, "dst": {"name": "2"}}]}
7575
}
7676
}
7777
}
7878
run_graphql_test(query, expected_output, graph)
79+
80+
81+
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
82+
def test_edges_chained_selection_with_edge_filter(graph):
83+
query = """
84+
query {
85+
graph(path: "g") {
86+
edges {
87+
select(expr: { dst: {
88+
field: NODE_ID
89+
where: { eq: { u64: 2 } }
90+
} }) {
91+
select(expr: { property: { name: "p2", where: { gt:{ i64: 2 } } } }) {
92+
list { src { name } dst { name } }
93+
}
94+
}
95+
}
96+
}
97+
}
98+
"""
99+
expected_output = {
100+
"graph": {
101+
"edges": {
102+
"select": {
103+
"select": {"list": [{"dst": {"name": "2"}, "src": {"name": "1"}}]}
104+
}
105+
}
106+
}
107+
}
108+
run_graphql_test(query, expected_output, graph)

0 commit comments

Comments
 (0)