An 1212/gold events (#11)

* gold blocks

* fixes

* revert blocks

* events

* address AN-1269

* format and core

* core yml

* revise event_id and event_data in yml
This commit is contained in:
Jack Forgash 2022-05-17 15:03:40 -06:00 committed by GitHub
parent 37095a607f
commit 79e8096768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 285 additions and 0 deletions

View File

@ -0,0 +1,15 @@
{{ config(
materialized = 'view'
) }}
WITH events AS (
SELECT
*
FROM
{{ ref('gold__events') }}
)
SELECT
*
FROM
events

View File

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

View File

@ -0,0 +1,5 @@
{% docs event_attributes %}
The data passed to the event, in the form of key-value pairs.
{% enddocs %}

View File

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

View File

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