The problem I’m having
I’m running my code to try to work with snapshot in dbt core. I encountered this error saying invalid.
Some example code or error messages in terminal
dbt snapshot
12:48:29 Running with dbt=1.8.5
12:48:36 Registered adapter: snowflake=1.8.3
12:48:36 Unable to do partial parsing because a project config has changed
12:48:36 Unable to do partial parsing because a project config has changed
12:48:38 Encountered an error:
Compilation Error in snapshot sql_snapshot (snapshots\sql_snapshot.sql)
invalid syntax for function call expression
line 4
config(
I will attach my code below. I know I’m only supposed to snapshot sources not recommended for joins. But I don’t think this error has anything to do with this.
{% snapshot sql_snapshot %}
{{
config(
target_database='target_db', -- Replace with your target database
target_schema='SNAPSHOTS',
unique_key='dim_sku_id', -- Choose the unique identifier for your data
strategy='timestamp', -- Tracks changes based on a timestamp
updated_at='UPDATED_AT' -- The column that determines if a row has changed
)
}}
WITH last_inderlivery AS (
SELECT DISTINCT
dim_sku_id,
MAX(ROW_LAST_UPDATED_TS) AS latest_filetimestamp
FROM {{ source('source', 'movements') }} fsm
WHERE ROW_LAST_UPDATED_TS <= CURRENT_DATE
AND dim_stockmovements_reason_code_id = 63
GROUP BY dim_sku_id
),
result AS (
SELECT DISTINCT
dd.dim_date_id AS dim_date_id,
CAST(zfs.latest_filetimestamp AS DATE) AS last_delivery_date,
fs.dim_sku_id AS dim_sku_id,
sku.sku,
CURRENT_DATE - CAST(zfs.latest_filetimestamp AS DATE) AS days_since_last_indelivery,
CASE
WHEN CURRENT_DATE - CAST(zfs.latest_filetimestamp AS DATE) BETWEEN 0 AND 28 THEN 1 -- 0 to 4 weeks
WHEN CURRENT_DATE - CAST(zfs.latest_filetimestamp AS DATE) BETWEEN 29 AND 56 THEN 2 -- 4 to 8 weeks
WHEN CURRENT_DATE - CAST(zfs.latest_filetimestamp AS DATE) BETWEEN 57 AND 84 THEN 3 -- 8 to 12 weeks
WHEN CURRENT_DATE - CAST(zfs.latest_filetimestamp AS DATE) BETWEEN 85 AND 112 THEN 4 -- 12 to 16 weeks
WHEN CURRENT_DATE - CAST(zfs.latest_filetimestamp AS DATE) > 112 THEN 5 -- more than 16 weeks
ELSE 0
END AS AGE_CAT_SKU_LAST_INDELIVERY
FROM {{ source('source', 'stock') }} fs
JOIN {{ source('source', 'date') }} dd
ON fs.dim_date_id = dd.dim_date_id
JOIN {{ source('source', 'sku') }} sku
ON sku.dim_sku_id = fs.dim_sku_id
LEFT JOIN zfs_last_inderlivery zfs
ON zfs.dim_sku_id = fs.dim_sku_id
WHERE dd.dim_date = CURRENT_DATE
AND fs.dim_warehouse_id = 5
)
SELECT *
FROM result
{% endsnapshot %}
Thanks for any help provided!!