Skip to content

[WIP] Testing#1048

Open
wagnerlmichael wants to merge 17 commits into
masterfrom
add-additional-mydec-sales-to-vw-pin-sale
Open

[WIP] Testing#1048
wagnerlmichael wants to merge 17 commits into
masterfrom
add-additional-mydec-sales-to-vw-pin-sale

Conversation

@wagnerlmichael

Copy link
Copy Markdown
Member

No description provided.

@wagnerlmichael

wagnerlmichael commented Jun 12, 2026

Copy link
Copy Markdown
Member Author

View diff at a glance

SELECT 
  (SELECT count(*) FROM "z_ci_add_additional_mydec_sales_to_vw_pin_sale_default"."vw_pin_sale")
  -
  (SELECT count(*) FROM "default"."vw_pin_sale")
  AS row_difference;
# row_difference
1 9882
SELECT
  COUNT(*) AS sales_matching_missing_list,
  COUNT_IF(sale.sale_key IS NULL) AS from_injected_cte,
  COUNT_IF(sale.sale_key IS NOT NULL) AS already_in_iasworld
FROM "z_ci_add_additional_mydec_sales_to_vw_pin_sale_default"."vw_pin_sale" AS sale
INNER JOIN "ccao"."additional_mydec_sales" AS ams
  ON sale.doc_no = ams.doc_no
# sales_matching_missing_list from_injected_cte already_in_iasworld
1 10,050 9,887 163

WHEN md.line_5_instrument_type = 'Beneficial interest'
THEN '06'
ELSE '05'
END AS instrtyp,

@wagnerlmichael wagnerlmichael Jun 12, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To have the new mydec sales pass the sale_filter_deed_type gates, we grab values that the filter understands (01, 02...).

SELECT
      md.line_5_instrument_type,
      COUNT(*) AS n_all_mydec,
      COUNT(ams.doc_no) AS n_in_injection_list
  FROM "sale"."mydec" AS md
  LEFT JOIN "ccao"."additional_mydec_sales" AS ams
      ON REPLACE(md.document_number, 'D', '') = ams.doc_no
  GROUP BY md.line_5_instrument_type
  ORDER BY n_all_mydec DESC
# line_5_instrument_type n_all_mydec n_in_injection_list
1 Warranty Deed 706392 8304
2 (NULL) 396265 2
3 Trustee Deed 127690 1548
4 Special Warranty Deed 118141 1668
5 Quit Claim Deed 16292 137
6 Judicial Sale 12217 89
7 Executor Deed 8613 84
8 Administrator's Deed 6637 112
9 Deed in Trust 5330 53
10 Other 4240 44
11 Beneficial interest 1523 15
12 Guardian's Deed 932 9
13 Limited Warranty Deed 811 9
14 Judge's Deed 551 4
15 Sheriff's Deed 361 5
. . .

-- Non-multisale mydec sales are single-parcel by definition
CAST(1 AS DECIMAL(4, 0)) AS nopar,
NULLIF(TRIM(md.seller_name), '') AS oldown,
NULLIF(TRIM(md.buyer_name), '') AS own1,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buyer and seller name technically needed for sales val outputs

AND cur = 'Y'
) AS ias
ON REPLACE(md.document_number, 'D', '') = ias.doc_no
WHERE NOT md.is_multisale

@wagnerlmichael wagnerlmichael Jun 12, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multi-sale exclusion is done here, then we put '1' as nopar for compatibility

FROM {{ source('iasworld', 'sales') }}
WHERE deactivat IS NULL
AND cur = 'Y'
) AS ias

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Match ias.doc_No onto the inner joined mydec sales and then we filter AND ias.doc_no IS NULL to remove sales that already are present in iasworld

NULLIF(TRIM(md.buyer_name), '') AS own1,
CAST(NULL AS VARCHAR) AS saletype,
CAST(NULL AS VARCHAR) AS deactivat,
'Y' AS cur

@wagnerlmichael wagnerlmichael Jun 15, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more stub columns so that the downstream logic doesn't break

