Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.

Commit a4f2638

Browse files
committed
[build] improve dataloading and not dropping tables during build
1 parent 2a2f95c commit a4f2638

File tree

3 files changed

+72
-80
lines changed

3 files changed

+72
-80
lines changed

pluto_build/01_dataloading.sh

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -56,77 +56,7 @@ import dof_condo
5656
wait
5757

5858
## Load local CSV files
59-
psql $BUILD_ENGINE -c "
60-
DROP TABLE IF EXISTS pluto_input_research;
61-
CREATE TABLE pluto_input_research (
62-
bbl text,
63-
field text,
64-
old_value text,
65-
new_value text,
66-
Type text,
67-
reason text,
68-
version text
69-
);
70-
71-
DROP TABLE IF EXISTS pluto_input_landuse_bldgclass;
72-
CREATE TABLE pluto_input_landuse_bldgclass (
73-
bldgclass text,
74-
landuse text,
75-
landusevalue text
76-
);
77-
78-
DROP TABLE IF EXISTS pluto_input_condolot_descriptiveattributes;
79-
CREATE TABLE pluto_input_condolot_descriptiveattributes (
80-
CondNO text,
81-
Boro text,
82-
PARID text,
83-
BC text,
84-
TC text,
85-
LandSize text,
86-
Story text,
87-
YearBuilt text
88-
);
89-
90-
DROP TABLE IF EXISTS pluto_input_condo_bldgclass;
91-
CREATE TABLE pluto_input_condo_bldgclass (
92-
code character varying,
93-
description character varying,
94-
type character varying,
95-
dcpcreated character varying,
96-
logic character varying
97-
);
98-
99-
DROP TABLE IF EXISTS pluto_input_bsmtcode;
100-
CREATE TABLE pluto_input_bsmtcode (
101-
bsmnt_type character varying,
102-
bsmntgradient character varying,
103-
bsmtcode character varying,
104-
bsmnt_typevalue character varying,
105-
bsmntgradientvalue character varying,
106-
bsmtcodevalue character varying
107-
);
108-
109-
DROP TABLE IF EXISTS dcp_zoning_maxfar;
110-
CREATE TABLE dcp_zoning_maxfar (
111-
zonedist character varying,
112-
contextual character varying,
113-
zoningdistricttype character varying,
114-
residfar character varying,
115-
facilfar character varying,
116-
commfar character varying,
117-
mnffar character varying,
118-
column1 character varying,
119-
verified character varying,
120-
extra character varying
121-
)
122-
"
123-
124-
imports_csv pluto_input_research &
125-
imports_csv pluto_input_landuse_bldgclass &
126-
imports_csv pluto_input_condolot_descriptiveattributes &
127-
imports_csv pluto_input_condo_bldgclass &
128-
imports_csv pluto_input_bsmtcode &
129-
imports_csv dcp_zoning_maxfar
59+
psql $BUILD_ENGINE -f sql/_create.sql
13060

13161
# Create data version table
132-
psql $BUILD_ENGINE -f sql/source_data_versions.sql
62+
psql $BUILD_ENGINE -f sql/source_data_versions.sql

pluto_build/02_build.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ source bin/config.sh
44
echo "Starting to build PLUTO ..."
55
psql $BUILD_ENGINE -f sql/preprocessing.sql
66
psql $BUILD_ENGINE -f sql/pts_clean.sql
7-
psql $BUILD_ENGINE -c "DROP TABLE pluto_pts;"
87
psql $BUILD_ENGINE -f sql/create_rpad_geo.sql
98

109
echo 'Reporting records that did not get geocoded...'
@@ -36,7 +35,6 @@ psql $BUILD_ENGINE -f sql/condono.sql
3635
echo 'Adding on CAMA data attributes'
3736
psql $BUILD_ENGINE -f sql/landuse.sql
3837
psql $BUILD_ENGINE -f sql/create_cama_primebbl.sql
39-
psql $BUILD_ENGINE -c "DROP TABLE pluto_input_cama_dof;"
4038

4139
psql $BUILD_ENGINE -f sql/cama_bsmttype.sql
4240
psql $BUILD_ENGINE -f sql/cama_lottype.sql
@@ -46,7 +44,6 @@ psql $BUILD_ENGINE -f sql/cama_bldgarea_2.sql
4644
psql $BUILD_ENGINE -f sql/cama_bldgarea_3.sql
4745
psql $BUILD_ENGINE -f sql/cama_bldgarea_4.sql
4846
psql $BUILD_ENGINE -f sql/cama_easements.sql
49-
psql $BUILD_ENGINE -c "DROP TABLE pluto_input_geocodes;"
5047

