-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: refactor largest connected subgraph (#20)
* rename macro to largest-connected-subgraph * make the largest_connected_subgraph macro make a table that is vertex focused rather than a graph * fix unit tests after refactor * fix readme error for largest connected subgraph
- Loading branch information
1 parent
3f07b8d
commit 3d987c3
Showing
28 changed files
with
240 additions
and
235 deletions.
There are no files selected for viewing
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions
16
...largest_connected_subgraph_identifier.yml → ...graph/test_largest_connected_subgraph.yml
This file contains 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
22 changes: 22 additions & 0 deletions
22
...sts/models/test_largest_connected_subgraph/test_largest_connected_subgraph_1_subgraph.sql
This file contains 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,22 @@ | ||
with computed as ( | ||
{{ dbt_graph_theory.largest_connected_largest_connected_subgraph( | ||
input=ref('test_largest_connected_subgraph_1_subgraph_data') | ||
) }} | ||
), | ||
|
||
subgraph_members as ( | ||
select v.* from ( | ||
values | ||
('A', '1', array['A', 'B', 'C', 'D', 'E']), | ||
('B', '1', array['A', 'B', 'C', 'D', 'E']), | ||
('C', '1', array['A', 'B', 'C', 'D', 'E']), | ||
('D', '1', array['A', 'B', 'C', 'D', 'E']), | ||
('E', '1', array['A', 'B', 'C', 'D', 'E']) | ||
) as v (vertex, subgraph_id, subgraph_members) | ||
) | ||
|
||
select * from {{ cte_difference( | ||
'computed', | ||
'subgraph_members', | ||
fields=["vertex", "subgraph_id", "subgraph_members"] | ||
) }} |
29 changes: 29 additions & 0 deletions
29
...ls/test_largest_connected_subgraph/test_largest_connected_subgraph_2_subgraph_no_edge.sql
This file contains 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,29 @@ | ||
with computed as ( | ||
{{ dbt_graph_theory.largest_connected_largest_connected_subgraph( | ||
input=ref('test_largest_connected_subgraph_2_subgraph_no_edge_data') | ||
) }} | ||
), | ||
|
||
-- recast because vertex_2 is all null in seed data, interpreted as int dtype | ||
recast_computed as ( | ||
select | ||
vertex::text as vertex, | ||
subgraph_id, | ||
subgraph_members | ||
from | ||
computed | ||
), | ||
|
||
subgraph_members as ( | ||
select v.* from ( | ||
values | ||
('A', '1', array['A']), | ||
('B', '2', array['B']) | ||
) as v (vertex, subgraph_id, subgraph_members) | ||
) | ||
|
||
select * from {{ cte_difference( | ||
'recast_computed', | ||
'subgraph_members', | ||
fields=["vertex", "subgraph_id", "subgraph_members"] | ||
) }} |
20 changes: 20 additions & 0 deletions
20
...ls/test_largest_connected_subgraph/test_largest_connected_subgraph_3_subgraph_no_edge.sql
This file contains 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,20 @@ | ||
with computed as ( | ||
{{ dbt_graph_theory.largest_connected_largest_connected_subgraph( | ||
input=ref('test_largest_connected_subgraph_3_subgraph_no_edge_data') | ||
) }} | ||
), | ||
|
||
subgraph_members as ( | ||
select v.* from ( | ||
values | ||
('A', '1', array['A']), | ||
('B', '2', array['B']), | ||
('C', '3', array['C']) | ||
) as v (vertex, subgraph_id, subgraph_members) | ||
) | ||
|
||
select * from {{ cte_difference( | ||
'computed', | ||
'subgraph_members', | ||
fields=["vertex", "subgraph_id", "subgraph_members"] | ||
) }} |
26 changes: 26 additions & 0 deletions
26
...sts/models/test_largest_connected_subgraph/test_largest_connected_subgraph_4_subgraph.sql
This file contains 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,26 @@ | ||
with computed as ( | ||
{{ dbt_graph_theory.largest_connected_largest_connected_subgraph( | ||
input=ref('test_largest_connected_subgraph_4_subgraph_data') | ||
) }} | ||
), | ||
|
||
subgraph_members as ( | ||
select v.* from ( | ||
values | ||
('A', '1', array['A', 'B', 'C', 'D']), | ||
('B', '1', array['A', 'B', 'C', 'D']), | ||
('C', '1', array['A', 'B', 'C', 'D']), | ||
('D', '1', array['A', 'B', 'C', 'D']), | ||
('E', '2', array['E', 'F']), | ||
('F', '2', array['E', 'F']), | ||
('G', '3', array['G']), | ||
('H', '4', array['H', 'I']), | ||
('I', '4', array['H', 'I']) | ||
) as v (vertex, subgraph_id, subgraph_members) | ||
) | ||
|
||
select * from {{ cte_difference( | ||
'computed', | ||
'subgraph_members', | ||
fields=["vertex", "subgraph_id", "subgraph_members"] | ||
) }} |
27 changes: 27 additions & 0 deletions
27
...tests/models/test_largest_connected_subgraph/test_largest_connected_subgraph_graph_id.sql
This file contains 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,27 @@ | ||
with computed as ( | ||
{{ dbt_graph_theory.largest_connected_largest_connected_subgraph( | ||
input=ref('test_largest_connected_subgraph_graph_id_data'), | ||
graph_id='graph_id' | ||
) }} | ||
), | ||
|
||
subgraph_members as ( | ||
select v.* from ( | ||
values | ||
(1, 'A', '1__1', array['A', 'B', 'C', 'D']), | ||
(1, 'B', '1__1', array['A', 'B', 'C', 'D']), | ||
(1, 'C', '1__1', array['A', 'B', 'C', 'D']), | ||
(1, 'D', '1__1', array['A', 'B', 'C', 'D']), | ||
(1, 'E', '1__2', array['E']), | ||
(2, 'A', '2__1', array['A', 'B', 'C', 'D']), | ||
(2, 'B', '2__1', array['A', 'B', 'C', 'D']), | ||
(2, 'C', '2__1', array['A', 'B', 'C', 'D']), | ||
(2, 'D', '2__1', array['A', 'B', 'C', 'D']) | ||
) as v (graph_id, vertex, subgraph_id, subgraph_members) | ||
) | ||
|
||
select * from {{ cte_difference( | ||
'computed', | ||
'subgraph_members', | ||
fields=["graph_id", "vertex", "subgraph_id", "subgraph_members"] | ||
) }} |
36 changes: 36 additions & 0 deletions
36
...s/test_largest_connected_subgraph/test_largest_connected_subgraph_graph_id_3_subgraph.sql
This file contains 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,36 @@ | ||
with computed as ( | ||
{{ dbt_graph_theory.largest_connected_largest_connected_subgraph( | ||
input=ref('test_largest_connected_subgraph_graph_id_3_subgraph_data'), | ||
graph_id='graph_id' | ||
) }} | ||
), | ||
|
||
subgraph_members as ( | ||
select v.* from ( | ||
values | ||
(1, 'A', '1__1', array['A', 'B', 'C', 'D']), | ||
(1, 'B', '1__1', array['A', 'B', 'C', 'D']), | ||
(1, 'C', '1__1', array['A', 'B', 'C', 'D']), | ||
(1, 'D', '1__1', array['A', 'B', 'C', 'D']), | ||
(1, 'E', '1__2', array['E', 'F', 'G', 'H']), | ||
(1, 'F', '1__2', array['E', 'F', 'G', 'H']), | ||
(1, 'G', '1__2', array['E', 'F', 'G', 'H']), | ||
(1, 'H', '1__2', array['E', 'F', 'G', 'H']), | ||
(1, 'I', '1__3', array['I', 'J']), | ||
(1, 'J', '1__3', array['I', 'J']), | ||
(2, 'A', '2__1', array['A', 'B', 'C']), | ||
(2, 'B', '2__1', array['A', 'B', 'C']), | ||
(2, 'C', '2__1', array['A', 'B', 'C']), | ||
(2, 'D', '2__2', array['D']), | ||
(2, 'E', '2__3', array['E', 'F', 'G', 'H']), | ||
(2, 'F', '2__3', array['E', 'F', 'G', 'H']), | ||
(2, 'G', '2__3', array['E', 'F', 'G', 'H']), | ||
(2, 'H', '2__3', array['E', 'F', 'G', 'H']) | ||
) as v (graph_id, vertex, subgraph_id, subgraph_members) | ||
) | ||
|
||
select * from {{ cte_difference( | ||
'computed', | ||
'subgraph_members', | ||
fields=["graph_id", "vertex", "subgraph_id", "subgraph_members"] | ||
) }} |
19 changes: 19 additions & 0 deletions
19
..._tests/models/test_largest_connected_subgraph/test_largest_connected_subgraph_no_data.sql
This file contains 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,19 @@ | ||
with computed as ( | ||
{{ dbt_graph_theory.largest_connected_largest_connected_subgraph( | ||
input=ref('test_largest_connected_subgraph_no_data_data') | ||
) }} | ||
), | ||
|
||
subgraph_members as ( | ||
select v.* from ( | ||
values | ||
(null::text, null::text, array[null]) | ||
) as v (vertex, subgraph_id, subgraph_members) | ||
where false | ||
) | ||
|
||
select * from {{ cte_difference( | ||
'computed', | ||
'subgraph_members', | ||
fields=["vertex", "subgraph_id", "subgraph_members"] | ||
) }} |
20 changes: 20 additions & 0 deletions
20
...dels/test_largest_connected_subgraph/test_largest_connected_subgraph_no_data_graph_id.sql
This file contains 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,20 @@ | ||
with computed as ( | ||
{{ dbt_graph_theory.largest_connected_largest_connected_subgraph( | ||
input=ref('test_largest_connected_subgraph_no_data_graph_id_data'), | ||
graph_id='graph_id' | ||
) }} | ||
), | ||
|
||
subgraph_members as ( | ||
select v.* from ( | ||
values | ||
(null::integer, null::text, null::text, array[null]) | ||
) as v (graph_id, vertex, subgraph_id, subgraph_members) | ||
where false | ||
) | ||
|
||
select * from {{ cte_difference( | ||
'computed', | ||
'subgraph_members', | ||
fields=["graph_id", "vertex", "subgraph_id", "subgraph_members"] | ||
) }} |
26 changes: 0 additions & 26 deletions
26
...dels/test_largest_connected_subgraph_identifier/test_largest_conn_subgraph_1_subgraph.sql
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
...t_largest_connected_subgraph_identifier/test_largest_conn_subgraph_2_subgraph_no_edge.sql
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.