Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions python/python/raphtory/filter/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ __all__ = [
"Edge",
"ExplodedEdge",
"FilterOps",
"PropertyFilterOps",
"NodeWindow",
"EdgeWindow",
"ExplodedEdgeWindow",
]

class FilterExpr(object):
Expand Down Expand Up @@ -84,6 +88,8 @@ class Node(object):

@staticmethod
def property(name): ...
@staticmethod
def window(py_start, py_end): ...

class EdgeFilterOp(object):
def __eq__(self, value):
Expand Down Expand Up @@ -125,12 +131,16 @@ class Edge(object):
def property(name): ...
@staticmethod
def src(): ...
@staticmethod
def window(py_start, py_end): ...

class ExplodedEdge(object):
@staticmethod
def metadata(name): ...
@staticmethod
def property(name): ...
@staticmethod
def window(py_start, py_end): ...

class FilterOps(object):
def __eq__(self, value):
Expand Down Expand Up @@ -169,3 +179,18 @@ class FilterOps(object):
def not_contains(self, value): ...
def starts_with(self, value): ...
def sum(self): ...

class PropertyFilterOps(FilterOps):
def temporal(self): ...

class NodeWindow(object):
def metadata(self, name): ...
def property(self, name): ...

class EdgeWindow(object):
def metadata(self, name): ...
def property(self, name): ...

class ExplodedEdgeWindow(object):
def metadata(self, name): ...
def property(self, name): ...
Original file line number Diff line number Diff line change
Expand Up @@ -1104,3 +1104,38 @@ def check(graph):
graph.filter(filter_expr).nodes.id

return check


@with_disk_variants(create_test_graph, variants=("graph", "persistent_graph"))
def test_filter_nodes_temporal_window_sum_ge():
def check(graph):
expr = filter.Node.window(1, 2).property("prop5").temporal().last().sum() >= 12
assert sorted(graph.filter(expr).nodes.id) == ["c"]

expr = filter.Node.window(1, 2).property("prop5").temporal().last().sum() >= 6
assert sorted(graph.filter(expr).nodes.id) == ["a", "c"]

return check


@with_disk_variants(create_test_graph, variants=("graph", "persistent_graph"))
def test_filter_nodes_two_windows_and():
def check(graph):
filter1 = (
filter.Node.window(1, 2).property("prop5").temporal().first().sum() == 6
)
filter2 = (
filter.Node.window(2, 3).property("prop6").temporal().last().sum() == 12
)
assert sorted(graph.filter(filter1 & filter2).nodes.id) == ["a"]

return check


@with_disk_variants(create_test_graph, variants=("graph", "persistent_graph"))
def test_filter_nodes_window_out_of_range_is_empty():
def check(graph):
expr = filter.Node.window(10, 20).property("prop5").temporal().sum() >= 0
assert list(graph.filter(expr).nodes.id) == []

return check
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,13 @@ def test_apply_view_a_lot_of_views():
"graph": {
"nodes": {
"applyViews": {
"list": [{"history": [1735689600000, 1735776000000], "name": "1"}]
"list": [
{"history": [1735689600000], "name": "1"},
{"history": [], "name": "2"},
{"history": [], "name": "3"},
{"history": [], "name": "6"},
{"history": [], "name": "7"},
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_filter_edges_with_str_ids_for_node_id_eq_gql(graph):
query = """
query {
graph(path: "g") {
edgeFilter(filter: {
filterEdges(expr: {
src: {
field: NODE_ID
where: { eq: { str: "3" } }
Expand All @@ -30,7 +30,7 @@ def test_filter_edges_with_str_ids_for_node_id_eq_gql(graph):
"""
expected_output = {
"graph": {
"edgeFilter": {
"filterEdges": {
"edges": {
"list": [
{"dst": {"name": "1"}, "src": {"name": "3"}},
Expand All @@ -52,7 +52,7 @@ def test_filter_edges_with_num_ids_for_node_id_eq_gql(graph):
query = """
query {
graph(path: "g") {
edgeFilter(filter: {
filterEdges(expr: {
src: {
field: NODE_ID
where: { eq: { u64: 1 } }
Expand All @@ -70,9 +70,39 @@ def test_filter_edges_with_num_ids_for_node_id_eq_gql(graph):
"""
expected_output = {
"graph": {
"edgeFilter": {
"filterEdges": {
"edges": {"list": [{"src": {"name": "1"}, "dst": {"name": "2"}}]}
}
}
}
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_edges_chained_selection_with_edge_filter(graph):
query = """
query {
graph(path: "g") {
edges {
select(expr: { dst: {
field: NODE_ID
where: { eq: { u64: 2 } }
} }) {
select(expr: { property: { name: "p2", where: { gt:{ i64: 2 } } } }) {
list { src { name } dst { name } }
}
}
}
}
}
"""
expected_output = {
"graph": {
"edges": {
"select": {
"select": {"list": [{"dst": {"name": "2"}, "src": {"name": "1"}}]}
}
}
}
}
run_graphql_test(query, expected_output, graph)
Loading