idk what that first commit was

This commit is contained in:
Eric Laurello 2024-02-22 08:56:45 -05:00
parent 245b1c3552
commit 976148ea23
5 changed files with 111 additions and 42 deletions

View File

@ -5,13 +5,10 @@
}} }
) }}
WITH base AS (
WITH txs AS (
SELECT
block_timestamp_hour,
block_number_min,
block_number_max,
block_count,
transaction_count,
transaction_count_success,
transaction_count_failed,
@ -35,21 +32,29 @@ WITH base AS (
AND p.id = 'terra-luna-2'
)
SELECT
block_timestamp_hour,
block_number_min,
block_number_max,
block_count,
transaction_count,
transaction_count_success,
transaction_count_failed,
unique_from_count,
total_fees_native,
A.block_timestamp_hour,
A.block_number_min,
A.block_number_max,
A.block_count,
b.transaction_count,
b.transaction_count_success,
b.transaction_count_failed,
b.unique_from_count,
b.total_fees_native,
ROUND(
total_fees_native * imputed_close,
b.total_fees_native * b.imputed_close,
2
) AS total_fees_usd,
ez_core_metrics_hourly_id,
inserted_timestamp,
modified_timestamp
A.core_metrics_block_hourly_id AS ez_core_metrics_hourly_id,
GREATEST(
A.inserted_timestamp,
b.inserted_timestamp
) AS inserted_timestamp,
GREATEST(
A.modified_timestamp,
b.modified_timestamp
) AS modified_timestamp
FROM
base
{{ ref('silver_stats__core_metrics_block_hourly') }} A
JOIN txs b
ON A.block_timestamp_hour = b.block_timestamp_hour

View File

@ -0,0 +1,43 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_timestamp_hour",
cluster_by = ['block_timestamp_hour::DATE'],
tags = ['noncore']
) }}
SELECT
DATE_TRUNC(
'hour',
block_timestamp
) AS block_timestamp_hour,
MIN(block_id) AS block_number_min,
MAX(block_id) AS block_number_max,
COUNT(
1
) AS block_count,
MAX(_inserted_timestamp) AS _inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(
['block_timestamp_hour']
) }} AS core_metrics_block_hourly_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
{{ ref('silver__blocks') }}
WHERE
block_timestamp_hour < DATE_TRUNC('hour', systimestamp())
{% if is_incremental() %}
AND DATE_TRUNC(
'hour',
_inserted_timestamp
) >= (
SELECT
MAX(DATE_TRUNC('hour', _inserted_timestamp)) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}
GROUP BY
1

View File

@ -0,0 +1,41 @@
version: 2
models:
- name: silver_stats__core_metrics_block_hourly
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- BLOCK_TIMESTAMP_HOUR
columns:
- name: BLOCK_TIMESTAMP_HOUR
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- TIMESTAMP_LTZ
- TIMESTAMP_NTZ
- name: BLOCK_NUMBER_MIN
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: BLOCK_NUMBER_MAX
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: BLOCK_COUNT
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: _INSERTED_TIMESTAMP
tests:
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 1

View File

@ -14,12 +14,12 @@ WITH msgs AS (
attribute_key,
attribute_value
FROM
{{ ref('silver__msg_attributes') }}
{{ ref('silver__msg_attributes_2') }}
WHERE
attribute_key IN ('acc_seq', 'fee')
{% if is_incremental() %}
DATE_TRUNC(
AND DATE_TRUNC(
'hour',
_inserted_timestamp
) >= (
@ -74,11 +74,12 @@ SELECT
'hour',
block_timestamp
) AS block_timestamp_hour,
MIN(block_id) AS block_number_min,
{# MIN(block_id) AS block_number_min,
MAX(block_id) AS block_number_max,
COUNT(
DISTINCT block_id
) AS block_count,
#}
COUNT(
DISTINCT A.tx_id
) AS transaction_count,

View File

@ -13,27 +13,6 @@ models:
column_type_list:
- TIMESTAMP_LTZ
- TIMESTAMP_NTZ
- name: BLOCK_NUMBER_MIN
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: BLOCK_NUMBER_MAX
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: BLOCK_COUNT
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: TRANSACTION_COUNT
tests:
- not_null