add/shares-ref-usage (#49)

* added models for shares references

* adds lookback
This commit is contained in:
drethereum 2023-05-04 12:29:34 -06:00 committed by GitHub
parent f58146564e
commit fd8199cea8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 265 additions and 19 deletions

View File

@ -0,0 +1,22 @@
{{ config(
materialized = 'view'
) }}
SELECT
system_created_at,
insert_date,
blockchain,
address,
creator,
label_type,
label_subtype,
address_name,
project_name
FROM
{{ source(
'crosschain',
'address_labels'
) }}
WHERE
blockchain = 'arbitrum'
AND address LIKE '0x%'

View File

@ -0,0 +1,17 @@
{{ config (
materialized = 'view'
) }}
SELECT
token_address,
symbol,
provider,
id,
_inserted_timestamp
FROM
{{ source(
'crosschain_silver',
'asset_metadata_priority'
) }}
WHERE
blockchain = 'arbitrum'

View File

@ -0,0 +1,17 @@
{{ config (
materialized = 'view'
) }}
SELECT
HOUR,
token_address,
price,
is_imputed,
_inserted_timestamp
FROM
{{ source(
'crosschain_silver',
'token_prices_priority_hourly'
) }}
WHERE
blockchain = 'arbitrum'

View File

@ -0,0 +1,18 @@
{{ config (
materialized = 'view'
) }}
SELECT
HOUR,
token_address,
price,
is_imputed,
_inserted_timestamp
FROM
{{ source(
'crosschain_silver',
'token_prices_priority_hourly'
) }}
WHERE
blockchain = 'ethereum'
AND token_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'

View File

@ -13,10 +13,4 @@ SELECT
label_subtype,
project_name
FROM
{{ source(
'crosschain_silver',
'address_labels'
) }}
WHERE
blockchain = 'arbitrum'
AND address LIKE '0x%'
{{ ref('silver__labels') }}

View File

@ -26,12 +26,7 @@ eth_price AS (
HOUR,
price AS eth_price
FROM
{{ source(
'ethereum',
'fact_hourly_token_prices'
) }}
WHERE
token_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
{{ ref('silver__prices_eth') }}
)
SELECT
A.tx_hash AS tx_hash,

View File

@ -12,8 +12,4 @@ SELECT
price,
is_imputed
FROM
{{ source(
'crosschain',
'ez_hourly_prices'
) }}
WHERE blockchain = 'arbitrum'
{{ ref('silver__prices') }}

View File

@ -0,0 +1,30 @@
{{ config(
materialized = 'incremental',
unique_key = 'address'
) }}
SELECT
system_created_at,
insert_date,
blockchain,
address,
creator,
label_type,
label_subtype,
address_name,
project_name
FROM
{{ ref('bronze__labels') }}
WHERE
1 = 1
{% if is_incremental() %}
AND insert_date >= (
SELECT
MAX(
insert_date
)
FROM
{{ this }}
)
{% endif %}

View File

@ -0,0 +1,34 @@
{{ config(
materialized = 'incremental',
unique_key = 'token_address'
) }}
SELECT
token_address,
symbol,
provider,
id,
CASE
WHEN provider = 'coingecko' THEN 1
WHEN provider = 'coinmarketcap' THEN 2
END AS priority,
_inserted_timestamp
FROM
{{ ref('bronze__asset_metadata') }}
WHERE
1 = 1
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
)
FROM
{{ this }}
)
{% endif %}
qualify(ROW_NUMBER() over (PARTITION BY token_address
ORDER BY
priority ASC)) = 1

View File

@ -0,0 +1,26 @@
{{ config(
materialized = 'incremental',
unique_key = ['token_address', 'hour']
) }}
SELECT
HOUR,
token_address,
price,
is_imputed,
_inserted_timestamp
FROM
{{ ref('bronze__hourly_prices') }}
WHERE
1 = 1
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
)
FROM
{{ this }}
)
{% endif %}

View File

@ -0,0 +1,37 @@
{{ config(
materialized = 'incremental',
unique_key = ['token_address', 'hour']
) }}
SELECT
p.hour,
p.token_address,
p.price,
p.is_imputed,
p._inserted_timestamp,
COALESCE(
C.token_symbol,
m.symbol
) AS symbol,
C.token_decimals AS decimals
FROM
{{ ref('silver__hourly_prices') }}
p
LEFT JOIN {{ ref('silver__asset_metadata') }}
m
ON p.token_address = m.token_address
LEFT JOIN {{ ref('silver__contracts') }} C
ON p.token_address = C.contract_address
WHERE
1 = 1
{% if is_incremental() %}
AND p._inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) :: DATE - 1
FROM
{{ this }}
)
{% endif %}

View File

@ -0,0 +1,16 @@
version: 2
models:
- name: silver__prices
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TOKEN_ADDRESS
- HOUR
columns:
- name: HOUR
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 1

View File

@ -0,0 +1,26 @@
{{ config(
materialized = 'incremental',
unique_key = ['token_address', 'hour']
) }}
SELECT
HOUR,
token_address,
price,
is_imputed,
_inserted_timestamp
FROM
{{ ref('bronze__hourly_prices_eth') }}
WHERE
1 = 1
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
)
FROM
{{ this }}
)
{% endif %}

View File

@ -0,0 +1,16 @@
version: 2
models:
- name: silver__prices_eth
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TOKEN_ADDRESS
- HOUR
columns:
- name: HOUR
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 1

View File

@ -44,4 +44,6 @@ sources:
schema: silver
tables:
- name: apis_keys
- name: address_labels
- name: address_labels
- name: token_prices_priority_hourly
- name: asset_metadata_priority