Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions dbt/models/default/default.vw_pin_address.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
-- Source of truth view for PIN address, both legal and mailing

-- We need a CTE here since MAILDAT is not unique by PIN and TAXYR - it tracks
-- changes to mailing addresses within a year for a given PIN using MAILSEQ.
-- For now, we're chosing to use the final address for a pin in any year where
-- it has more than one since this seems to align with which addresses surface
-- on the Treasurer's website.
WITH mail AS (
SELECT
parid,
taxyr,
NULLIF(
REGEXP_REPLACE(CONCAT_WS(' ', mail1, mail2), '\s+', ' '), ''
) AS mail_address_name,
NULLIF(
REGEXP_REPLACE(CONCAT_WS(' ', maddr1, maddr2), '\s+', ' '), ''
) AS mail_address_full,
mcityname AS mail_address_city_name,
mstatecode AS mail_address_state,
NULLIF(mzip1, '00000') AS mail_address_zipcode_1,
NULLIF(mzip2, '0000') AS mail_address_zipcode_2,
mailseq = MAX(mailseq) OVER (PARTITION BY parid, taxyr) AS newest
FROM {{ source('iasworld', 'maildat') }}
WHERE cur = 'Y'
AND deactivat IS NULL
)

SELECT
-- Main PIN-level attribute data from iasWorld
par.parid AS pin,
Expand Down Expand Up @@ -29,11 +55,11 @@ SELECT
NULLIF(leg.zip1, '00000') AS prop_address_zipcode_1,
NULLIF(leg.zip2, '0000') AS prop_address_zipcode_2,

-- PIN mailing address from OWNDAT
-- PIN owner address from OWNDAT
NULLIF(CONCAT_WS(
' ',
own.own1, own.own2
), '') AS mail_address_name,
), '') AS owner_address_name,
CASE WHEN NULLIF(own.addr1, '') IS NOT NULL THEN own.addr1
WHEN NULLIF(own.addr2, '') IS NOT NULL THEN own.addr2
ELSE NULLIF(CONCAT_WS(
Expand All @@ -42,11 +68,19 @@ SELECT
own.adrdir, own.adrstr, own.adrsuf,
own.unitdesc, own.unitno
), '')
END AS mail_address_full,
own.cityname AS mail_address_city_name,
own.statecode AS mail_address_state,
NULLIF(own.zip1, '00000') AS mail_address_zipcode_1,
NULLIF(own.zip2, '0000') AS mail_address_zipcode_2
END AS owner_address_full,
own.cityname AS owner_address_city_name,
own.statecode AS owner_address_state,
NULLIF(own.zip1, '00000') AS owner_address_zipcode_1,
NULLIF(own.zip2, '0000') AS owner_address_zipcode_2,

-- PIN mailing address from MAILDAT
mail.mail_address_name,
mail.mail_address_full,
mail.mail_address_city_name,
mail.mail_address_state,
mail.mail_address_zipcode_1,
mail.mail_address_zipcode_2

FROM {{ source('iasworld', 'pardat') }} AS par
LEFT JOIN {{ source('iasworld', 'legdat') }} AS leg
Expand All @@ -59,6 +93,10 @@ LEFT JOIN {{ source('iasworld', 'owndat') }} AS own
AND par.taxyr = own.taxyr
AND own.cur = 'Y'
AND own.deactivat IS NULL
LEFT JOIN mail
ON par.parid = mail.parid
AND par.taxyr = mail.taxyr
AND mail.newest
WHERE par.cur = 'Y'
AND par.deactivat IS NULL
-- Remove any parcels with non-numeric characters
Expand Down
12 changes: 12 additions & 0 deletions dbt/models/default/schema/default.vw_pin_address.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ models:
description: '{{ doc("shared_column_mail_address_zipcode_1") }}'
- name: mail_address_zipcode_2
description: '{{ doc("shared_column_mail_address_zipcode_2") }}'
- name: owner_address_city_name
description: '{{ doc("shared_column_owner_address_city_name") }}'
- name: owner_address_full
description: '{{ doc("shared_column_owner_address_full") }}'
- name: owner_address_name
description: '{{ doc("shared_column_owner_address_name") }}'
- name: owner_address_state
description: '{{ doc("shared_column_owner_address_state") }}'
- name: owner_address_zipcode_1
description: '{{ doc("shared_column_owner_address_zipcode_1") }}'
- name: owner_address_zipcode_2
description: '{{ doc("shared_column_owner_address_zipcode_2") }}'
- name: pin
description: '{{ doc("shared_column_pin") }}'
- name: pin10
Expand Down
23 changes: 22 additions & 1 deletion dbt/models/iasworld/columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,12 @@ Owner 2 suffix
Owner number
{% enddocs %}

## ownseq

{% docs column_ownseq %}
Owner sequence number
{% enddocs %}

## page

{% docs column_page %}
Expand Down Expand Up @@ -836,7 +842,10 @@ Split/combination tracking number
## ssn

{% docs column_ssn %}
Social security number
Social security number.

The CCAO Data Team does not store sensitive data in our data lake, so this
field is always null.
{% enddocs %}

## ssn2
Expand All @@ -851,6 +860,12 @@ Social security number 2
State or province (2 digit)
{% enddocs %}

## stateid

{% docs column_stateid %}
State tax ID number
{% enddocs %}

## status

{% docs column_status %}
Expand Down Expand Up @@ -983,6 +998,12 @@ Sketch vector notes
Calculation table version
{% enddocs %}

## vldrsc

{% docs column_vldrsc %}
No validation reason code
{% enddocs %}

## wallhgt

{% docs column_wallhgt %}
Expand Down
15 changes: 15 additions & 0 deletions dbt/models/iasworld/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,19 @@ Neighborhood parameter table for calp, valuation models, etc.
**Primary Key**: `jur`, `ver`, `nbhd`
{% enddocs %}

# maildat

{% docs table_maildat %}
Taxpayer information such as name and mailing address.

### Nuance

- Taxpayer mailing addresses are not necessarily the same as property owner
mailing addresses. For property owner addresses, see `iasworld.owndat`.

**Primary Key**: `jur`, `taxyr`, `parid`
{% enddocs %}

# oby

{% docs table_oby %}
Expand All @@ -296,6 +309,8 @@ Property owner information such as name and mailing address.
### Nuance

- Mailing addresses and owner names have not been regularly updated since 2017.
- Property owner mailing addresses are not necessarily the same as taxpayer
mailing addresses. For taxpayer addresses, see `iasworld.maildat`.

**Primary Key**: `jur`, `taxyr`, `parid`
{% enddocs %}
Expand Down
2 changes: 1 addition & 1 deletion dbt/models/iasworld/schema/iasworld.cname.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ sources:
- name: upd_status
description: '{{ doc("column_upd_status") }}'
- name: vldrsc
description: No validation reason code
description: '{{ doc("column_vldrsc") }}'
- name: wen
description: '{{ doc("shared_column_updated_at") }}'
- name: who
Expand Down
Loading
Loading