-
Notifications
You must be signed in to change notification settings - Fork 5
[WIP] Testing #1048
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
base: master
Are you sure you want to change the base?
[WIP] Testing #1048
Changes from all commits
4374da2
48cbb0f
cb25535
cb8c8e7
811c6a9
27d897a
173e0dd
c5622ad
2262897
e96971c
75bd952
beec2bf
87197ab
28cb665
b4a0387
1a5fd76
2ce9630
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,71 @@ WITH town_class AS ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AND par.deactivat IS NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- doc no's for these sales come from the ccao.additional_mydec_sales table. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- 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 ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sales.parid, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sales.saledt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sales.price, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sales.salekey, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sales.instruno, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sales.instrtyp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sales.nopar, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sales.oldown, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sales.own1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sales.saletype, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sales.deactivat, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sales.cur | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM {{ source('iasworld', 'sales') }} AS sales | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| UNION ALL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REPLACE(md.line_1_primary_pin, '-', '') AS parid, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Match the exact iasworld saledt string format so that the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- dedupe windows below, which partition on raw saledt, treat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- same-day sales from both sources as equal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CONCAT(md.line_4_instrument_date, ' 00:00:00.000') AS saledt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CAST(md.line_11_full_consideration AS DECIMAL(10, 0)) AS price, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CAST(NULL AS DECIMAL(8, 0)) AS salekey, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| md.document_number AS instruno, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Map mydec instrument types to iasworld deed type codes (see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- the sale.deed_type seed) so that these sales pass downstream | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- deed type filters the same way iasworld sales do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CASE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WHEN md.line_5_instrument_type = 'Warranty Deed' THEN '01' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WHEN md.line_5_instrument_type = 'Trustee Deed' THEN '02' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WHEN md.line_5_instrument_type = 'Quit Claim Deed' THEN '03' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WHEN md.line_5_instrument_type = 'Executor Deed' THEN '04' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WHEN md.line_5_instrument_type = 'Beneficial interest' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| THEN '06' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ELSE '05' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| END AS instrtyp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
Author
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. To have the new mydec sales pass the 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
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- 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, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
Author
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. buyer and seller name technically needed for sales val outputs |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CAST(NULL AS VARCHAR) AS saletype, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CAST(NULL AS VARCHAR) AS deactivat, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Y' AS cur | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
Author
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. more stub columns so that the downstream logic doesn't break |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM {{ source('sale', 'mydec') }} AS md | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| INNER JOIN {{ source('ccao', 'additional_mydec_sales') }} AS ams | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ON md.document_number = ams.doc_no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Exclude doc nos already live in iasworld so we keep parity with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- prod for sales that were ingested normally | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LEFT JOIN ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT DISTINCT NULLIF(REPLACE(instruno, 'D', ''), '') AS doc_no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM {{ source('iasworld', 'sales') }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WHERE deactivat IS NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AND cur = 'Y' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) AS ias | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
Author
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. Match |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ON md.document_number = ias.doc_no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WHERE NOT md.is_multisale | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
Author
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. Multi-sale exclusion is done here, then we put '1' as |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AND md.line_11_full_consideration IS NOT NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AND ias.doc_no IS NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- "nopar" isn't entirely accurate for sales associated with only one parcel, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- so we create our own counter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| calculated AS ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -29,7 +94,7 @@ calculated AS ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT DISTINCT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parid, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| NULLIF(REPLACE(instruno, 'D', ''), '') AS instruno | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM {{ source('iasworld', 'sales') }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM sales_unioned | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WHERE deactivat IS NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AND cur = 'Y' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -128,7 +193,7 @@ unique_sales AS ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sales.instrtyp IN ('03', '04', '06') OR sales.instrtyp IS NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FALSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) AS sale_filter_deed_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM {{ source('iasworld', 'sales') }} AS sales | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM sales_unioned AS sales | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LEFT JOIN calculated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ON NULLIF(REPLACE(sales.instruno, 'D', ''), '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| = calculated.instruno | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -145,14 +210,15 @@ unique_sales AS ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AND tc.township_code IS NOT NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AND sales.price IS NOT NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) AS sales_calculated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Only use max price by pin/sale date | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WHERE max_price = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AND (bad_doc_no = 1 OR is_multisale = TRUE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mydec_sales AS ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT * FROM ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REPLACE(document_number, 'D', '') AS doc_no, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REPLACE(line_1_primary_pin, '-', '') AS pin, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,12 +11,12 @@ SELECT | |
| sf.sv_outlier_reason3, | ||
| sf.run_id, | ||
| sf.version | ||
| FROM {{ source('sale', 'flag') }} AS sf | ||
| FROM z_dev_miwagne_sale.flag AS sf | ||
|
Member
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. [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:
You may know this already, but I figured I'd drop a comment to make it extra clear!
Member
Author
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. 2 is very clarifying - that the managed DAG that
Member
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. Yup, that's right! |
||
| INNER JOIN ( | ||
| SELECT | ||
| meta_sale_document_num, | ||
| MAX(version) AS max_version | ||
| FROM {{ source('sale', 'flag') }} | ||
| FROM z_dev_miwagne_sale.flag | ||
| GROUP BY meta_sale_document_num | ||
| ) AS mv | ||
| ON sf.meta_sale_document_num = mv.meta_sale_document_num | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| library(arrow) | ||
| library(dplyr) | ||
| library(openxlsx) | ||
|
|
||
| # Declare output paths | ||
| AWS_S3_WAREHOUSE_BUCKET <- Sys.getenv("AWS_S3_WAREHOUSE_BUCKET") | ||
| output_bucket <- file.path( | ||
| AWS_S3_WAREHOUSE_BUCKET, | ||
| "ccao", "other", "additional_mydec_sales" | ||
| ) | ||
|
|
||
| input_file <- "O:/CCAODATA/data/additional_mydec_sales/Missing Sales.xlsx" | ||
|
|
||
| openxlsx::read.xlsx(input_file, sheet = "Summary") %>% | ||
| select(doc_no = `203.Document.Number`) %>% | ||
| mutate( | ||
| doc_no = gsub("\\D", "", as.character(doc_no)), | ||
| loaded_at = as.character(Sys.time()) | ||
| ) %>% | ||
| write_parquet(file.path(output_bucket, "additional_mydec_sales.parquet")) |
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.
The idea here is to put mydec sales into the iasworld structure upstream of all the filters