|
| 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