-- Constructing the rows here, upstream of all other logic, means the
-- additional sales flow through the same dedupe windows and filters as
-- iasworld sales
sales_unioned AS (

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is to put mydec sales into the iasworld structure upstream of all the filters

Comment on lines +67 to +68
'Administrator''s Deed',
'Guardian''s Deed'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the right filter for these but I'm not positive

@wrridgeway wrridgeway left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this is genuinely great work. Super impressed at the attention to detail you put in here, you caught stuff I probably wouldn't even have. I just have two minor requests:

  • Can we move removing the 'D' in ccao.additional_mydec_sales.document_number into the warehouse script like we do for the normal mydec sales and out of default.vw_pin_sale? Just for the sake of consistency.

  • Can we double check that we've mapped deed types as thoroughly as possible? I think using something like the query below could help investigate how it's being done currently:

select distinct sales.instrtyp,
	mydec.line_5_instrument_type
from iasworld.sales
	left join sale.mydec on sales.instruno = mydec.document_number
where sales.cur = 'Y'
	and sales.deactivat is null
	and sales.instrtyp in ('01', '02', '03', '04', '05', '06', '99')
	and trim(mydec.line_5_instrument_type) != ''
	and substr(sales.saledt, 1, 4) = '2025'
order by sales.instrtyp

There's definitely some overlap in how these map to each other, but we can just use our better judgement to decide how they should map in those cases.

Comment thread dbt/models/default/default.vw_pin_sale.sql Outdated
@wrridgeway wrridgeway marked this pull request as ready for review June 15, 2026 17:22
@wrridgeway wrridgeway requested a review from a team as a code owner June 15, 2026 17:22
wagnerlmichael and others added 4 commits June 15, 2026 12:27

@wrridgeway wrridgeway left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks @wagnerlmichael. We may need to update the deed type mapping if Derrick informs us of anything new, but otherwise I think we're good to do.

I'll drop a bit more review here. Checking to make sure we only have row diffs for 2025:

with old as (
	select year,
		count(*) as old_count
	from default.vw_pin_sale
	group by year
),
new as (
	select year,
		count(*) as new_count
	from z_ci_add_additional_mydec_sales_to_vw_pin_sale_default.vw_pin_sale
	group by year
)
select old.*,
	new.new_count,
	abs(old.old_count - new.new_count) as diff
from old
	left join new on old.year = new.year
where abs(old.old_count - new.new_count) != 0
year old_count new_count diff
2025 66131 76013 9882

Checking we're still unique by doc_no for non-multisales:

select doc_no,
	count(*)
from z_ci_add_additional_mydec_sales_to_vw_pin_sale_default.vw_pin_sale
where not is_multisale
group by doc_no
having count(*) > 1

returns nothing.

@jeancochrane jeancochrane left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few thoughts on the dbt architecture here! I know dbt refs and sources can be confusing, so I'm happy to chat it out if it would be faster.

I suspect you may just be waiting until later on to add more context, but to be clear: Even though this work is likely temporary and won't get merged to the main branch, we should still give the PR a clear title and description so that we can find this PR in the future and remind ourselves what we did and why we did it.

LEFT JOIN mydec_sales
ON unique_sales.doc_no = mydec_sales.doc_no
LEFT JOIN {{ ref('sale.vw_outlier') }} AS outlier
LEFT JOIN z_ci_add_additional_mydec_sales_to_vw_pin_sale_sale.vw_outlier AS outlier

@jeancochrane jeancochrane Jun 16, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question, non-blocking] When the build-and-test-dbt GitHub workflow builds a staging version of default.vw_pin_sale using the new view definition in this branch, it should automatically resolve {{ ref('sale.vw_outlier') }} to z_ci_add_additional_mydec_sales_to_vw_pin_sale_sale.vw_outlier, since dbt will be running in a CI environment on the add-additional-mydec-sales-to-vw-pin-sale branch. So I wouldn't expect you to have to make this change in order for default.vw_pin_sale to build correctly. Is that not the case here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. I made the z_dev_miwagne_sale.flag AS sf change first and then just edited the other two in the same way without thinking very hard. I'm sure that is how it will work when I switch it back

sf.run_id,
sf.version
FROM {{ source('sale', 'flag') }} AS sf
FROM z_dev_miwagne_sale.flag AS sf

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Thought, non-blocking] In contrast to my above comment, this hardcoded schema reference is necessary in order for the build to work, for two reasons:

  1. sale.flag is a dbt source (i.e. it's managed outside of the dbt DAG) so {{ source('sale', 'flag') }} will always resolve to the sale schema, even when dbt runs in a dev or CI environment
  2. z_dev_miwagne_sale is a separate dev environment, so even if sale.flag were defined as a dbt model and managed in the dbt DAG, dbt would resolve {{ ref('sale.flag') }} to the z_ci_add_additional_mydec_sales_to_vw_pin_sale_sale schema, not z_dev_miwagne_sale

You may know this already, but I figured I'd drop a comment to make it extra clear!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 is very clarifying - that the managed DAG that build-and-test-dbt uses for staging vs prod assets is a separate thing from our hardwired sales val dev environment setup. Is that roughly correct?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's right!

Comment thread dbt/models/sale/sale.vw_outlier.sql Outdated
'has_characteristic_change' VALUE has_characteristic_change
) AS review_json -- noqa: enable=CP02,RF02
FROM {{ ref('sale.vw_flag') }} AS flag
FROM z_ci_add_additional_mydec_sales_to_vw_pin_sale_sale.vw_flag AS flag

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question, non-blocking] This ref is the same as the one I commented on in default.vw_pin_sale: In theory, ref() should resolve correctly here, so my question stands about why we need to hardcode the schema name.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up question - will the ref resolve correctly pointing to the dev table even when there is no diff to the file itself?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so!

@wrridgeway wrridgeway self-requested a review June 16, 2026 19:39
@wrridgeway

wrridgeway commented Jun 16, 2026

Copy link
Copy Markdown
Member

Just to be clear - I approved the original changes to default.vw_pin_sale, but I'm not qualified to approve any of the sales val changes that need to be made here, that's gonna be up to @jeancochrane.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants