block_id and macro

This commit is contained in:
forgash_ 2022-07-13 18:44:07 -06:00
parent 8abefa1047
commit f1b93ebe90
33 changed files with 124 additions and 32 deletions

View File

@ -10,7 +10,7 @@ near:
region: "{{ env_var('REGION') }}"
database: "{{ env_var('DATABASE_DEV') }}"
warehouse: "{{ env_var('WAREHOUSE_DEV') }}"
schema: DEV
schema: SILVER
threads: 4
client_session_keep_alive: False
query_tag: gh_actions
@ -23,7 +23,7 @@ near:
region: "{{ env_var('REGION') }}"
database: "{{ env_var('DATABASE_PROD') }}"
warehouse: "{{ env_var('WAREHOUSE_PROD') }}"
schema: PROD
schema: SILVER
threads: 4
client_session_keep_alive: False
query_tag: gh_actions

View File

@ -14,10 +14,10 @@ SF_ACCOUNT=zsniary-metricsdao
SF_USERNAME=<your_metrics_dao_snowflake_username>
SF_PASSWORD=<your_metrics_dao_snowflake_password>
SF_REGION=us-east-1
SF_DATABASE=NEAR
SF_DATABASE=NEAR_DEV
SF_WAREHOUSE=DEFAULT
SF_ROLE=PUBLIC
SF_SCHEMA=DEV
SF_SCHEMA=SILVER
```
3. New to DBT? It's pretty dope. Read up on it [here](https://www.getdbt.com/docs/)

View File

@ -9,7 +9,7 @@ WITH block_base AS (
{{ column_block }},
{{ column_tx_count }}
FROM
{{ ref('blocks') }}
{{ ref('silver__blocks') }}
),
model_name AS (
SELECT

View File

@ -12,6 +12,7 @@ WITH actions_events AS (
SELECT
action_id,
tx_hash,
block_id,
block_timestamp,
action_index,
action_name,

View File

@ -29,6 +29,15 @@ models:
- STRING
- VARCHAR
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: block_timestamp
description: "{{ doc('block_timestamp')}}"
tests:

View File

@ -12,6 +12,7 @@ WITH actions_events_addkey AS (
SELECT
action_id,
tx_hash,
block_id,
block_timestamp,
nonce,
public_key,

View File

@ -29,6 +29,15 @@ models:
- STRING
- VARCHAR
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: block_timestamp
description: "{{ doc('block_timestamp')}}"
tests:

View File

@ -12,6 +12,7 @@ WITH actions_events_function_call AS (
SELECT
action_id,
tx_hash,
block_id,
block_timestamp,
action_name,
method_name,

View File

@ -29,6 +29,15 @@ models:
- STRING
- VARCHAR
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: block_timestamp
description: "{{ doc('block_timestamp')}}"
tests:

View File

@ -10,7 +10,7 @@ WITH blocks AS (
{{ ref('silver__blocks') }}
)
SELECT
block_height,
block_id,
block_timestamp,
block_hash,
tx_count,

View File

@ -7,14 +7,14 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- block_height
- block_id
- sequence_gaps:
column_name: block_height
column_name: block_id
where: BLOCK_TIMESTAMP < CURRENT_DATE
columns:
- name: block_height
description: "{{ doc('block_height')}}"
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:

View File

@ -11,7 +11,7 @@ WITH receipts AS (
)
SELECT
block_timestamp,
block_hash,
block_id,
tx_hash,
receipt_object_id,
receipt_outcome_id,

View File

@ -17,14 +17,14 @@ models:
column_type_list:
- TIMESTAMP_NTZ
- name: block_hash
description: "{{ doc('block_hash')}}"
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- NUMBER
- FLOAT
- name: tx_hash
description: "{{ doc('tx_hash')}}"

View File

@ -11,7 +11,7 @@ WITH transactions AS (
)
SELECT
tx_hash,
block_height,
block_id,
block_hash,
block_timestamp,
nonce,

View File

@ -9,8 +9,8 @@ models:
- tx_hash
columns:
- name: block_height
description: "{{ doc('block_height')}}"
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
@ -37,7 +37,7 @@ models:
- STRING
- VARCHAR
- tx_gaps:
column_block: block_height
column_block: block_id
column_tx_count: tx_count
where: BLOCK_TIMESTAMP < CURRENT_DATE

View File

@ -12,6 +12,7 @@ WITH transfers AS (
SELECT
tx_hash,
action_id,
block_id,
block_timestamp,
tx_signer,
tx_receiver,

View File

@ -29,6 +29,15 @@ models:
- STRING
- VARCHAR
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: block_timestamp
description: "{{ doc('block_timestamp')}}"
tests:

View File

@ -10,7 +10,7 @@ WITH blocks AS (
{{ ref('silver__blocks') }}
)
SELECT
block_height,
block_id AS block_height,
block_timestamp,
block_hash,
tx_count,

View File

@ -11,7 +11,7 @@ WITH transactions AS (
)
SELECT
tx_hash AS txn_hash,
block_height,
block_id AS block_height,
block_hash,
block_timestamp,
nonce,

View File

@ -17,6 +17,7 @@ WITH txs AS (
actions AS (
SELECT
tx_hash,
block_id,
block_timestamp,
INDEX AS action_index,
CASE
@ -43,6 +44,7 @@ FINAL AS (
action_index
) AS action_id,
tx_hash,
block_id,
block_timestamp,
action_index,
action_name,

View File

@ -29,6 +29,15 @@ models:
- STRING
- VARCHAR
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: block_timestamp
description: "{{ doc('block_timestamp')}}"
tests:

View File

@ -19,6 +19,7 @@ addkey_events AS (
SELECT
action_id,
tx_hash,
block_id,
block_timestamp,
action_data :access_key :nonce :: NUMBER AS nonce,
action_data :public_key :: STRING AS public_key,

View File

@ -29,6 +29,15 @@ models:
- STRING
- VARCHAR
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: block_timestamp
description: "{{ doc('block_timestamp')}}"
tests:

View File

@ -29,6 +29,7 @@ decoding AS (
SELECT
action_id,
tx_hash,
block_id,
block_timestamp,
action_name,
method_name,

View File

@ -29,6 +29,15 @@ models:
- STRING
- VARCHAR
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: block_timestamp
description: "{{ doc('block_timestamp')}}"
tests:

View File

@ -1,6 +1,6 @@
{{ config(
materialized = 'incremental',
unique_key = 'block_height',
unique_key = 'block_id',
incremental_strategy = 'delete+insert',
cluster_by = ['_inserted_timestamp::DATE']
) }}
@ -21,7 +21,7 @@ WITH base_blocks AS (
),
FINAL AS (
SELECT
header :height :: INTEGER AS block_height,
block_id,
div0(
header :timestamp :: INTEGER,
1000000000

View File

@ -7,14 +7,14 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- block_height
- block_id
- sequence_gaps:
column_name: block_height
column_name: block_id
where: BLOCK_TIMESTAMP < CURRENT_DATE
columns:
- name: block_height
description: "{{ doc('block_height')}}"
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:

View File

@ -18,6 +18,7 @@ receipts AS (
SELECT
block_timestamp,
block_hash,
block_id,
tx_hash,
VALUE :id :: STRING AS receipt_object_id,
VALUE :outcome :receipt_ids AS receipt_outcome_id,

View File

@ -35,6 +35,15 @@ models:
- STRING
- VARCHAR
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: receipt_object_id
description: "{{ doc('receipt_object_id')}}"
tests:

View File

@ -21,7 +21,7 @@ WITH base_transactions AS (
),
transactions AS (
SELECT
block_id AS block_height,
block_id AS block_id,
tx :outcome :block_hash :: STRING AS block_hash,
tx_hash,
block_timestamp,
@ -60,7 +60,7 @@ receipts AS (
),
FINAL AS (
SELECT
t.block_height,
t.block_id,
t.block_hash,
t.tx_hash,
t.block_timestamp,

View File

@ -9,8 +9,8 @@ models:
- tx_hash
columns:
- name: block_height
description: "{{ doc('block_height')}}"
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
@ -37,7 +37,7 @@ models:
- STRING
- VARCHAR
- tx_gaps:
column_block: block_height
column_block: block_id
column_tx_count: tx_count
where: BLOCK_TIMESTAMP < CURRENT_DATE

View File

@ -20,6 +20,7 @@ WITH action_events AS(
actions AS (
SELECT
t.tx_hash,
t.block_id,
A.action_id,
t.block_timestamp,
t.tx_receiver,
@ -44,6 +45,7 @@ actions AS (
FINAL AS (
SELECT
tx_hash,
block_id,
action_id,
block_timestamp,
tx_signer,

View File

@ -29,6 +29,15 @@ models:
- STRING
- VARCHAR
- name: block_id
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: block_timestamp
description: "{{ doc('block_timestamp')}}"
tests: