Skip to content

Commit 14bd1a6

Browse files
authored
chore: create new organizations datasource with inferred slug (IN-1174) (#4132)
Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org>
1 parent 32284c2 commit 14bd1a6

2 files changed

Lines changed: 161 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
DESCRIPTION >
2+
Denormalized organizations datasource: every column from organizations FINAL plus a
3+
deterministic globally unique slug derived from displayName and a total contributionCount
4+
across all segments.
5+
Only includes organizations that have at least one activity recorded in
6+
cdp_organization_segment_aggregates_ds (activityCountState > 0).
7+
Slug rules:
8+
- slug = lowerUTF8(displayName) with non-alphanumeric runs collapsed to '-' and
9+
leading/trailing dashes trimmed.
10+
- If two or more organizations produce the same baseSlug, the one with the highest
11+
contributionCount keeps the bare slug; the rest get '--1', '--2', ... suffixes
12+
(double-dash) ordered by descending contributionCount, with id ASC as the
13+
deterministic tiebreaker. Double-dash prevents collisions with natural slugs that
14+
end in a digit or word (e.g. 'dark-1' vs 'dark--1').
15+
- If the derived slug would be empty (displayName contains only non-ASCII or special
16+
characters), the slug falls back to id.
17+
Refreshed hourly at :35 by organizations_populate_slug.pipe.
18+
19+
SCHEMA >
20+
`id` String,
21+
`displayName` String,
22+
`location` String DEFAULT '',
23+
`logo` String DEFAULT '',
24+
`tags` Array(String) DEFAULT [],
25+
`employees` UInt32 DEFAULT 0,
26+
`createdAt` DateTime64(3),
27+
`updatedAt` DateTime64(3),
28+
`isTeamOrganization` UInt8 DEFAULT 0,
29+
`type` String DEFAULT '',
30+
`size` String DEFAULT '',
31+
`headline` String DEFAULT '',
32+
`industry` String DEFAULT '',
33+
`founded` UInt16 DEFAULT 0,
34+
`slug` String,
35+
`contributionCount` UInt64
36+
37+
ENGINE MergeTree
38+
ENGINE_SORTING_KEY id
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
DESCRIPTION >
2+
Populates organizations_populated_slug with one row per organization that has contributions.
3+
Carries all columns from organizations FINAL and adds a deterministic globally unique
4+
slug and a total contributionCount (sourced from cdp_organization_segment_aggregates_ds).
5+
6+
NODE organizations_slugged_contribution_counts
7+
DESCRIPTION >
8+
Total activity count per organization summed across all segments, read from the
9+
pre-aggregated AggregatingMergeTree. Much faster than scanning the bucket union.
10+
11+
SQL >
12+
SELECT organizationId, countMerge(activityCountState) AS contributionCount
13+
FROM cdp_organization_segment_aggregates_ds
14+
WHERE organizationId != ''
15+
GROUP BY organizationId
16+
17+
NODE organizations_slugged_enriched
18+
DESCRIPTION >
19+
Join contribution counts with full org metadata and compute the base slug candidate.
20+
21+
SQL >
22+
SELECT
23+
org.id AS id,
24+
org.displayName AS displayName,
25+
org.location AS location,
26+
org.logo AS logo,
27+
org.tags AS tags,
28+
org.employees AS employees,
29+
org.createdAt AS createdAt,
30+
org.updatedAt AS updatedAt,
31+
org.isTeamOrganization AS isTeamOrganization,
32+
org.type AS type,
33+
org.size AS size,
34+
org.headline AS headline,
35+
org.industry AS industry,
36+
org.founded AS founded,
37+
c.contributionCount AS contributionCount,
38+
replaceRegexpAll(
39+
replaceRegexpAll(lowerUTF8(org.displayName), '[^a-z0-9]+', '-'), '(^-+)|(-+$)', ''
40+
) AS generatedSlug
41+
FROM organizations_slugged_contribution_counts c
42+
INNER JOIN organizations org FINAL ON org.id = c.organizationId
43+
44+
NODE organizations_slugged_base_slug
45+
DESCRIPTION >
46+
Apply empty-slug fallback: if generatedSlug is empty, use the org id as baseSlug.
47+
48+
SQL >
49+
SELECT
50+
id,
51+
displayName,
52+
location,
53+
logo,
54+
tags,
55+
employees,
56+
createdAt,
57+
updatedAt,
58+
isTeamOrganization,
59+
type,
60+
size,
61+
headline,
62+
industry,
63+
founded,
64+
contributionCount,
65+
if(length(generatedSlug) > 0, generatedSlug, id) AS baseSlug
66+
FROM organizations_slugged_enriched
67+
68+
NODE organizations_slugged_ranked
69+
DESCRIPTION >
70+
Assign final globally unique slugs. Orgs with a unique baseSlug keep it as-is.
71+
Orgs in a collision group (>=2 share the same baseSlug) all get a '--N' suffix
72+
ordered by descending contributionCount (id ASC tiebreaker). Double-dash is used
73+
so synthetic suffixes never collide with natural slugs that end in a number or word
74+
(e.g. 'dark-1' from 'Dark-1' vs 'dark--1' from 'Dark++' in a collision group).
75+
76+
SQL >
77+
SELECT
78+
id,
79+
displayName,
80+
location,
81+
logo,
82+
tags,
83+
employees,
84+
createdAt,
85+
updatedAt,
86+
isTeamOrganization,
87+
type,
88+
size,
89+
headline,
90+
industry,
91+
founded,
92+
if(groupSize = 1 OR slugRank = 1, baseSlug, concat(baseSlug, '--', toString(slugRank))) AS slug,
93+
contributionCount
94+
FROM
95+
(
96+
SELECT
97+
id,
98+
displayName,
99+
location,
100+
logo,
101+
tags,
102+
employees,
103+
createdAt,
104+
updatedAt,
105+
isTeamOrganization,
106+
type,
107+
size,
108+
headline,
109+
industry,
110+
founded,
111+
contributionCount,
112+
baseSlug,
113+
count() OVER (PARTITION BY baseSlug) AS groupSize,
114+
row_number() OVER (
115+
PARTITION BY baseSlug ORDER BY contributionCount DESC, id ASC
116+
) AS slugRank
117+
FROM organizations_slugged_base_slug
118+
)
119+
120+
TYPE COPY
121+
TARGET_DATASOURCE organizations_populated_slug
122+
COPY_MODE replace
123+
COPY_SCHEDULE 35 * * * *

0 commit comments

Comments
 (0)