-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into test-microbatch-model
- Loading branch information
Showing
16 changed files
with
316 additions
and
10 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
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
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
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
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,34 @@ | ||
{% set COLUMNS = 'columns' %} | ||
{{ | ||
config( | ||
materialized = 'incremental', | ||
unique_key='uuid', | ||
on_schema_change='append_new_columns', | ||
indexes=[ | ||
{COLUMNS: ['uuid'], 'type': 'hash'}, | ||
{COLUMNS: ['saved_timestamp']}, | ||
{COLUMNS: ['period_start']}, | ||
{COLUMNS: ['user_name']}, | ||
] | ||
) | ||
}} | ||
|
||
SELECT | ||
document_metadata.uuid as uuid, | ||
document_metadata.saved_timestamp, | ||
doc#>>'{meta,source}' AS source, | ||
doc#>>'{meta,url}' AS url, | ||
doc#>>'{meta,user,name}' AS user_name, | ||
doc#>>'{meta,time}' AS period_start, | ||
COALESCE(doc#>>'{info,cause}',doc->>'info') AS cause, | ||
doc#>>'{info,message}' AS message | ||
FROM {{ ref('document_metadata') }} document_metadata | ||
INNER JOIN | ||
{{ source('couchdb', env_var('POSTGRES_TABLE')) }} source_table | ||
ON source_table._id = document_metadata.uuid | ||
WHERE | ||
document_metadata.doc_type = 'feedback' | ||
AND document_metadata._deleted = false | ||
{% if is_incremental() %} | ||
AND document_metadata.saved_timestamp >= {{ max_existing_timestamp('saved_timestamp') }} | ||
{% endif %} |
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,55 @@ | ||
{% set COLUMNS = 'columns' %} | ||
{{ | ||
config( | ||
materialized = 'incremental', | ||
unique_key='uuid', | ||
on_schema_change='append_new_columns', | ||
indexes=[ | ||
{COLUMNS: ['uuid'], 'type': 'hash'}, | ||
{COLUMNS: ['saved_timestamp']}, | ||
{COLUMNS: ['period_start']}, | ||
{COLUMNS: ['user_name']}, | ||
{COLUMNS: ['app_version']}, | ||
] | ||
) | ||
}} | ||
|
||
SELECT | ||
document_metadata.uuid as uuid, | ||
document_metadata.saved_timestamp, | ||
CONCAT_WS( --> Date concatenation from JSON fields, eg. 2021-5-17 | ||
'-', | ||
doc#>>'{metadata,year}', --> year | ||
CASE --> month of the year | ||
WHEN | ||
string_to_array(substring(doc#>>'{metadata,versions,app}' FROM '(\d+.\d+.\d+)'),'.')::int[] < '{3,8,0}'::int[] | ||
THEN | ||
(doc#>>'{metadata,month}')::int+1 --> Legacy, months zero-indexed (0 - 11) | ||
ELSE | ||
(doc#>>'{metadata,month}')::int --> Month is between 1 - 12 | ||
END, | ||
CASE --> day of the month, else 1 | ||
WHEN | ||
(doc#>>'{metadata,day}') IS NOT NULL | ||
THEN | ||
doc#>>'{metadata,day}' | ||
ELSE | ||
'1' | ||
END | ||
)::timestamptz AS period_start, | ||
doc#>>'{metadata,user}' AS user_name, | ||
doc#>>'{metadata,versions,app}' AS app_version, | ||
doc#>>'{metrics,boot_time,min}' AS boot_time_min, | ||
doc#>>'{metrics,boot_time,max}' AS boot_time_max, | ||
doc#>>'{metrics,boot_time,count}' AS boot_time_count, | ||
doc#>>'{dbInfo,doc_count}' AS doc_count_on_local_db | ||
FROM {{ ref('document_metadata') }} document_metadata | ||
INNER JOIN | ||
{{ source('couchdb', env_var('POSTGRES_TABLE')) }} source_table | ||
ON source_table._id = document_metadata.uuid | ||
WHERE | ||
document_metadata.doc_type = 'telemetry' | ||
AND document_metadata._deleted = false | ||
{% if is_incremental() %} | ||
AND document_metadata.saved_timestamp >= {{ max_existing_timestamp('saved_timestamp') }} | ||
{% endif %} |
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,35 @@ | ||
{% set COLUMNS = 'columns' %} | ||
{{ | ||
config( | ||
materialized = 'incremental', | ||
unique_key='uuid', | ||
on_schema_change='append_new_columns', | ||
indexes=[ | ||
{COLUMNS: ['uuid'], 'type': 'hash'}, | ||
{COLUMNS: ['saved_timestamp']}, | ||
{COLUMNS: ['period_start']}, | ||
{COLUMNS: ['android_version']}, | ||
] | ||
) | ||
}} | ||
|
||
SELECT | ||
telemetry.uuid, | ||
telemetry.saved_timestamp, | ||
telemetry.period_start, | ||
doc #>> '{device,deviceInfo,hardware,manufacturer}' AS device_manufacturer, | ||
doc #>> '{device,deviceInfo,hardware,model}' AS device_model, | ||
doc #>> '{device,userAgent}' AS user_agent, | ||
doc #>> '{device,deviceInfo,app,version}' AS cht_android_version, | ||
doc #>> '{device,deviceInfo,software,androidVersion}' AS android_version, | ||
doc #>> '{device,deviceInfo,storage,free}' AS storage_free, | ||
doc #>> '{device,deviceInfo,storage,total}' AS storage_total, | ||
doc #>> '{device,deviceInfo,network,upSpeed}' AS network_up_speed, | ||
doc #>> '{device,deviceInfo,network,downSpeed}' AS network_down_speed | ||
FROM {{ ref('telemetry') }} telemetry | ||
INNER JOIN | ||
{{ source('couchdb', env_var('POSTGRES_TABLE')) }} source_table | ||
ON source_table._id = telemetry.uuid | ||
{% if is_incremental() %} | ||
WHERE telemetry.saved_timestamp >= {{ max_existing_timestamp('saved_timestamp') }} | ||
{% endif %} |
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 @@ | ||
unit_tests: | ||
- name: test_feedback_model_transformation_and_data_integrity | ||
description: | | ||
This unit test validates the transformation logic in the `feedback` model and ensures data integrity. | ||
It uses fixture data for both `document_metadata` and `source_table` to test the complete logic. | ||
model: feedback | ||
overrides: | ||
macros: | ||
is_incremental: false | ||
given: | ||
- input: ref('document_metadata') | ||
format: csv | ||
fixture: user_document_metadata_initial | ||
- input: source('couchdb', "{{ env_var('POSTGRES_TABLE') }}") | ||
format: csv | ||
fixture: user_source_table_initial | ||
expect: | ||
format: csv | ||
fixture: feedback_initial_expected |
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 @@ | ||
unit_tests: | ||
- name: test_telemetry_model_transformation_and_data_integrity | ||
description: | | ||
This unit test validates the transformation logic in the `telemetry` model and ensures data integrity. | ||
It uses fixture data for both `document_metadata` and `source_table` to test the complete logic. | ||
model: telemetry | ||
overrides: | ||
macros: | ||
is_incremental: false | ||
given: | ||
- input: ref('document_metadata') | ||
format: csv | ||
fixture: user_document_metadata_initial | ||
- input: source('couchdb', "{{ env_var('POSTGRES_TABLE') }}") | ||
format: csv | ||
fixture: user_source_table_initial | ||
expect: | ||
format: csv | ||
fixture: telemetry_initial_expected |
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 @@ | ||
unit_tests: | ||
- name: test_telemetry_devices_model_transformation_and_data_integrity | ||
description: | | ||
This unit test validates the transformation logic in the `telemetry_devices` model and ensures data integrity. | ||
It uses fixture data for both `telemtry` and `source_table` to test the complete logic. | ||
model: telemetry_devices | ||
overrides: | ||
macros: | ||
is_incremental: false | ||
given: | ||
- input: ref('telemetry') | ||
format: csv | ||
fixture: telemetry_initial_expected | ||
- input: source('couchdb', "{{ env_var('POSTGRES_TABLE') }}") | ||
format: csv | ||
fixture: user_source_table_initial | ||
expect: | ||
format: csv | ||
fixture: telemetry_devices_initial_expected |
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
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,2 @@ | ||
uuid,saved_timestamp,source,url,user_name,period_start,cause,message | ||
6,2024-08-02 00:00:00,automatic,http://example.com,admin,2024-08-02 00:00:00,bug,this is a bug |
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,2 @@ | ||
uuid,saved_timestamp,period_start,device_manufacturer,device_model,user_agent,cht_android_version,android_version,storage_free,storage_total,network_up_speed,network_down_speed | ||
8,2024-08-02 00:00:00,2024-09-11,Google,Pixel 3,Chrome Mobile,4.15.0,10,100,200,100,200 |
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,2 @@ | ||
uuid,saved_timestamp,period_start,user_name,app_version,boot_time_min,boot_time_max,boot_time_count,doc_count_on_local_db | ||
8,2024-08-02 00:00:00,2024-09-11,admin,4.15.0,0.5,1.5,2,20 |
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
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