From dcfb8e0ad2625edf0546d7f346fe00697853ff4b Mon Sep 17 00:00:00 2001 From: Jona Date: Tue, 7 Nov 2023 21:03:19 -0500 Subject: [PATCH 1/2] First pass slick_plus extension to sources --- .../3736e85bc273_add_exposed_funcs.py | 24 ++++++++++++++----- alembic/versions/39277f6278f4_add_view.py | 14 ++++++++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/alembic/versions/3736e85bc273_add_exposed_funcs.py b/alembic/versions/3736e85bc273_add_exposed_funcs.py index 7b3c44c8..2a9eef9a 100644 --- a/alembic/versions/3736e85bc273_add_exposed_funcs.py +++ b/alembic/versions/3736e85bc273_add_exposed_funcs.py @@ -67,7 +67,9 @@ def upgrade() -> None: OUT cls_long_name text, OUT aoi_type_1_ids bigint[], OUT aoi_type_2_ids bigint[], - OUT aoi_type_3_ids bigint[] + OUT aoi_type_3_ids bigint[], + OUT source_type_1_ids bigint[], + OUT source_type_2_ids bigint[] ) RETURNS SETOF record LANGUAGE 'sql' @@ -99,7 +101,9 @@ def upgrade() -> None: sp.cls_long_name, sp.aoi_type_1_ids, sp.aoi_type_2_ids, - sp.aoi_type_3_ids + sp.aoi_type_3_ids, + sp.source_type_1_ids, + sp.source_type_2_ids FROM public.slick_plus sp LEFT JOIN slick_to_source sts ON sts.slick = sp.id AND source_id != 'NULL' LEFT JOIN slick_to_aoi sta ON sta.slick = sp.id AND aoi_id != 'NULL' @@ -137,7 +141,9 @@ def upgrade() -> None: OUT cls_long_name text, OUT aoi_type_1_ids bigint[], OUT aoi_type_2_ids bigint[], - OUT aoi_type_3_ids bigint[] + OUT aoi_type_3_ids bigint[], + OUT source_type_1_ids bigint[], + OUT source_type_2_ids bigint[] ) RETURNS SETOF record LANGUAGE 'sql' @@ -169,7 +175,9 @@ def upgrade() -> None: sp.cls_long_name, sp.aoi_type_1_ids, sp.aoi_type_2_ids, - sp.aoi_type_3_ids + sp.aoi_type_3_ids, + sp.source_type_1_ids, + sp.source_type_2_ids FROM public.slick_plus sp JOIN slick_to_source sts ON sts.slick = sp.id WHERE sts.source = ANY(string_to_array(source_id, ',')::int[]) @@ -205,7 +213,9 @@ def upgrade() -> None: OUT cls_long_name text, OUT aoi_type_1_ids bigint[], OUT aoi_type_2_ids bigint[], - OUT aoi_type_3_ids bigint[] + OUT aoi_type_3_ids bigint[], + OUT source_type_1_ids bigint[], + OUT source_type_2_ids bigint[] ) RETURNS SETOF record LANGUAGE 'sql' @@ -237,7 +247,9 @@ def upgrade() -> None: sp.cls_long_name, sp.aoi_type_1_ids, sp.aoi_type_2_ids, - sp.aoi_type_3_ids + sp.aoi_type_3_ids, + sp.source_type_1_ids, + sp.source_type_2_ids FROM public.slick_plus sp JOIN slick_to_aoi sta ON sta.slick = sp.id WHERE sta.aoi = ANY(string_to_array(aoi_id, ',')::int[]); diff --git a/alembic/versions/39277f6278f4_add_view.py b/alembic/versions/39277f6278f4_add_view.py index c6547757..c30f49f9 100644 --- a/alembic/versions/39277f6278f4_add_view.py +++ b/alembic/versions/39277f6278f4_add_view.py @@ -31,12 +31,14 @@ def upgrade() -> None: cls.long_name AS cls_long_name, aoi_agg.aoi_type_1_ids, aoi_agg.aoi_type_2_ids, - aoi_agg.aoi_type_3_ids + aoi_agg.aoi_type_3_ids, + source_agg.source_type_1_ids, + source_agg.source_type_2_ids FROM slick JOIN orchestrator_run ON orchestrator_run.id = slick.orchestrator_run JOIN sentinel1_grd ON sentinel1_grd.id = orchestrator_run.sentinel1_grd JOIN cls ON cls.id = slick.cls - JOIN ( + LEFT JOIN ( SELECT slick_to_aoi.slick, array_agg(aoi.id) FILTER (WHERE aoi.type = 1) AS aoi_type_1_ids, array_agg(aoi.id) FILTER (WHERE aoi.type = 2) AS aoi_type_2_ids, @@ -44,7 +46,13 @@ def upgrade() -> None: FROM slick_to_aoi JOIN aoi ON slick_to_aoi.aoi = aoi.id GROUP BY slick_to_aoi.slick - ) aoi_agg ON aoi_agg.slick = slick.id; + ) aoi_agg ON aoi_agg.slick = slick.id + LEFT JOIN ( SELECT slick_to_source.slick, + array_agg(source.id) FILTER (WHERE source.type = 1) AS source_type_1_ids, + array_agg(source.id) FILTER (WHERE source.type = 2) AS source_type_2_ids + FROM slick_to_source + JOIN source ON slick_to_source.source = source.id + GROUP BY slick_to_source.slick) source_agg ON source_agg.slick = slick.id; """, ) op.create_entity(slick_plus) From f30bdfefaa637144a3d664fded78f015a5b38ac6 Mon Sep 17 00:00:00 2001 From: Jona Date: Tue, 7 Nov 2023 22:24:06 -0500 Subject: [PATCH 2/2] Fix typo --- alembic/versions/7cd715196b8d_add_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alembic/versions/7cd715196b8d_add_index.py b/alembic/versions/7cd715196b8d_add_index.py index 7944a8ca..2e394bd8 100644 --- a/alembic/versions/7cd715196b8d_add_index.py +++ b/alembic/versions/7cd715196b8d_add_index.py @@ -70,8 +70,8 @@ def downgrade() -> None: op.drop_index("idx_orchestrator_run_git_hash", "orchestrator_run") op.drop_index("idx_orchestrator_run_sentinel1_grd", "orchestrator_run") - op.drop_index("idx_slick_to_aoi_aoi", "source") - op.drop_index("idx_slick_to_aoi_slick", "source") + op.drop_index("idx_slick_to_aoi_aoi", "slick_to_aoi") + op.drop_index("idx_slick_to_aoi_slick", "slick_to_aoi") op.drop_index("idx_source_name", "source")