-
Notifications
You must be signed in to change notification settings - Fork 100
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
[DS-3326] Add state to subplat subscriptions v2 #5836
Open
BenWu
wants to merge
7
commits into
main
Choose a base branch
from
benwu/stripe-sub-state
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 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
97a0ed7
[DS-3326] Add state to subplat subscriptions v2
BenWu 6d37825
Update schema
BenWu 11a5e36
indents
BenWu 0467bfa
Update column names, descriptions, comments; fixes
BenWu 931c938
oop
BenWu 4346584
update descriptions
BenWu eaba223
🧹
BenWu 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 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -40,18 +40,69 @@ WITH original_changelog AS ( | |||||
JSON_VALUE(customer.metadata.userid) AS userid, | ||||||
TO_HEX(SHA256(JSON_VALUE(customer.metadata.userid))) AS userid_sha256 | ||||||
) AS metadata, | ||||||
-- Limit address data to just country since the metadata includes FxA user IDs | ||||||
-- and this is in a Mozilla-confidential dataset. | ||||||
STRUCT(customer.address.country) AS address, | ||||||
-- Limit address data to country and state since the metadata includes FxA user IDs | ||||||
-- and this is in a Mozilla-confidential dataset. State is only for US and Canada. | ||||||
STRUCT( | ||||||
NULLIF(customer.address.country, ""), | ||||||
IF( | ||||||
customer.address.country IN ("US", "CA"), | ||||||
COALESCE( | ||||||
-- Only use two-letter codes for consistency since billing addresses sometimes have full names | ||||||
IF(LENGTH(customer.address.state) = 2, customer.address.state, NULL), | ||||||
us_zip_code_prefixes.state_code, | ||||||
ca_postal_districts.province_code | ||||||
), | ||||||
NULL | ||||||
) AS state | ||||||
) AS address, | ||||||
( | ||||||
SELECT AS STRUCT | ||||||
customer.shipping.* REPLACE (STRUCT(customer.shipping.address.country) AS address) | ||||||
customer.shipping.* REPLACE ( | ||||||
STRUCT( | ||||||
NULLIF(customer.shipping.address.country, ""), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
IF( | ||||||
customer.shipping.address.country IN ("US", "CA"), | ||||||
COALESCE( | ||||||
IF( | ||||||
LENGTH(customer.shipping.address.state) = 2, | ||||||
customer.shipping.address.state, | ||||||
NULL | ||||||
), | ||||||
us_shipping_zip_code_prefixes.state_code, | ||||||
ca_shipping_postal_districts.province_code | ||||||
), | ||||||
NULL | ||||||
) AS state | ||||||
) AS address | ||||||
) | ||||||
) AS shipping | ||||||
) | ||||||
) AS customer, | ||||||
ROW_NUMBER() OVER customer_changes_asc AS customer_change_number | ||||||
FROM | ||||||
`moz-fx-data-shared-prod`.stripe_external.customers_changelog_v1 | ||||||
-- try to get state using postal code if state field is unavailable | ||||||
LEFT JOIN | ||||||
`moz-fx-data-shared-prod.static.us_zip_code_prefixes_v1` AS us_shipping_zip_code_prefixes | ||||||
ON customer.shipping.address.country = "US" | ||||||
AND LEFT( | ||||||
customer.shipping.address.postal_code, | ||||||
3 | ||||||
) = us_shipping_zip_code_prefixes.zip_code_prefix | ||||||
LEFT JOIN | ||||||
`moz-fx-data-shared-prod.static.us_zip_code_prefixes_v1` AS us_zip_code_prefixes | ||||||
ON customer.address.country = "US" | ||||||
AND LEFT(customer.address.postal_code, 3) = us_zip_code_prefixes.zip_code_prefix | ||||||
LEFT JOIN | ||||||
`moz-fx-data-shared-prod.static.ca_postal_districts_v1` AS ca_shipping_postal_districts | ||||||
ON customer.shipping.address.country = "CA" | ||||||
AND UPPER( | ||||||
LEFT(customer.shipping.address.postal_code, 1) | ||||||
) = ca_shipping_postal_districts.postal_district_code | ||||||
LEFT JOIN | ||||||
`moz-fx-data-shared-prod.static.ca_postal_districts_v1` AS ca_postal_districts | ||||||
ON customer.address.country = "CA" | ||||||
AND UPPER(LEFT(customer.address.postal_code, 1)) = ca_postal_districts.postal_district_code | ||||||
WINDOW | ||||||
customer_changes_asc AS ( | ||||||
PARTITION BY | ||||||
|
@@ -68,7 +119,7 @@ pre_fivetran_changelog AS ( | |||||
TIMESTAMP '2022-03-25 00:02:29' AS `timestamp`, | ||||||
STRUCT( | ||||||
id, | ||||||
STRUCT(address.country) AS address, | ||||||
STRUCT(address.country, address.state) AS address, | ||||||
created, | ||||||
CAST(NULL AS STRING) AS default_source_id, | ||||||
CAST( | ||||||
|
@@ -103,7 +154,7 @@ pre_fivetran_changelog AS ( | |||||
CAST(NULL AS STRING) AS userid, | ||||||
JSON_VALUE(metadata.userid_sha256) AS userid_sha256 | ||||||
) AS metadata, | ||||||
CAST(NULL AS STRUCT<address STRUCT<country STRING>>) AS shipping, | ||||||
CAST(NULL AS STRUCT<address STRUCT<country STRING, state STRING>>) AS shipping, | ||||||
CAST(NULL AS STRING) AS tax_exempt | ||||||
) AS customer, | ||||||
1 AS customer_change_number | ||||||
|
This file contains 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
Oops, something went wrong.
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.