-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add V2 artifact upload method which flattens on load, avoiding 16MB field limit
- Loading branch information
1 parent
ec1bda4
commit f435114
Showing
17 changed files
with
635 additions
and
152 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% macro drop_test_schema() %} | ||
|
||
-- We drop if exists so that it still passes when the db is clean. | ||
{% set drop_schema_query %} | ||
drop schema if exists {{ target.schema }}; | ||
{% endset %} | ||
|
||
{% do log("Dropping test schema: " ~ drop_schema_query, info=True) %} | ||
{% do run_query(drop_schema_query) %} | ||
|
||
{% endmacro %} |
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,37 @@ | ||
with raw_model_executions as ( | ||
|
||
select * from {{ ref('fct_dbt__model_executions') }} | ||
|
||
), | ||
|
||
grouped_executions as ( | ||
|
||
select | ||
artifact_run_id, | ||
count(*) as runs | ||
from raw_model_executions | ||
group by artifact_run_id | ||
|
||
), | ||
|
||
expected_results as ( | ||
|
||
select | ||
artifact_run_id, | ||
runs, | ||
-- Hard coded expected results. Potentially to improve later. | ||
case artifact_run_id | ||
when 'b27910c784063dc867a762eb91ac7e93033492ac49b482215cd1761824b07a58' then 31 -- build | ||
when '1ab40ec436539434416dfca0bb0e8d8cf3708bb568fb2385321a192b59b9c4e7' then 31 -- build_full_refresh | ||
when 'c6775fc1f3d39acb37f389df8b67aa59cb989994dc9b940b51e7bcba830212a3' then 31 -- run | ||
when '4fbd1feb6cfc3cd088fc47ac461efdfab7f95380aa5a939360da629bbdb9ce1d' then 31 -- run_full_refresh | ||
when '6ee8780f7533ae3901f8759fd07ddae4af20b7856c788bf515bdf14ee059e90d' then 0 -- seed | ||
when '1c87fbb828af7f041f0d7d4440904a8e482a8be74e617eb57a11b76001936550' then 0 -- snapshot | ||
when '37f4a0fca17b0f8f1fb0db04fbef311dd73cacfcd6653c76d46e3d7f36dc079c' then 0 -- test | ||
else 0 | ||
end as expected_runs | ||
from grouped_executions | ||
where runs != expected_runs | ||
) | ||
|
||
select * from expected_results |
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,37 @@ | ||
with raw_node_executions as ( | ||
|
||
select * from {{ ref('stg_dbt__node_executions') }} | ||
|
||
), | ||
|
||
grouped_executions as ( | ||
|
||
select | ||
artifact_run_id, | ||
count(*) as runs | ||
from raw_node_executions | ||
group by artifact_run_id | ||
|
||
), | ||
|
||
expected_results as ( | ||
|
||
select | ||
artifact_run_id, | ||
runs, | ||
-- Hard coded expected results. Potentially to improve later. | ||
case artifact_run_id | ||
when 'b27910c784063dc867a762eb91ac7e93033492ac49b482215cd1761824b07a58' then 51 -- build | ||
when '1ab40ec436539434416dfca0bb0e8d8cf3708bb568fb2385321a192b59b9c4e7' then 51 -- build_full_refresh | ||
when 'c6775fc1f3d39acb37f389df8b67aa59cb989994dc9b940b51e7bcba830212a3' then 31 -- run | ||
when '4fbd1feb6cfc3cd088fc47ac461efdfab7f95380aa5a939360da629bbdb9ce1d' then 31 -- run_full_refresh | ||
when '6ee8780f7533ae3901f8759fd07ddae4af20b7856c788bf515bdf14ee059e90d' then 1 -- seed | ||
when '1c87fbb828af7f041f0d7d4440904a8e482a8be74e617eb57a11b76001936550' then 1 -- snapshot | ||
when '37f4a0fca17b0f8f1fb0db04fbef311dd73cacfcd6653c76d46e3d7f36dc079c' then 18 -- test | ||
else 0 | ||
end as expected_runs | ||
from grouped_executions | ||
where runs != expected_runs | ||
) | ||
|
||
select * from expected_results |
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,25 @@ | ||
with raw_runs as ( | ||
|
||
select * from {{ ref('stg_dbt__run_results') }} | ||
|
||
), | ||
|
||
grouped_runs as ( | ||
|
||
select | ||
count(*) as runs | ||
from raw_runs | ||
|
||
), | ||
|
||
expected_results as ( | ||
|
||
select | ||
runs, | ||
-- Hard coded expected results. Potentially to improve later. | ||
7 as expected_runs | ||
from grouped_runs | ||
where runs != expected_runs | ||
) | ||
|
||
select * from expected_results |
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,4 @@ | ||
-- This ID provides a reliable ID, regardless of whether running in a local or cloud environment. | ||
{% macro make_artifact_run_id() %} | ||
sha2_hex(coalesce(dbt_cloud_run_id::string, command_invocation_id::string), 256) | ||
{% endmacro %} |
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 |
---|---|---|
@@ -1,29 +1,113 @@ | ||
{% macro create_artifact_resources() %} | ||
|
||
{% set src_dbt_artifacts = source('dbt_artifacts', 'artifacts') %} | ||
{% set artifact_stage = var('dbt_artifacts_stage', 'dbt_artifacts_stage') %} | ||
|
||
{% set src_results = source('dbt_artifacts', 'dbt_run_results') %} | ||
{% set src_results_nodes = source('dbt_artifacts', 'dbt_run_results_nodes') %} | ||
{% set src_manifest_nodes = source('dbt_artifacts', 'dbt_run_manifest_nodes') %} | ||
|
||
{{ create_schema(src_dbt_artifacts) }} | ||
|
||
{% set create_stage_query %} | ||
{% set create_v1_stage_query %} | ||
create stage if not exists {{ src_dbt_artifacts }} | ||
file_format = (type = json); | ||
{% endset %} | ||
|
||
{% set create_table_query %} | ||
{% set create_v2_stage_query %} | ||
create stage if not exists {{ artifact_stage }} | ||
file_format = (type = json); | ||
{% endset %} | ||
|
||
{% set create_v1_table_query %} | ||
create table if not exists {{ src_dbt_artifacts }} ( | ||
data variant, | ||
generated_at timestamp, | ||
path string, | ||
artifact_type string | ||
); | ||
{% endset %} | ||
|
||
{% set create_v2_results_query %} | ||
create table if not exists {{ src_results }} ( | ||
command_invocation_id string, | ||
dbt_cloud_run_id int, | ||
artifact_run_id string, | ||
artifact_generated_at timestamp_tz, | ||
dbt_version string, | ||
env variant, | ||
elapsed_time double, | ||
execution_command string, | ||
was_full_refresh boolean, | ||
selected_models variant, | ||
target string, | ||
metadata variant, | ||
args variant | ||
); | ||
{% endset %} | ||
|
||
{% set create_v2_result_nodes_table_query %} | ||
create table if not exists {{ src_results_nodes }} ( | ||
command_invocation_id string, | ||
dbt_cloud_run_id int, | ||
artifact_run_id string, | ||
artifact_generated_at timestamp_tz, | ||
execution_command string, | ||
was_full_refresh boolean, | ||
node_id string, | ||
thread_id integer, | ||
status string, | ||
message string, | ||
compile_started_at timestamp_tz, | ||
query_completed_at timestamp_tz, | ||
total_node_runtime float, | ||
rows_affected int, | ||
result_json variant | ||
); | ||
{% endset %} | ||
|
||
{% set create_v2_manifest_nodes_table_query %} | ||
create table if not exists {{ src_manifest_nodes }} ( | ||
command_invocation_id string, | ||
dbt_cloud_run_id int, | ||
artifact_run_id string, | ||
artifact_generated_at timestamp_tz, | ||
node_id string, | ||
resource_type string, | ||
node_database string, | ||
node_schema string, | ||
name string, | ||
depends_on_nodes array, | ||
depends_on_sources array, | ||
exposure_type string, | ||
exposure_owner string, | ||
exposure_maturity string, | ||
source_name string, | ||
package_name string, | ||
relation_name string, | ||
node_path string, | ||
checksum string, | ||
materialization string, | ||
node_json variant | ||
); | ||
{% endset %} | ||
|
||
{% do log("Creating V1 Stage: " ~ create_v1_stage_query, info=True) %} | ||
{% do run_query(create_v1_stage_query) %} | ||
|
||
{% do log("Creating V2 Stage: " ~ create_v2_stage_query, info=True) %} | ||
{% do run_query(create_v2_stage_query) %} | ||
|
||
{% do log("Creating V1 Table: " ~ create_v1_table_query, info=True) %} | ||
{% do run_query(create_v1_table_query) %} | ||
|
||
{% do log("Creating V2 Results Table: " ~ create_v2_results_query, info=True) %} | ||
{% do run_query(create_v2_results_query) %} | ||
|
||
{% do log("Creating Stage: " ~ create_stage_query, info=True) %} | ||
{% do run_query(create_stage_query) %} | ||
{% do log("Creating V2 Result Nodes Table: " ~ create_v2_result_nodes_table_query, info=True) %} | ||
{% do run_query(create_v2_result_nodes_table_query) %} | ||
|
||
{% do log("Creating Table: " ~ create_table_query, info=True) %} | ||
{% do run_query(create_table_query) %} | ||
{% do log("Creating V2 Manifest Nodes Table: " ~ create_v2_manifest_nodes_table_query, info=True) %} | ||
{% do run_query(create_v2_manifest_nodes_table_query) %} | ||
|
||
{% endmacro %} |
Oops, something went wrong.