Skip to content

Commit 447821a

Browse files
committed
Amend sql queries to only include ke columns and rows
1 parent 803c3be commit 447821a

File tree

1 file changed

+75
-3
lines changed

1 file changed

+75
-3
lines changed

scripts/helpers/housing_gx_dq_inputs.py

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,88 @@
66
'sql': """SELECT * FROM "housing-refined-zone"."tenure_reshape" where import_date=(select max(import_date) from "housing-refined-zone"."tenure_reshape") and description in ('Secure', 'Introductory', 'Mesne Profit Ac', 'Non-Secure') and (endoftenuredate is null or substr(endoftenuredate, 1, 11) = '1900-01-01')""",
77
'id_field': 'tenancy_id'},
88
'contacts_reshape': {
9-
'sql': """SELECT id, targetid, substr(createdat, 1, 10) as createdat, contacttype, subtype, value, substr(lastmodified, 1, 10) as lastmodified, targettype, isactive, person_id, import_date FROM "housing-refined-zone"."contacts_reshape" where import_date=(select max(import_date) from "housing-refined-zone"."contacts_reshape") and isactive=True""",
9+
'sql': """SELECT
10+
DATE_FORMAT(from_iso8601_timestamp(createdat), '%Y-%b-%d') AS createdat,
11+
contacttype,
12+
subtype,
13+
cast(value as varchar) as contact_value,
14+
DATE_FORMAT(from_iso8601_timestamp(lastmodified), '%Y-%b-%d') AS lastmodified,
15+
targettype,
16+
person_id,
17+
import_year,
18+
import_month,
19+
import_day,
20+
import_date
21+
FROM "housing-refined-zone"."contacts_reshape"
22+
where targettype = 'person'
23+
and import_date = (select max(import_date) from "housing-refined-zone"."contacts_reshape")""",
1024
'id_field': 'id'},
1125
'housing_homeowner_record_sheet': {
1226
'sql': """SELECT * FROM "housing-raw-zone"."housing_homeowner_record_sheet" where import_date=(select max(import_date) from "housing-raw-zone"."housing_homeowner_record_sheet")""",
1327
'id_field': 'property_no'},
1428
'housing_dwellings_list': {
15-
'sql': """SELECT * FROM "housing-raw-zone"."housing_dwellings_list" where import_date=(select max(import_date) from "housing-raw-zone"."housing_homeowner_record_sheet")""",
29+
'sql': """SELECT
30+
cast(property_dwelling_reference_number as varchar) as property_dwelling_reference_number,
31+
cast(llpg as varchar) as llpg,
32+
cast(estate_reference_number as varchar) as estate_reference_number,
33+
estate_name,
34+
block_name_as_per_naming_convention_procedure as block_name,
35+
cast(block_reference_number as varchar) as block_reference_number,
36+
sub_block_name,
37+
cast(sub_block_reference as varchar) as sub_block_reference,
38+
block_total_stories,
39+
block_typology_based_on_dwelling_type_defined_list as block_typology,
40+
building_heights_h1,
41+
communal_heat_network,
42+
dwelling_front_door_access_floor_level,
43+
dwelling_no_of_bedrooms,
44+
fra_block,
45+
no_of_floors_within_dwelling,
46+
registered_building,
47+
year_built_block
48+
FROM "housing-raw-zone"."housing_dwellings_list" where import_date = (select max(import_date) from "housing-raw-zone"."housing_dwellings_list")""",
1649
'id_field': 'property_dwelling_reference_number'},
1750
'assets_reshape': {
18-
'sql': """SELECT * FROM "housing-refined-zone"."assets_reshape" where import_date=(select max(import_date) from "housing-refined-zone"."assets_reshape") and assettype = 'Dwelling'""",
51+
'sql': """select
52+
cast(assetid as varchar) as assetid,
53+
assettype,
54+
cast(uprn as varchar) as uprn,
55+
owner as property_owner,
56+
agent,
57+
iscouncilproperty,
58+
istmomanaged,
59+
managingorganisation,
60+
cast(managingorganisationid as varchar) as managingorganisationid,
61+
totalblockfloors,
62+
floorno,
63+
numberoflifts,
64+
numberoflivingrooms,
65+
numberofkitchens,
66+
numberofbedrooms,
67+
numberofbedspaces,
68+
numberofshowers,
69+
numberoffloors,
70+
numberofdoublebeds,
71+
numberofsinglebeds,
72+
numberofbathrooms,
73+
yearconstructed,
74+
hascommunalareas,
75+
hasprivatekitchen,
76+
hasprivatebathroom,
77+
hasrampaccess,
78+
isstepfree,
79+
hasstairs,
80+
heating,
81+
numberofcots,
82+
windowtype,
83+
estate_name,
84+
cast(estate_id as varchar) as estate_id,
85+
import_year,
86+
import_month,
87+
import_day,
88+
import_date
89+
FROM "housing-refined-zone"."assets_reshape" where import_date = (select max(import_date) from "housing-refined-zone"."assets_reshape")
90+
and assettype in ('BoilerHouse','BoosterPump','CleanersFacilities','CombinedHeatAndPowerUnit','CommunityHall','Concierge','Dwelling','LettableNonDwelling','Lift','NA','NBD','OutBuilding','TravellerSite')""",
1991
'id_field': 'asset_id'},
2092
'matenancyagreement': {
2193
'sql': """SELECT *, substr(cast(eot as varchar), 1, 10) as eot_parsed, substr(cast(cot as varchar), 1, 10) as cot_parsed FROM "housing-raw-zone"."sow2b_dbo_matenancyagreement" where import_date=(select max(import_date) FROM "housing-raw-zone"."sow2b_dbo_matenancyagreement")""",

0 commit comments

Comments
 (0)