-
Notifications
You must be signed in to change notification settings - Fork 60
Replace existing filters/filtering Raphtory APIs with composite filters and APIs/ Write tests #1982 #1991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shivamka1
wants to merge
51
commits into
master
Choose a base branch
from
features/new-filter-apis
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+12,681
−8,654
Open
Replace existing filters/filtering Raphtory APIs with composite filters and APIs/ Write tests #1982 #1991
Changes from 50 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
3a10189
restruct filters package, impl node filter graph
shivamka1 40b44fb
fix bench
shivamka1 7d4dff6
impl and/or as left and right composition instead of vec, fix tests
shivamka1 03efde7
replace struct based filter expr with trait based abstraction, fix al…
shivamka1 43acbe5
impl node field filtered graph
shivamka1 9d1f73a
impl edge field filtered graph
shivamka1 847e5ea
ref edge property filter
shivamka1 0bab9d6
impl and/or filtered graph
shivamka1 48a3a7d
Merge branch 'master' into features/new-filter-apis
shivamka1 67fe9a5
fix bench
shivamka1 5271646
ref
shivamka1 2432809
fix graphql for new filter abs
shivamka1 864027c
impl filter abs in python
shivamka1 1ce7ea3
impl python for new filter expr abstraction
shivamka1 32931f1
make filter expr work with filter apis
shivamka1 2cbe89f
fix infinite recursion
ljeub-pometry f85981d
fix/add py tests
shivamka1 733318c
more python tests
shivamka1 3827c90
fmt
shivamka1 f782b8c
fix tests
shivamka1 ce93d7b
add filter api tests for rest WIP
shivamka1 119546d
move search tests and ref
shivamka1 2d78d03
ref, fix tests
shivamka1 4b325f1
Merge branch 'master' into features/new-filter-apis
shivamka1 db2fa3c
impl filter tests for cached view graph
shivamka1 40df3e9
ref persistent graph
shivamka1 c046d2e
impl filter tests for layered graph
shivamka1 2eb7aa1
impl filter tests for node subgraph
shivamka1 1a655be
impl tests for node type filtered subgraph view
shivamka1 95d079c
impl filter tests for window graph
shivamka1 3772d4c
ref tests
shivamka1 3bb8be8
fix tests
shivamka1 9038605
fix tests
shivamka1 9611982
fix tests
shivamka1 49025dc
fix semantics
shivamka1 f2dc3eb
impl name, type builder in python
shivamka1 5511068
fix tests
shivamka1 ed208e7
fix tests
shivamka1 92c0fb8
change includes/excludes to is_in/is_not_in
shivamka1 07ada34
ref
shivamka1 29c111a
add fuzzy search filter test
shivamka1 30ed02f
impl contains and contains_not for filter
shivamka1 b5f10cf
support both tokenized and non-tokenized search queries
shivamka1 60a3a69
impl filter_expr for graphql fitler apis, fix all warnings, impl/fix …
shivamka1 84d12cd
merge from master
shivamka1 947268b
fixed bug where graphql property model for list was not getting trans…
shivamka1 6d041f8
ref, fix tests, rid duplicate tests
shivamka1 3401e12
Merge branch 'master' into features/new-filter-apis
shivamka1 d5c67b6
merge from master
shivamka1 67481fb
Merge branch 'master' into features/new-filter-apis
shivamka1 462e776
Merge branch 'master' into features/new-filter-apis
shivamka1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
196 changes: 196 additions & 0 deletions
196
python/tests/test_base_install/test_filters/semantics/test_edge_property_filter_semantics.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
from raphtory import Graph, PersistentGraph, Prop | ||
from raphtory import filter | ||
|
||
|
||
def init_graph(graph): | ||
edges = [ | ||
(6, "N1", "N2", {"p1": 2}), | ||
(7, "N1", "N2", {"p1": 1}), | ||
(6, "N2", "N3", {"p1": 1}), | ||
(7, "N2", "N3", {"p1": 2}), | ||
(8, "N3", "N4", {"p1": 1}), | ||
(9, "N4", "N5", {"p1": 1}), | ||
(5, "N5", "N6", {"p1": 1}), | ||
(6, "N5", "N6", {"p1": 2}), | ||
(5, "N6", "N7", {"p1": 1}), | ||
(6, "N6", "N7", {"p1": 1}), | ||
(3, "N7", "N8", {"p1": 1}), | ||
(5, "N7", "N8", {"p1": 1}), | ||
(3, "N8", "N9", {"p1": 1}), | ||
(4, "N8", "N9", {"p1": 2}), | ||
(2, "N9", "N10", {"p1": 2}), | ||
(2, "N10", "N11", {"q1": 0}), | ||
(2, "N10", "N11", {"p1": 3}), | ||
(2, "N11", "N12", {"p1": 3}), | ||
(2, "N11", "N12", {"q1": 0}), | ||
(2, "N12", "N13", {"q1": 0}), | ||
(3, "N12", "N13", {"p1": 3}), | ||
(2, "N13", "N14", {"q1": 0}), | ||
(3, "N13", "N14", {"p1": 3}), | ||
(2, "N14", "N15", {"q1": 0}), | ||
(2, "N15", "N1", {}), | ||
] | ||
|
||
for time, src, dst, props in edges: | ||
graph.add_edge(time, src, dst, props) | ||
|
||
constant_properties = [ | ||
("N1", "N2", {"p1": 1}), | ||
("N4", "N5", {"p1": 2}), | ||
("N9", "N10", {"p1": 1}), | ||
("N10", "N11", {"p1": 1}), | ||
("N11", "N12", {"p1": 1}), | ||
("N12", "N13", {"p1": 1}), | ||
("N13", "N14", {"p1": 1}), | ||
("N14", "N15", {"p1": 1}), | ||
("N15", "N1", {"p1": 1}), | ||
] | ||
|
||
for src, dst, props in constant_properties: | ||
graph.edge(src, dst).add_constant_properties(props) | ||
|
||
return graph | ||
|
||
|
||
def init_graph_for_secondary_indexes(graph): | ||
edges = [ | ||
(1, "N16", "N15", {"p1": 2}), | ||
(1, "N16", "N15", {"p1": 1}), | ||
(1, "N17", "N16", {"p1": 1}), | ||
(1, "N17", "N16", {"p1": 2}), | ||
] | ||
|
||
for time, src, dst, props in edges: | ||
graph.add_edge(time, src, dst, props) | ||
|
||
return graph | ||
|
||
|
||
def test_constant_semantics(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
|
||
filter_expr = filter.Property("p1").constant() == 1 | ||
result_ids = sorted(graph.filter_edges(filter_expr).edges.id) | ||
expected_ids = sorted([("N1","N2"), ("N10","N11"), ("N11","N12"), ("N12","N13"), ("N13","N14"), ("N14","N15"), ("N15","N1"), ("N9","N10")]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_temporal_any_semantics(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
|
||
filter_expr = filter.Property("p1").temporal().any() == 1 | ||
|
||
result_ids = sorted(graph.filter_edges(filter_expr).edges.id) | ||
expected_ids = sorted([("N1","N2"), ("N2","N3"), ("N3","N4"), ("N4","N5"), ("N5","N6"), ("N6","N7"), ("N7","N8"),("N8","N9")]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_temporal_any_semantics_for_secondary_indexes(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
graph = init_graph_for_secondary_indexes(graph) | ||
|
||
filter_expr = filter.Property("p1").temporal().any() == 1 | ||
|
||
result_ids = sorted(graph.filter_edges(filter_expr).edges.id) | ||
expected_ids = sorted([("N1","N2"), ("N16","N15"), ("N17","N16"), ("N2","N3"), ("N3","N4"), ("N4","N5"), ("N5","N6"), ("N6","N7"), ("N7","N8"), ("N8","N9")]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_temporal_latest_semantics(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
|
||
filter_expr = filter.Property("p1").temporal().latest() == 1 | ||
result_ids = sorted(graph.filter_edges(filter_expr).edges.id) | ||
expected_ids = sorted([("N1","N2"), ("N3","N4"), ("N4","N5"), ("N6","N7"), ("N7","N8")]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_temporal_latest_semantics_for_secondary_indexes(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
graph = init_graph_for_secondary_indexes(graph) | ||
|
||
filter_expr = filter.Property("p1").temporal().latest() == 1 | ||
result_ids = sorted(graph.filter_edges(filter_expr).edges.id) | ||
expected_ids = sorted([("N1","N2"), ("N16","N15"), ("N3","N4"), ("N4","N5"), ("N6","N7"), ("N7","N8")]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_property_semantics(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
|
||
filter_expr = filter.Property("p1") == 1 | ||
result_ids = sorted(graph.filter_edges(filter_expr).edges.id) | ||
expected_ids = sorted([("N1","N2"), ("N14","N15"), ("N15","N1"), ("N3","N4"), ("N4","N5"), ("N6","N7"), ("N7","N8")]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_property_semantics_for_secondary_indexes(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
graph = init_graph_for_secondary_indexes(graph) | ||
|
||
filter_expr = filter.Property("p1") == 1 | ||
result_ids = sorted(graph.filter_edges(filter_expr).edges.id) | ||
expected_ids = sorted([("N1","N2"), ("N14","N15"), ("N15","N1"), ("N16","N15"), ("N3","N4"), ("N4","N5"), ("N6","N7"), ("N7","N8")]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_property_semantics_only_constant(): | ||
# For this graph there won't be any temporal property index for property name "p1". | ||
graph = Graph() | ||
edges = [ | ||
(2, "N1", "N2", {"q1": 0}), | ||
(2, "N2", "N3", {}), | ||
] | ||
|
||
for time, src, dst, props in edges: | ||
graph.add_edge(time, src, dst, props) | ||
|
||
constant_properties = [ | ||
("N1", "N2", {"p1": 1}), | ||
("N2", "N3", {"p1": 1}), | ||
] | ||
|
||
for src, dst, props in constant_properties: | ||
graph.edge(src, dst).add_constant_properties(props) | ||
|
||
filter_expr = filter.Property("p1") == 1 | ||
result_ids = sorted(graph.filter_edges(filter_expr).edges.id) | ||
expected_ids = sorted([("N1","N2"), ("N2","N3")]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_property_semantics_only_temporal(): | ||
# For this graph there won't be any constant property index for property name "p1". | ||
graph = Graph() | ||
|
||
edges = [ | ||
(2, "N1", "N2", {"p1": 1}), | ||
(2, "N2", "N3", {"p1": 1}), | ||
(2, "N2", "N3", {"p1": 2}), | ||
(2, "N3", "N4", {"p1": 2}), | ||
(2, "N3", "N4", {"p1": 1}), | ||
(2, "N4", "N5", {}), | ||
] | ||
|
||
for time, src, dst, props in edges: | ||
graph.add_edge(time, src, dst, props) | ||
|
||
constant_properties = [ | ||
("N1", "N2", {"p2": 1}), | ||
] | ||
|
||
for src, dst, props in constant_properties: | ||
graph.edge(src, dst).add_constant_properties(props) | ||
|
||
filter_expr = filter.Property("p1") == 1 | ||
result_ids = sorted(graph.filter_edges(filter_expr).edges.id) | ||
expected_ids = sorted([("N1","N2"), ("N3","N4")]) | ||
assert result_ids == expected_ids | ||
|
195 changes: 195 additions & 0 deletions
195
python/tests/test_base_install/test_filters/semantics/test_node_property_filter_semantics.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
from raphtory import Graph, PersistentGraph, Prop | ||
from raphtory import filter | ||
|
||
|
||
def init_graph(graph): | ||
nodes = [ | ||
(6, "N1", {"p1": 2}), | ||
(7, "N1", {"p1": 1}), | ||
(6, "N2", {"p1": 1}), | ||
(7, "N2", {"p1": 2}), | ||
(8, "N3", {"p1": 1}), | ||
(9, "N4", {"p1": 1}), | ||
(5, "N5", {"p1": 1}), | ||
(6, "N5", {"p1": 2}), | ||
(5, "N6", {"p1": 1}), | ||
(6, "N6", {"p1": 1}), | ||
(3, "N7", {"p1": 1}), | ||
(5, "N7", {"p1": 1}), | ||
(3, "N8", {"p1": 1}), | ||
(4, "N8", {"p1": 2}), | ||
(2, "N9", {"p1": 2}), | ||
(2, "N10", {"q1": 0}), | ||
(2, "N10", {"p1": 3}), | ||
(2, "N11", {"p1": 3}), | ||
(2, "N11", {"q1": 0}), | ||
(2, "N12", {"q1": 0}), | ||
(3, "N12", {"p1": 3}), | ||
(2, "N13", {"q1": 0}), | ||
(3, "N13", {"p1": 3}), | ||
(2, "N14", {"q1": 0}), | ||
(2, "N15", {}), | ||
] | ||
|
||
for time, label, props in nodes: | ||
graph.add_node(time, label, props) | ||
|
||
constant_properties = { | ||
"N1": {"p1": 1}, | ||
"N4": {"p1": 2}, | ||
"N9": {"p1": 1}, | ||
"N10": {"p1": 1}, | ||
"N11": {"p1": 1}, | ||
"N12": {"p1": 1}, | ||
"N13": {"p1": 1}, | ||
"N14": {"p1": 1}, | ||
"N15": {"p1": 1}, | ||
} | ||
|
||
for label, props in constant_properties.items(): | ||
graph.node(label).add_constant_properties(props) | ||
|
||
return graph | ||
|
||
|
||
def init_graph_for_secondary_indexes(graph): | ||
graph.add_node(1, "N16", {"p1": 2}) | ||
graph.add_node(1, "N16", {"p1": 1}) | ||
|
||
graph.add_node(1, "N17", {"p1": 1}) | ||
graph.add_node(1, "N17", {"p1": 2}) | ||
|
||
return graph | ||
|
||
|
||
def test_constant_semantics(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
|
||
filter_expr = filter.Property("p1").constant() == 1 | ||
result_ids = sorted(graph.filter_nodes(filter_expr).nodes.id) | ||
expected_ids = sorted(["N1", "N10", "N11", "N12", "N13", "N14", "N15", "N9"]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_temporal_any_semantics(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
|
||
filter_expr = filter.Property("p1").temporal().any() == 1 | ||
|
||
result_ids = sorted(graph.filter_nodes(filter_expr).nodes.id) | ||
expected_ids = sorted(["N1", "N2", "N3", "N4", "N5", "N6", "N7", "N8"]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_temporal_any_semantics_for_secondary_indexes(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
graph = init_graph_for_secondary_indexes(graph) | ||
|
||
filter_expr = filter.Property("p1").temporal().any() == 1 | ||
|
||
result_ids = sorted(graph.filter_nodes(filter_expr).nodes.id) | ||
expected_ids = sorted(["N1", "N16", "N17", "N2", "N3", "N4", "N5", "N6", "N7", "N8"]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_temporal_latest_semantics(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
|
||
filter_expr = filter.Property("p1").temporal().latest() == 1 | ||
result_ids = sorted(graph.filter_nodes(filter_expr).nodes.id) | ||
expected_ids = sorted(["N1", "N3", "N4", "N6", "N7"]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_temporal_latest_semantics_for_secondary_indexes(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
graph = init_graph_for_secondary_indexes(graph) | ||
|
||
filter_expr = filter.Property("p1").temporal().latest() == 1 | ||
result_ids = sorted(graph.filter_nodes(filter_expr).nodes.id) | ||
expected_ids = sorted(["N1", "N16", "N3", "N4", "N6", "N7"]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_property_semantics(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
|
||
filter_expr = filter.Property("p1") == 1 | ||
result_ids = sorted(graph.filter_nodes(filter_expr).nodes.id) | ||
expected_ids = sorted(["N1", "N14", "N15", "N3", "N4", "N6", "N7"]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_property_semantics_for_secondary_indexes(): | ||
graph = Graph() | ||
graph = init_graph(graph) | ||
graph = init_graph_for_secondary_indexes(graph) | ||
|
||
filter_expr = filter.Property("p1") == 1 | ||
result_ids = sorted(graph.filter_nodes(filter_expr).nodes.id) | ||
expected_ids = sorted(["N1", "N14", "N15", "N16", "N3", "N4", "N6", "N7"]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_property_semantics_only_constant(): | ||
# For this graph there won't be any temporal property index for property name "p1". | ||
graph = Graph() | ||
nodes = [ | ||
(2, "N1", {"q1": 0}), | ||
(2, "N2", {}), | ||
] | ||
|
||
for time, label, props in nodes: | ||
graph.add_node(time, label, props) | ||
|
||
constant_properties = { | ||
"N1": {"p1": 1}, | ||
"N2": {"p1": 1}, | ||
} | ||
|
||
for label, props in constant_properties.items(): | ||
graph.node(label).add_constant_properties(props) | ||
|
||
filter_expr = filter.Property("p1") == 1 | ||
result_ids = sorted(graph.filter_nodes(filter_expr).nodes.id) | ||
expected_ids = sorted(["N1", "N2"]) | ||
assert result_ids == expected_ids | ||
|
||
|
||
def test_property_semantics_only_temporal(): | ||
# For this graph there won't be any constant property index for property name "p1". | ||
graph = Graph() | ||
nodes = [ | ||
(1, "N1", {"p1": 1}), | ||
|
||
(2, "N2", {"p1": 1}), | ||
(3, "N2", {"p1": 2}), | ||
|
||
(2, "N3", {"p1": 2}), | ||
(3, "N3", {"p1": 1}), | ||
|
||
(2, "N4", {}), | ||
] | ||
|
||
for time, label, props in nodes: | ||
graph.add_node(time, label, props) | ||
|
||
constant_properties = { | ||
"N1": {"p2": 1}, | ||
"N2": {"p1": 1}, | ||
} | ||
|
||
for label, props in constant_properties.items(): | ||
graph.node(label).add_constant_properties(props) | ||
|
||
filter_expr = filter.Property("p1") == 1 | ||
result_ids = sorted(graph.filter_nodes(filter_expr).nodes.id) | ||
expected_ids = sorted(["N1", "N3"]) | ||
assert result_ids == expected_ids | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put all init graphs in the same place?