-
Notifications
You must be signed in to change notification settings - Fork 0
Modify int_customer_segments: add loyalty_score and churn risk columns #7
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
Open
zingleai
wants to merge
1
commit into
main
Choose a base branch
from
dp/modtest1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
This file contains hidden or 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
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.
🧩 Analysis chain
🏁 Script executed:
Repository: zingleai/dataPortal_demo
Length of output: 2702
🏁 Script executed:
Repository: zingleai/dataPortal_demo
Length of output: 3705
🏁 Script executed:
Repository: zingleai/dataPortal_demo
Length of output: 1787
🏁 Script executed:
Repository: zingleai/dataPortal_demo
Length of output: 36079
🏁 Script executed:
Repository: zingleai/dataPortal_demo
Length of output: 5266
🏁 Script executed:
Repository: zingleai/dataPortal_demo
Length of output: 50380
The
'Inactive'segment is unreachable code;days_since_last_orderbecomes NULL only in downstream models.Within
int_customer_segments, all rows originate fromint_customer_order_history, which aggregates from orders usingGROUP BY customer_id. This meanslifetime_ordersis always ≥ 1, making theelse 'Inactive'branch at line 17 impossible to reach.However,
dim_customersLEFT JOINs this model to the base customer dimension. Customers without orders will have NULL for all segment columns, includingdays_since_last_orderandloyalty_score. Nonot_nulltests protect these columns indim_customers, and downstream churn logic consuming numeric fields will operate on NULLs.Consider either:
not_nulltests on segment columns indim_customersto document that only customers with orders are includedcoalesce()indim_customerswhen selecting segment metrics to provide defaults for customers without ordersdim_customersto only include customers withlifetime_orders > 0🤖 Prompt for AI Agents
🧩 Analysis chain
🌐 Web query:
dbt.datediff macro signature documentation minimum version💡 Result:
dbt.datediffmacro signature (as implemented in dbt’s built-in cross-db macros){{ dbt.datediff(first_date, second_date, datepart) }}The default implementation renders SQL like:
[1]
Minimum dbt version
dbt.datediffis part of the “cross-db macros” that were migrated fromdbt_utilsinto dbt Core (so you call them asdbt.<macro>). That migration is called out in thedbt-utilsv0.9.0 release notes. [2]In practice, packages that bumped to the dbt-utils v1-era / “use
dbt.<macro>” pattern required dbt-core >= 1.3.0. [3]So: minimum dbt-core version to rely on
dbt.datediffis1.3.0. [2][3]Sources: [1] [2] [3]
🌐 Web query:
dbt datediff BigQuery Postgres cross-database macro support💡 Result:
dbt does support a cross-database
datediffmacro for BigQuery and Postgres—it lives in dbt Core (thedbt.namespace), notdbt_utils, in modern projects.{{ dbt.datediff(first_date, second_date, datepart) }}(and similarly{{ dbt.dateadd(...) }}), and dbt will dispatch to the right SQL per adapter (e.g., BigQuery vs Postgres), handling dialect differences like argument order and function names. [1], [2]datediff) were removed fromdbt_utilsand moved to dbt Core, so you must switch fromdbt_utils.datedifftodbt.datediff. [3], [4]Sources
[1] dbt Community Forum (example + motivation for cross-db
datediff) (discourse.getdbt.com)[2] dbt Community Forum (dispatched macros;
dbt_utils.datediffhistory + adapter dispatch concept) (discourse.getdbt.com)[3] dbt-utils README (states cross-db macros removed from dbt-utils v1.0 and points to dbt Core docs) (github.com)
[4] dbt-core v1.2.0 release notes (move cross-db macros from dbt-utils into dbt-core global project) (newreleases.io)
Citations:
🏁 Script executed:
Repository: zingleai/dataPortal_demo
Length of output: 219
🏁 Script executed:
Repository: zingleai/dataPortal_demo
Length of output: 612
🏁 Script executed:
Repository: zingleai/dataPortal_demo
Length of output: 276
🏁 Script executed:
# Check the int_customer_order_history.sql file for last_order_date column cat -n dbt/models/intermediate/int_customer_order_history.sqlRepository: zingleai/dataPortal_demo
Length of output: 944
🏁 Script executed:
Repository: zingleai/dataPortal_demo
Length of output: 1522
Use
{{ dbt.datediff() }}cross-database macro instead of rawdatediff()syntax.The syntax
datediff('day', last_order_date, current_date)is specific to Snowflake, Redshift, and Databricks. BigQuery usesDATE_DIFF()with different argument order, and Postgres has no nativedatediff()function. This will fail or produce incorrect results on any adapter that doesn't support this exact signature.dbt provides a cross-database macro
{{ dbt.datediff(first_date, second_date, datepart) }}(available in dbt-core >= 1.2.0) that handles adapter-specific SQL generation. Your repository requires dbt >= 1.0.0, which supports this macro.🔧 Proposed fix
Note: For Inactive customers (where
lifetime_orders = 0), thelast_order_datewill beNULL, resulting inNULLfordays_since_last_order. Consider whether this behavior is acceptable for churn risk analysis, or if these rows should be excluded or handled explicitly.📝 Committable suggestion
🤖 Prompt for AI Agents