Skip to content

Commit

Permalink
mplx more efficient filters + incremental
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwes committed Nov 8, 2024
1 parent bdd7f30 commit a2926cb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
)
}}

SELECT * FROM {{ source('SOLANA_FLIPSIDE', 'fact_events') }}
WHERE program_id IN (SELECT program_id FROM {{ ref('fact_metaplex_programs') }})
SELECT e.* FROM {{ source('SOLANA_FLIPSIDE', 'fact_events') }} e
JOIN {{ ref('fact_metaplex_programs') }} mp ON e.program_id = mp.program_id
AND succeeded = TRUE
{% if is_incremental() %}
AND block_timestamp > (SELECT MAX(block_timestamp) FROM {{ this }})
Expand Down
2 changes: 1 addition & 1 deletion models/staging/metaplex/fact_metaplex_buybacks.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ config(
materialized= "table",
materialized= "incremental",
snowflake_warehouse="METAPLEX"
) }}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ config(
materialized="table",
materialized="incremental",
snowflake_warehouse="METAPLEX"
) }}

Expand Down
18 changes: 11 additions & 7 deletions models/staging/metaplex/fact_metaplex_unique_signers.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ config(
materialized="table",
snowflake_warehouse="METAPLEX"
materialized="incremental",
snowflake_warehouse="METAPLEX",
unique_key=["date"]
) }}

with filtered_transactions AS (
Expand All @@ -9,16 +10,18 @@ with filtered_transactions AS (
DATE_TRUNC('day', t.block_timestamp) AS day_date,
ARRAY_AGG(DISTINCT TRIM(LOWER(unnested_signer.value::STRING))) AS signers
FROM
solana_flipside.core.fact_transactions t
{{ source('SOLANA_FLIPSIDE', 'fact_transactions') }} t
INNER JOIN
solana_flipside.core.fact_events e
{{ ref('fact_filtered_metaplex_solana_events') }} e
ON t.tx_id = e.tx_id
AND e.succeeded = TRUE
AND t.succeeded = TRUE
INNER JOIN
{{ ref('fact_metaplex_programs') }} mp
ON e.program_id = mp.program_id
, LATERAL FLATTEN(input => t.signers) AS unnested_signer
{% if is_incremental() %}
WHERE t.block_timestamp > (SELECT DATEADD(day, -2, MAX(date)) FROM {{ this }})
{% else %}
WHERE t.block_timestamp > '2021-07-01'::date
{% endif %}
GROUP BY
t.tx_id, day_date
),
Expand Down Expand Up @@ -60,5 +63,6 @@ LEFT JOIN
daily_stats m
ON
d.day = m.day
where date < to_date(sysdate())
ORDER BY
d.day DESC

0 comments on commit a2926cb

Please sign in to comment.