5148
echo 'Adding on data attributes from other sources'
5249
psql $BUILD_ENGINE -f sql/lpc.sql
@@ -83,7 +80,6 @@ psql $BUILD_ENGINE -f sql/zoning_parks.sql
8380
psql $BUILD_ENGINE -f sql/zoning_correctdups.sql
8481
psql $BUILD_ENGINE -f sql/zoning_correctgaps.sql
8582
psql $BUILD_ENGINE -f sql/zoning_splitzone.sql
86-
psql $BUILD_ENGINE -c "DROP TABLE dof_dtm;"
8783
psql $BUILD_ENGINE -c "VACUUM ANALYZE pluto;"
8884

8985
echo 'Filling in FAR values'
@@ -117,9 +113,5 @@ psql $BUILD_ENGINE -v ON_ERROR_STOP=1 -f sql/plutomapid_1.sql
117113
psql $BUILD_ENGINE -v ON_ERROR_STOP=1 -f sql/plutomapid_2.sql
118114
psql $BUILD_ENGINE -f sql/shorelineclip.sql
119115

120-
# echo 'Backfilling'
121-
# psql $BUILD_ENGINE -v ON_ERROR_STOP=1 -f sql/backfill.sql
122-
# psql $BUILD_ENGINE -c "VACUUM ANALYZE pluto;"
123-
124116
echo 'Done'
125117
exit 0

pluto_build/sql/_create.sql

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
DROP TABLE IF EXISTS pluto_input_research;
2+
CREATE TABLE pluto_input_research (
3+
bbl text,
4+
field text,
5+
old_value text,
6+
new_value text,
7+
type text,
8+
reason text,
9+
version text
10+
);
11+
\COPY pluto_input_research FROM 'data/pluto_input_research.csv' DELIMITER ',' CSV HEADER;
12+
13+
DROP TABLE IF EXISTS pluto_input_landuse_bldgclass;
14+
CREATE TABLE pluto_input_landuse_bldgclass (
15+
bldgclass text,
16+
landuse text,
17+
landusevalue text
18+
);
19+
\COPY pluto_input_landuse_bldgclass FROM 'data/pluto_input_landuse_bldgclass.csv' DELIMITER ',' CSV HEADER;
20+
21+
22+
DROP TABLE IF EXISTS pluto_input_condolot_descriptiveattributes;
23+
CREATE TABLE pluto_input_condolot_descriptiveattributes (
24+
CondNO text,
25+
Boro text,
26+
PARID text,
27+
BC text,
28+
TC text,
29+
LandSize text,
30+
Story text,
31+
YearBuilt text
32+
);
33+
\COPY pluto_input_condolot_descriptiveattributes FROM 'data/pluto_input_condolot_descriptiveattributes.csv' DELIMITER ',' CSV HEADER;
34+
35+
DROP TABLE IF EXISTS pluto_input_condo_bldgclass;
36+
CREATE TABLE pluto_input_condo_bldgclass (
37+
code character varying,
38+
description character varying,
39+
type character varying,
40+
dcpcreated character varying,
41+
logic character varying
42+
);
43+
\COPY pluto_input_condo_bldgclass FROM 'data/pluto_input_condo_bldgclass.csv' DELIMITER ',' CSV HEADER;
44+
45+
DROP TABLE IF EXISTS pluto_input_bsmtcode;
46+
CREATE TABLE pluto_input_bsmtcode (
47+
bsmnt_type character varying,
48+
bsmntgradient character varying,
49+
bsmtcode character varying,
50+
bsmnt_typevalue character varying,
51+
bsmntgradientvalue character varying,
52+
bsmtcodevalue character varying
53+
);
54+
\COPY pluto_input_bsmtcode FROM 'data/pluto_input_bsmtcode.csv' DELIMITER ',' CSV HEADER;
55+
56+
57+
DROP TABLE IF EXISTS dcp_zoning_maxfar;
58+
CREATE TABLE dcp_zoning_maxfar (
59+
zonedist character varying,
60+
contextual character varying,
61+
zoningdistricttype character varying,
62+
residfar character varying,
63+
facilfar character varying,
64+
commfar character varying,
65+
mnffar character varying,
66+
column1 character varying,
67+
verified character varying,
68+
extra character varying
69+
);
70+
\COPY dcp_zoning_maxfar FROM 'data/dcp_zoning_maxfar.csv' DELIMITER ',' CSV HEADER;

0 commit comments

Comments
 (0)