nlextract / NLExtract

Convert (ETL) and visualize free Dutch geo-datasets.
https://nlextract.nl
GNU General Public License v3.0
149 stars 84 forks source link

BGT SQL scripts: plaats BEGIN..COMMIT om geheugenproblemen te voorkomen. #356

Closed justb4 closed 8 months ago

justb4 commented 8 months ago

In sommige contexten kunnen SQL scripts uit de BGT ETL door een memory/disk shortage probleem afgebroken worden. Net als de BAGv2 adres-plus SQL lijkt het beter om BEGIN..COMMIT rond eenheden van werk te plaatsen. Met name in de postprocessing scripts: create-final-tables-v2.1.1.sql en fix-eindregistratie.sql. Dus bijv

BEGIN;
-- Bak
select _nlx_renamecolumn('bak_tmp', 'wkb_geometry', 'geometrie_punt');

drop table if exists bak cascade;
create table bak as select ogc_fid, geometrie_punt, gml_id, namespace, lokaalid, cast(objectbegintijd as date), cast(objecteindtijd as date), cast(tijdstipregistratie as timestamptz), cast(eindregistratie as timestamptz), cast(lv_publicatiedatum as timestamptz), bronhouder, cast(inonderzoek as boolean), relatievehoogteligging, bgt_status, plus_status, bgt_type, plus_type from bak_tmp;

alter table bak add primary key (ogc_fid);
alter table bak alter column gml_id set not null;
create index bak_geometrie_punt_geom_idx on bak using gist((geometrie_punt::geometry(POINT, 28992)));
create index bak_eindregistratie_idx on bak (eindregistratie);
create index bak_bgt_status_idx on bak (bgt_status);
create index bak_plus_status_idx on bak (plus_status);

create or replace view bakactueel as select * from bak where eindregistratie is null;
create or replace view bakactueelbestaand as select * from bak where eindregistratie is null and bgt_status = 'bestaand' and plus_status <> 'plan' and plus_status <> 'historie';

drop table bak_tmp;
COMMIT;

BEGIN;
-- Begroeid terreindeel
drop table if exists begroeidterreindeel cascade;
create table begroeidterreindeel as select ogc_fid, geometrie_vlak, geometrie_kruinlijn, gml_id, namespace, lokaalid, cast(objectbegintijd as date), cast(objecteindtijd as date), cast(tijdstipregistratie as timestamptz), cast(eindregistratie as timestamptz), cast(lv_publicatiedatum as timestamptz), bronhouder, cast(inonderzoek as boolean), relatievehoogteligging, bgt_status, plus_status, bgt_fysiekvoorkomen, plus_fysiekvoorkomen, cast(begroeidterreindeeloptalud as boolean) from begroeidterreindeel_tmp;

.
.
etc
justb4 commented 8 months ago

BEGIN..COMMIT in files added and tested ok with full BGT ETL.