Merged PR 2034: Add XE rates to staging
Ingests XE exchange rates from the new sync schema into staging. Related work items: #17212
This commit is contained in:
commit
eaf1a87ab3
4 changed files with 81 additions and 0 deletions
6
macros/tests/not_negative_or_zero.sql
Normal file
6
macros/tests/not_negative_or_zero.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{% test not_negative_or_zero(model, column_name) %}
|
||||
with validation as (select {{ column_name }} as value from {{ model }})
|
||||
select *
|
||||
from validation
|
||||
where value <= 0
|
||||
{% endtest %}
|
||||
8
models/staging/xedotcom/_core_sources.yml
Normal file
8
models/staging/xedotcom/_core_sources.yml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
version: 2
|
||||
|
||||
sources:
|
||||
- name: xedotcom
|
||||
schema: sync_xedotcom_currency_rates
|
||||
tables:
|
||||
- name: exchange_rates
|
||||
identifier: exchange_rates
|
||||
48
models/staging/xedotcom/schema.yml
Normal file
48
models/staging/xedotcom/schema.yml
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
models:
|
||||
- name: stg_xedotcom__exchange_rates
|
||||
description: >-
|
||||
Exchange Rates sourced from xedotcom. The time granularity is daily. Each
|
||||
record holds a currency pair for a specific day.
|
||||
|
||||
Reverse rates are explicit. This means that, for any given day and any
|
||||
given currency pair, you will find two records with opposite from/to
|
||||
positions. So, for 2024-01-01, you will find both a EUR->USD record and a
|
||||
USD->EUR record with the opposite rate (1/rate).
|
||||
columns:
|
||||
- name: id_exchange_rate
|
||||
description: A unique ID for the record, derived from concatenating the
|
||||
currencies and date. Currency order is relevant (EURUSD != USDEUR).
|
||||
data_type: text
|
||||
tests:
|
||||
- not_null
|
||||
- unique
|
||||
- name: from_currency
|
||||
description: The source currency, represented as an ISO 4217 code.
|
||||
data_type: character
|
||||
tests:
|
||||
- not_null
|
||||
- name: to_currency
|
||||
description: The target currency, represented as an ISO 4217 code.
|
||||
data_type: character
|
||||
tests:
|
||||
- not_null
|
||||
- name: rate
|
||||
description: >-
|
||||
The exchange rate, represented as the units of the target currency
|
||||
that one unit of source currency gets you. So, from_currency=USD to
|
||||
to_currency=PLN with rate=4.2 should be read as '1 US Dollar buys me
|
||||
4.2 Polish Zlotys'.
|
||||
|
||||
For same currency pairs (EUR to EUR, USD to USD, etc). The rate will
|
||||
always be one.
|
||||
|
||||
The rate can be smaller than one, but can't be negative.
|
||||
data_type: numeric
|
||||
tests:
|
||||
- not_negative_or_zero
|
||||
- not_null
|
||||
- name: rate_date_utc
|
||||
description: The date in which the rate record is relevant.
|
||||
data_type: date
|
||||
- name: dwh_extracted_at_utc
|
||||
data_type: timestamp without time zone
|
||||
19
models/staging/xedotcom/stg_xedotcom__exchange_rates.sql
Normal file
19
models/staging/xedotcom/stg_xedotcom__exchange_rates.sql
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
with
|
||||
raw_exchange_rates as (select * from {{ source("xedotcom", "exchange_rates") }}),
|
||||
stg_xedotcom__exchange_rates as (
|
||||
select
|
||||
concat(
|
||||
{{ adapter.quote("from_currency") }},
|
||||
{{ adapter.quote("to_currency") }},
|
||||
{{ adapter.quote("rate_date_utc") }}
|
||||
) as id_exchange_rate,
|
||||
{{ adapter.quote("from_currency") }},
|
||||
{{ adapter.quote("to_currency") }},
|
||||
{{ adapter.quote("rate") }},
|
||||
{{ adapter.quote("rate_date_utc") }},
|
||||
{{ adapter.quote("exported_at_utc") }} as dwh_extracted_at_utc
|
||||
|
||||
from raw_exchange_rates
|
||||
)
|
||||
select *
|
||||
from stg_xedotcom__exchange_rates
|
||||
Loading…
Add table
Add a link
Reference in a new issue