Fix timezone handling bug in sales aggregation causing incorrect daily sales totals
harbor run -t snowflake-labs/dbt-fix-timezone-salesharbor download snowflake-labs/dbt-fix-timezone-salesFix a dbt model with data inconsistencies in sales reporting.
The data warehouse consolidates orders from multiple systems (SAP and POS). The operations team has reported that daily sales aggregations are incorrect, particularly around midnight hours.
Fix the int_sales__orders_enriched.sql model to produce correct output.
/app/dbt_models_duckdb/models/intermediate/sales/int_sales__orders_enriched.sql/app/dbt_models_snowflake/models/intermediate/sales/int_sales__orders_enriched.sqlThis task supports both DuckDB and Snowflake. Run echo $DB_TYPE in a shell BEFORE you write any code or spawn any subagents — the live env determines which backend the verifier runs against. Do NOT assume a default from this prose. Both /app/dbt_models_duckdb/ and /app/dbt_models_snowflake/ exist on disk; the verifier only checks the project matching the live $DB_TYPE.
DB_TYPE=duckdb$DUCKDB_PATH (default: /app/database/retail.duckdb)DB_TYPE=snowflakeSNOWFLAKE_ACCOUNTSNOWFLAKE_USERSNOWFLAKE_PASSWORDSNOWFLAKE_DATABASE - The clone database to useSNOWFLAKE_SCHEMASNOWFLAKE_WAREHOUSESNOWFLAKE_ROLE (optional)Note: For Snowflake, the entrypoint automatically creates a clone database and sets SNOWFLAKE_DATABASE. The clone is destroyed when the task completes.
You must configure dbt to connect to the database:
profiles.yml in the dbt project directory with profile name retail_dw_masterDBT_PROFILES_DIR environment variable to the directory containing profiles.ymlConfigure with type: duckdb and the database path from $DUCKDB_PATH.
Configure with type: snowflake using password authentication:
schema: to $SNOWFLAKE_SCHEMA — do NOT leave it blank. A blank or omitted schema makes Snowflake silently default to PUBLIC, so your models get built in the wrong schema and the verifier cannot find them.Data from different source systems is being processed inconsistently. Investigation shows that timestamps from POS and SAP systems are not aligned properly, causing incorrect aggregations when combining the data.
Hints:
The two source systems may store timestamps in different timezones. There is a 5-hour difference between the systems. You can solve this by either:
The timestamp fields in the staging tables use MIXED formats - the data quality is inconsistent. You'll find:
YYYY-MM-DD HH:MM:SSmm/dd/yyyy or mm/dd/yyyy HH:MM:SS (e.g., 07/23/2020, 11/27/2023)dd/mm/yyyy or dd/mm/yyyy HH:MM:SSYYYYMMDDYou'll need to handle all these formats. Try American format before European format.
{% if target.type == 'snowflake' %}) to handle backend-specific SQL where needed. For example, Snowflake uses TRY_TO_TIMESTAMP(...) while DuckDB uses TRY_CAST(... AS TIMESTAMP) or strptime(...). Snowflake's REGEXP_REPLACE does global replacement by default (no 'g' flag), while DuckDB requires 'g'.