diff --git a/models/core/core__fact_events.sql b/models/core/core__fact_events.sql new file mode 100644 index 0000000..aff5d98 --- /dev/null +++ b/models/core/core__fact_events.sql @@ -0,0 +1,15 @@ +{{ config( + materialized = 'view' +) }} + +WITH events AS ( + + SELECT + * + FROM + {{ ref('gold__events') }} +) +SELECT + * +FROM + events diff --git a/models/core/core__fact_events.yml b/models/core/core__fact_events.yml new file mode 100644 index 0000000..bed8def --- /dev/null +++ b/models/core/core__fact_events.yml @@ -0,0 +1,80 @@ + +version: 2 + +models: + - name: core__fact_events + description: |- + This table records events from each transaction on the FLOW blockchain. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_id + - event_index + + columns: + - name: tx_id + description: "{{ doc('tx_id') }}" + tests: + - not_null + + - name: block_timestamp + description: "{{ doc('block_timestamp') }}" + tests: + - not_null + - dbt_expectations.expect_row_values_to_have_recent_data: + datepart: day + interval: 1 + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - TIMESTAMP_NTZ + + - name: block_height + description: "{{ doc('block_height') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + + - name: tx_succeeded + description: "{{ doc('tx_succeeded') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - BOOLEAN + + - name: event_index + description: "{{ doc('event_index') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + + - name: event_contract + description: "{{ doc('event_contract') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + + - name: event_type + description: "{{ doc('event_type') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + + - name: event_data + description: "{{ doc('event_attributes') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - OBJECT diff --git a/models/descriptions/event_attributes.md b/models/descriptions/event_attributes.md new file mode 100644 index 0000000..0604635 --- /dev/null +++ b/models/descriptions/event_attributes.md @@ -0,0 +1,5 @@ +{% docs event_attributes %} + +The data passed to the event, in the form of key-value pairs. + +{% enddocs %} \ No newline at end of file diff --git a/models/gold/gold__events.sql b/models/gold/gold__events.sql new file mode 100644 index 0000000..8c45c70 --- /dev/null +++ b/models/gold/gold__events.sql @@ -0,0 +1,105 @@ +{{ config( + materialized = 'incremental', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp::date'], + unique_key = "CONCAT_WS('-', tx_id, event_id)" +) }} + +WITH silver_events AS ( + + SELECT + * + FROM + {{ ref('silver__events') }} + +{% if is_incremental() %} +WHERE + _ingested_at :: DATE >= CURRENT_DATE -2 +{% endif %} +), +silver_event_attributes AS ( + SELECT + * + FROM + {{ ref('silver__event_attributes') }} + +{% if is_incremental() %} +WHERE + _ingested_at :: DATE >= CURRENT_DATE -2 +{% endif %} +), +objs AS ( + SELECT + event_id, + OBJECT_AGG( + attribute_key, + attribute_value_adj :: variant + ) AS event_data + FROM + silver_event_attributes + GROUP BY + 1 +), +location_object AS ( + SELECT + event_id, + tx_id, + block_timestamp, + block_height, + tx_succeeded, + event_index, + event_contract, + event_type, + COALESCE( + _event_data_type :location, + _event_data_type :Location + ) AS event_data + FROM + silver_events + WHERE + _event_data_fields = '[]' +), +gold_events AS ( + SELECT + e.event_id, + e.tx_id, + e.block_timestamp, + e.block_height, + e.tx_succeeded, + e.event_index, + e.event_contract, + e.event_type, + A.event_data + FROM + objs A + LEFT JOIN silver_events e USING (event_id) +), +FINAL AS ( + SELECT + tx_id, + block_timestamp, + block_height, + tx_succeeded, + event_index, + event_contract, + event_type, + event_data + FROM + gold_events + UNION + SELECT + tx_id, + block_timestamp, + block_height, + tx_succeeded, + event_index, + event_contract, + event_type, + event_data + FROM + location_object +) +SELECT + * +FROM + FINAL diff --git a/models/gold/gold__events.yml b/models/gold/gold__events.yml new file mode 100644 index 0000000..22a032a --- /dev/null +++ b/models/gold/gold__events.yml @@ -0,0 +1,80 @@ + +version: 2 + +models: + - name: gold__events + description: |- + This table records events from each transaction on the FLOW blockchain. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_id + - event_index + + columns: + - name: tx_id + description: "{{ doc('tx_id') }}" + tests: + - not_null + + - name: block_timestamp + description: "{{ doc('block_timestamp') }}" + tests: + - not_null + - dbt_expectations.expect_row_values_to_have_recent_data: + datepart: day + interval: 1 + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - TIMESTAMP_NTZ + + - name: block_height + description: "{{ doc('block_height') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + - FLOAT + + - name: tx_succeeded + description: "{{ doc('tx_succeeded') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - BOOLEAN + + - name: event_index + description: "{{ doc('event_index') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - NUMBER + + - name: event_contract + description: "{{ doc('event_contract') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + + - name: event_type + description: "{{ doc('event_type') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - STRING + - VARCHAR + + - name: event_data + description: "{{ doc('event_attributes') }}" + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_in_type_list: + column_type_list: + - OBJECT