Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Commit b181444

Browse files
author
Thomas Markovich
committed
Added SQL queries to generate edgelists
Fixes to SQL Commands
1 parent 46c45e6 commit b181444

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
type_tmp_table = """
2+
DROP TABLE IF EXISTS {type}_id2part
3+
;
4+
5+
create temporary table {type}_id2part as
6+
select id, abs(random()) % {nparts} as part
7+
from (
8+
select distinct source_id as id from edges where source_type='{type}'
9+
union
10+
select distinct destination_id as id from edges where destination_type='{type}'
11+
)
12+
13+
;
14+
"""
15+
16+
partitioned_mapped_entities = """
17+
DROP TABLE IF EXISTS {type}_ids_map_{n}
18+
;
19+
20+
create table {type}_ids_map_{n} as
21+
select
22+
f.id
23+
, f.part
24+
, '{type}' as type
25+
, (ROW_NUMBER() OVER(ORDER BY f.id)) - 1 as graph_id
26+
from {type}_id2part f
27+
where f.part = {n}
28+
order by 2 desc, 1 asc
29+
;
30+
"""
31+
32+
remap_relns = """
33+
DROP TABLE IF EXISTS reln_map
34+
;
35+
36+
create table reln_map as
37+
select f.rel as id, source_type, destination_type, (ROW_NUMBER() OVER(ORDER BY f.rel)) - 1 as graph_id
38+
from (
39+
select distinct rel, source_type, destination_type
40+
from edges
41+
) f
42+
"""
43+
44+
edgelist_cte_mapper = """
45+
select lhs.graph_id as source_id, rel.graph_id as rel_id, rhs.graph_id as destination_id
46+
from edges g
47+
join reln_map rel on (rel.id = g.rel)
48+
join {lhs_type}_ids_map_{i} lhs on (
49+
lhs.id = g.source_id and
50+
g.source_type = rel.source_type and
51+
lhs.type = g.source_type
52+
)
53+
join {rhs_type}_ids_map_{j} rhs on (
54+
rhs.id = g.destination_id and
55+
g.destination_type = rel.destination_type and
56+
rhs.type = g.destination_type
57+
)
58+
where g.rel = '{rel_name}'
59+
"""
60+
61+
edges_partitioned = """
62+
DROP TABLE IF EXISTS edges_{i}_{j}
63+
;
64+
65+
create table edges_{i}_{j} as
66+
{ctes}
67+
select *
68+
from (
69+
{tables}
70+
)
71+
;
72+
"""

0 commit comments

Comments
 (0)