Skip to content

Commit 6f671f9

Browse files
committed
add multi-project support
1 parent 3925dd6 commit 6f671f9

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

dbt_project.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,24 @@ seeds:
3333
vars:
3434
overbase_firebase:
3535
"OVERBASE:DONT_CARE": "MAKE_YAML_WORK" # optional
36+
# "OVERBASE:SOURCES":
37+
# - {project_id: watermark-maker,
38+
# analytics_dataset_id: analytics_150733022,
39+
# events_table: events_*,
40+
# crashlytics_dataset_id: firebase_crashlytics,
41+
# crashlytics_table: com_kobe_watermarkmaker_*}
42+
# # add more projects here
43+
# - {project_id: logo-maker-35628,
44+
# analytics_dataset_id: analytics_153578578,
45+
# events_table: events_*,
46+
# crashlytics_dataset_id: firebase_crashlytics,
47+
# crashlytics_table: com_dave_logomaker_*}
48+
3649
# don't define variables here, because if they aren't overwritten in the client yml, then they will resolve to "None".
3750
# Instead, use them in the package where you need them with them with the appropriate default value
3851
# Furthermore, whatever we use in sources.yml, we can't define in this package's dbt_project.yml, or else they won't be able to be overwritten by the client
3952
# Any mandatory variables you want to be enforced should go into overbase_mandatory_vars.sql
4053
# The comments liste here is just for our sanity & easier c/p in client configs
41-
# "OVERBASE:FIREBASE_PROJECT_ID": "overbase" # mandatory, but used in sources.yml
42-
# "OVERBASE:FIREBASE_ANALYTICS_DATASET_ID": "firebase_analytics_raw_test" # mandatory, but used in sources.yml
43-
# "OVERBASE:FIREBASE_ANALYTICS_EVENTS_TABLE_NAME": "events_*" # optional, but used in sources.yml
44-
# "OVERBASE:FIREBASE_ANALYTICS_EVENTS_INTRADAY_TABLE_NAME": "events_intraday_*" # optional, but used in sources.yml
4554
# "OVERBASE:FIREBASE_ANALYTICS_CUSTOM_INSTALL_EVENT": "" # optional e.g. attributed_first_open
4655
# "OVERBASE:CUSTOM_PLATFORM_PREPROCESSOR": "IF(app_info.version LIKE '%nexus', 'nexus', platform)"
4756
# "OVERBASE:FIREBASE_ANALYTICS_DEFAULT_INCREMENTAL_DAYS": # optional

models/analytics/fb_analytics_events_raw.sql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ SELECT TIMESTAMP_MICROS(event_timestamp) as event_ts
5757
) AS users_ltv
5858
, STRUCT<firebase_app_id STRING, stream_id STRING, advertising_id STRING>(
5959
LOWER(app_info.firebase_app_id), LOWER(stream_id), LOWER({{ null_if_length_zero('device.advertising_id') }})
60-
) as other_ids
6160
, {{ overbase_firebase.generate_date_timezone_struct('TIMESTAMP_MICROS(event_timestamp)') }} as event_dates
6261
, {{ overbase_firebase.generate_date_timezone_struct('TIMESTAMP_MICROS(user_first_touch_timestamp)') }} as install_dates
6362
, COUNT(1) OVER (PARTITION BY user_pseudo_id, event_bundle_sequence_id, event_name, event_timestamp, event_previous_timestamp) as duplicates_cnt
@@ -71,6 +70,4 @@ LEFT JOIN {{ref('ob_iso_country')}} as language_region_codes -- some language ha
7170

7271
WHERE True
7372
AND {{ overbase_firebase.analyticsTableSuffixFilter() }} -- already extended by 1 day compared to event_timestamp filter
74-
AND {{ overbase_firebase.analyticsDateFilterFor('DATE(TIMESTAMP_MICROS(event_timestamp))') }}
7573

76-
QUALIFY ROW_NUMBER() OVER (PARTITION BY user_pseudo_id, event_bundle_sequence_id, event_name, event_timestamp, event_previous_timestamp) = 1

models/crashlytics/fb_crashlytics_events_raw.sql

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
) }}
1313

1414
-- https://firebase.google.com/docs/crashlytics/bigquery-export#without_stack_traces
15-
SELECT event_timestamp as event_ts
15+
16+
{% set projects = var('OVERBASE:SOURCES', []) %}
17+
18+
{% for p in projects %}
19+
{% if not loop.first %}UNION ALL{% endif %}
20+
SELECT
21+
'{{ p.project_id }}' as project_id,
1622
, DATE(event_timestamp) as event_date
1723
, received_timestamp as received_ts
1824
, installation_uuid as crashlytics_user_pseudo_id
@@ -77,8 +83,8 @@ SELECT event_timestamp as event_ts
7783
], "unity_metadata." )| join(", ") }}
7884
) AS unity_metadata
7985
, COUNT(1) OVER (PARTITION BY installation_uuid, event_id, variant_id) as duplicates_cnt
80-
FROM {{ source("firebase_crashlytics", "events") }} as events
81-
WHERE True
82-
AND {{ overbase_firebase.crashlyticsTSFilterFor("event_timestamp") }}
83-
QUALIFY ROW_NUMBER() OVER (PARTITION BY installation_uuid, event_id, variant_id ORDER BY received_ts) = 1
8486
87+
FROM {{ source('firebase_crashlytics__' ~ p.project_id, 'events') }}
88+
WHERE {{ overbase_firebase.crashlyticsTSFilterFor("event_timestamp") }}
89+
QUALIFY ROW_NUMBER() OVER (PARTITION BY installation_uuid, event_id, variant_id ORDER BY received_ts) = 1
90+
{% endfor %}

0 commit comments

Comments
 (0)