DBT: Postgres Traders
File location: s3://trase-storage/postgres_views/postgres_traders.parquet
DBT model name: postgres_traders
Explore on Metabase: Full table; summary statistics
Explore dependencies/lineage: link
Description
Queries the Postgres 'views.traders_basic_info' view and brings the traders names, array of labels, array of groups (each a json containing group name, start and end time), and the current time to know when it was updated.
Details
| Column | Type | Description |
|---|---|---|
name |
VARCHAR |
|
trader_node_id |
BIGINT |
|
trase_id |
VARCHAR |
|
labels |
VARCHAR[] |
|
groups |
JSON[] |
|
updated_at |
TIMESTAMP WITH TIME ZONE |
No data tests defined 🧐
Models
brazil_beef_sei_pcs_v2_2_2_for_ingest_2010_2023brazil_bol_2023_silverdiet_trase_coffee_trade_consolidated_2020diet_trase_coffee_trader_parentsgold_colombia_cd_coffee_2020gold_india_trade_coffee_2020gold_indonesia_bol_coffee_2020gold_peru_cd_coffee_2020gold_vietnam_trade_coffee_2020pre_gold_cote_divoire_coffee_2020
{{
config(materialized='external')
}}
WITH
-- Filter out records without labels, or without name + trase_id
original_table AS (
SELECT
name,
trader_node_id,
trase_id,
labels::VARCHAR[] AS labels,
groups::JSON[] AS groups,
FROM
{{ this.identifier }}_postgres_db.views.traders_basic_info
WHERE
labels[1] IS NOT NULL
AND
NOT (name IS NULL AND trase_id IS NULL)
),
-- There are 3 records with repeated trase_id. Keep the one with the most groups
ranked_records AS (
SELECT
*,
ROW_NUMBER() OVER (
PARTITION BY trase_id
ORDER BY array_length(groups, 1) DESC
) AS rn
FROM original_table
),
without_repeated_trase_id AS (
SELECT
name,
trader_node_id,
trase_id,
labels,
groups,
NOW() AS updated_at
FROM ranked_records
WHERE rn = 1
OR trase_id IS NULL
)
SELECT * FROM without_repeated_trase_id
-
Dbt path:
trase_production.main.postgres_traders -
Containing yaml link: trase/data_pipeline/models/postgres_views/_schema_postgres_tables.yml
-
Model file: trase/data_pipeline/models/postgres_views/postgres_traders.sql
-
Tags:
postgres,traders