-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tags to models #16
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5bd13b4
Add tags to models
chowbao 99d51c7
Add comma
chowbao 84518bf
Remove type anomaly check
chowbao e721860
remove volume check
chowbao ab6b3d0
Remove tags from staging
chowbao ccb6fc5
Revert "Remove tags from staging"
chowbao 5d99361
Fix tags
chowbao adca59a
Add current tables
chowbao 220a19d
Update staging tags
chowbao f31c132
Update tag name
chowbao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
models/docs/marts/ledger_current_state/account_signers_current.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[comment]: < Account Signers Current - | ||
|
||
{% docs account_signers_current %} | ||
|
||
The `account_signers_current` table is a nightly snapshotted table that represents the current status of all account signers associated with an account. The table returns the latest account entry, which is defined as the highest `last_modified_ledger` per account signer on the Stellar Network. Deleted signers are included in the table. For full state history, please use the `account_signers` table. | ||
|
||
**The `account_signers_current` table is only updated nightly. Intraday ledger state changes are not captured in the table.** | ||
|
||
The `account_signers_current` table may be joined to the `accounts` table in order to find out more information about the originating account. The signers table has a many-to-one relationship with the accounts table, so you should expect multiple records to be returned for each `account_id`. | ||
|
||
{% enddocs %} |
11 changes: 11 additions & 0 deletions
11
models/docs/marts/ledger_current_state/accounts_current.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[comment]: < Accounts Current - | ||
|
||
{% docs accounts_current %} | ||
|
||
The `accounts_current` table is a nightly snapshotted table that represents the current state of account ledger entries. The table returns the latest account entry, which is defined as the highest `last_modified_ledger` per account on the Stellar Network. Deleted accounts are included in the table. For full state history, please use the `accounts` table. | ||
|
||
**The `accounts_current` table is only updated nightly. Intraday ledger state changes are not captured in the table.** | ||
|
||
As a reminder, account ledger entries store detailed information for a given account, including current account status, preconditions for transaction authorization, security settings and account balance. The balance reported in the accounts table reflects the account’s XLM balance only. All other asset balances are reported in the `trust_lines` table. | ||
|
||
{% enddocs %} |
15 changes: 15 additions & 0 deletions
15
models/docs/marts/ledger_current_state/liquidity_pools_current.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[comment]: < Liquidity Pools Current - | ||
|
||
{% docs liquidity_pools_current %} | ||
|
||
The `liquidity_pools_current` table is a nightly snapshotted table that represents the current status of all liquidity pools. The table returns the latest pool entry, which is defined as the highest `last_modified_ledger` per liquidity pool on the Stellar Network. Deleted pools are included in the table. For full state history, please use the `liquidity_pools` table. | ||
|
||
**The `liquidity_pools_current` table is only updated nightly. Intraday ledger state changes are not captured in the table.** | ||
|
||
{% enddocs %} | ||
|
||
{% docs asset_pair %} | ||
|
||
A concatenated representation of the pair of assets in the liquidity pool, in the form `asset_a_code:asset_b_code`. In the case when the pool contains `XLM`, `XLM` is written as an asset code even though the native asset normally has a null asset code. Asset pair intends to make a human readable name for a pool, but does **not** represent a unique pool id. Different asset issuers can mint asset codes of the same name. In these cases, there will be duplicate `asset_pair` names. The pool ids are unique. | ||
|
||
{% enddocs %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[comment]: < Offers Current - | ||
|
||
{% docs offers_current %} | ||
|
||
The `offers_current` table is a nightly snapshotted table that represents the current orderbook of the Stellar Decentralized Exchange. The table returns the latest offer, which is defined as the highest `last_modified_ledger` per offer on the Stellar Network. Deleted offers are included in the table. An offer is deleted when the seller either updates their offer price to zero or an order is completely filled. For full orderbook history, please use the `offers` table. | ||
|
||
**The `offers_current` table is only updated nightly. Intraday ledger state changes are not captured in the table.** | ||
|
||
For more information on how the Stellar Decentralized Exchange works, please read [these docs](https://developers.stellar.org/docs/encyclopedia/liquidity-on-stellar-sdex-liquidity-pools#order-books). | ||
|
||
{% enddocs %} |
11 changes: 11 additions & 0 deletions
11
models/docs/marts/ledger_current_state/trust_lines_current.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[comment]: < Trust Lines Current - | ||
|
||
{% docs trust_lines_current %} | ||
|
||
The `trust_lines_current` table is a nightly snapshotted table that represents the current state of account trustlines. The table returns the latest trustline entry, per account, which is defined as the highest `last_modified_ledger` per trustline/account on the Stellar Network. Deleted trust lines are included in the table. For full state history, please use the `trust_lines` table. | ||
|
||
**The `trust_lines_current` table is only updated nightly. Intraday ledger state changes are not captured in the table.** | ||
|
||
As a reminder, trustline ledger entries store detailed information for assets trusted by a given account. The balance reported in the trustlines table reflects the account’s trusted asset balances, `XLM` balance is reported in the `accounts` table. | ||
|
||
{% enddocs %} |
62 changes: 62 additions & 0 deletions
62
models/marts/ledger_current_state/account_signers_current.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{{ | ||
config( | ||
tags = ["current_state"], | ||
materialized = "incremental", | ||
unique_key = "unique_id", | ||
cluster_by = "account_id" | ||
) | ||
}} | ||
|
||
/* Finds the latest state of each account signer in the `account_signers` table. | ||
Ranks each record (grain: one row per account) using | ||
last modified ledger sequence number. View includes all account signers. | ||
(Deleted and Existing). View matches the Horizon snapshotted state tables. */ | ||
with | ||
current_signers as ( | ||
select | ||
s.account_id | ||
, s.signer | ||
, s.weight | ||
, s.sponsor | ||
, s.last_modified_ledger | ||
, l.closed_at | ||
, s.ledger_entry_change | ||
, s.deleted | ||
-- table only has natural keys, creating a primary key | ||
, concat(s.account_id, '-', s.signer | ||
) as unique_id | ||
, s.batch_run_date | ||
, s.batch_insert_ts | ||
, row_number() | ||
over ( | ||
partition by s.account_id, s.signer | ||
order by s.last_modified_ledger desc, s.ledger_entry_change desc | ||
) as row_nr | ||
from {{ ref('stg_account_signers') }} as s | ||
join {{ ref('stg_history_ledgers') }} as l | ||
on s.last_modified_ledger = l.sequence | ||
|
||
{% if is_incremental() %} | ||
-- limit the number of partitions fetched | ||
where | ||
s.batch_run_date >= date_sub(current_date(), interval 30 day) | ||
-- fetch the last week of records loaded | ||
and timestamp_add(s.batch_insert_ts, interval 7 day) | ||
> (select max(t.upstream_insert_ts) from {{ this }} as t) | ||
{% endif %} | ||
) | ||
select | ||
account_id | ||
, signer | ||
, weight | ||
, sponsor | ||
, last_modified_ledger | ||
, ledger_entry_change | ||
, closed_at | ||
, deleted | ||
, unique_id | ||
, batch_run_date | ||
, batch_insert_ts as upstream_insert_ts | ||
, current_timestamp() as batch_insert_ts | ||
from current_signers | ||
where row_nr = 1 |
121 changes: 121 additions & 0 deletions
121
models/marts/ledger_current_state/account_signers_current.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: account_signers_current | ||
description: '{{ doc("account_signers_current") }}' | ||
tests: | ||
- dbt_utils.recency: | ||
datepart: hour | ||
field: cast(closed_at as datetime) | ||
interval: 12 | ||
config: | ||
severity: warn | ||
meta: | ||
description: | ||
"Monitors the freshness of your table over time, as the expected time between data updates." | ||
- elementary.volume_anomalies: | ||
timestamp_column: closed_at | ||
backfill_days: 90 | ||
time_bucket: | ||
period: day | ||
count: 1 | ||
meta: | ||
description: | ||
"Monitors the row count of your table over time." | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- account_id | ||
- signer | ||
- ledger_entry_change | ||
- last_modified_ledger | ||
config: | ||
where: closed_at >= timestamp_trunc(timestamp_sub(current_timestamp(), interval 2 day), day) | ||
and closed_at < timestamp_trunc(current_timestamp(), day) | ||
meta: | ||
description: | ||
"Tests the uniqueness combination of: account_id, signer, ledger_entry_change and last_modified_ledger." | ||
columns: | ||
- name: account_id | ||
description: '{{ doc("account_id") }}' | ||
tests: | ||
- not_null: | ||
config: | ||
where: closed_at > current_timestamp - interval 2 day | ||
|
||
- name: signer | ||
description: '{{ doc("signer") }}' | ||
tests: | ||
- not_null: | ||
config: | ||
where: closed_at > current_timestamp - interval 2 day | ||
|
||
- name: weight | ||
description: '{{ doc("weight") }}' | ||
tests: | ||
- not_null: | ||
config: | ||
where: closed_at > current_timestamp - interval 2 day | ||
|
||
- name: sponsor | ||
description: '{{ doc("sponsor") }}' | ||
|
||
- name: last_modified_ledger | ||
description: '{{ doc("last_modified_ledger") }}' | ||
tests: | ||
- not_null: | ||
config: | ||
where: closed_at > current_timestamp - interval 2 day | ||
|
||
- name: ledger_entry_change | ||
description: '{{ doc("ledger_entry_change") }}' | ||
tests: | ||
- not_null: | ||
config: | ||
where: closed_at > current_timestamp - interval 2 day | ||
- accepted_values: | ||
values: [0, 1, 2] | ||
quote: false | ||
|
||
- name: closed_at | ||
description: '{{ doc("closed_at") }}' | ||
tests: | ||
- not_null: | ||
config: | ||
where: closed_at > current_timestamp - interval 2 day | ||
|
||
- name: deleted | ||
description: '{{ doc("deleted") }}' | ||
tests: | ||
- not_null: | ||
config: | ||
where: closed_at > current_timestamp - interval 2 day | ||
- accepted_values: | ||
values: ["true", "false"] | ||
quote: false | ||
|
||
- name: batch_run_date | ||
description: '{{ doc("batch_run_date") }}' | ||
tests: | ||
- not_null: | ||
config: | ||
where: closed_at > current_timestamp - interval 2 day | ||
|
||
- name: batch_insert_ts | ||
description: '{{ doc("batch_insert_ts") }}' | ||
tests: | ||
- not_null: | ||
config: | ||
where: closed_at > current_timestamp - interval 2 day | ||
|
||
- name: upstream_insert_ts | ||
description: '{{ doc("upstream_insert_ts") }}' | ||
tests: | ||
- not_null: | ||
config: | ||
where: closed_at > current_timestamp - interval 2 day | ||
|
||
- name: unique_id | ||
description: '{{ doc("unique_id") }}' | ||
tests: | ||
- not_null | ||
- unique |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{{ | ||
config( | ||
tags = ["current_state"], | ||
materialized = "incremental", | ||
unique_key = "account_id" | ||
) | ||
}} | ||
/* Returns the latest state of each account in the `accounts` table. | ||
Table includes all accounts. (Deleted and Existing). | ||
|
||
Rank all rows for an account by last modified ledger and ledger entry type. | ||
Deleted entry types reuse the last modified ledger sequence */ | ||
|
||
with | ||
current_accts as ( | ||
select | ||
a.account_id | ||
, a.balance | ||
, a.buying_liabilities | ||
, a.selling_liabilities | ||
, a.sequence_number | ||
, a.num_subentries | ||
, a.num_sponsoring | ||
, a.num_sponsored | ||
, a.inflation_destination | ||
, a.flags | ||
, a.home_domain | ||
, a.master_weight | ||
, a.threshold_low | ||
, a.threshold_medium | ||
, a.threshold_high | ||
, a.last_modified_ledger | ||
, a.ledger_entry_change | ||
, l.closed_at | ||
, a.deleted | ||
, a.sponsor | ||
, a.sequence_ledger | ||
, a.sequence_time | ||
, a.batch_run_date | ||
, a.batch_insert_ts | ||
, row_number() | ||
over ( | ||
partition by a.account_id | ||
order by | ||
a.last_modified_ledger desc | ||
, a.ledger_entry_change desc | ||
) | ||
as row_nr | ||
from {{ ref('stg_accounts') }} as a | ||
join {{ ref('stg_history_ledgers') }} as l | ||
on a.last_modified_ledger = l.sequence | ||
|
||
{% if is_incremental() %} | ||
-- limit the number of partitions fetched | ||
where | ||
a.batch_run_date >= date_sub(current_date(), interval 30 day) | ||
-- fetch the last week of records loaded | ||
and timestamp_add(a.batch_insert_ts, interval 7 day) | ||
> (select max(t.upstream_insert_ts) from {{ this }} as t) | ||
{% endif %} | ||
) | ||
|
||
/* Return the same fields as the `accounts` table */ | ||
select | ||
account_id | ||
, balance | ||
, buying_liabilities | ||
, selling_liabilities | ||
, sequence_number | ||
, num_subentries | ||
, num_sponsoring | ||
, num_sponsored | ||
, inflation_destination | ||
, flags | ||
, home_domain | ||
, master_weight | ||
, threshold_low | ||
, threshold_medium | ||
, threshold_high | ||
, last_modified_ledger | ||
, ledger_entry_change | ||
, closed_at | ||
, deleted | ||
, sponsor | ||
, sequence_ledger | ||
, sequence_time | ||
, batch_run_date | ||
, batch_insert_ts as upstream_insert_ts | ||
, current_timestamp() as batch_insert_ts | ||
from current_accts | ||
where row_nr = 1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: I think we can remove the join against
history_ledgers
on the current state tables. Since the state tables now all haveclosed_at
. We will need to validate that though and confirm that theclosed_at
field is backfilled appropriately.