Skip to content

Commit

Permalink
Fix calc_dataset_view join with label values
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Lamparelli <[email protected]>
  • Loading branch information
lampajr committed Dec 5, 2024
1 parent 41c1fa5 commit 274d003
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions horreum-backend/src/main/resources/db/changeLog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4665,4 +4665,26 @@
<dropColumn tableName="schema" columnName="token" />
<dropTable tableName="test_token" />
</changeSet>
<changeSet id="125" author="lampajr">
<validCheckSum>ANY</validCheckSum>
<sql>
-- still need db procedure until https://hibernate.atlassian.net/browse/HHH-17314 is fixed in quarkus
CREATE OR REPLACE PROCEDURE calc_dataset_view(datasetId bigint) AS $$
BEGIN
WITH view_agg AS (
SELECT
vc.view_id, vc.id as vcid, array_agg(DISTINCT label.id) as label_ids, jsonb_object_agg(label.name, lv.value) as value FROM dataset_schemas ds
JOIN label ON label.schema_id = ds.schema_id
JOIN viewcomponent vc ON vc.labels ? label.name
JOIN label_values lv ON lv.label_id = label.id AND lv.dataset_id = ds.dataset_id
WHERE ds.dataset_id = datasetId
GROUP BY vc.view_id, vcid
)
INSERT INTO dataset_view (dataset_id, view_id, label_ids, value)
SELECT datasetId, view_id, array_agg(DISTINCT label_id), jsonb_object_agg(vcid, value) FROM view_agg, unnest(label_ids) as label_id
GROUP BY view_id;
END
$$ LANGUAGE plpgsql;
</sql>
</changeSet>
</databaseChangeLog>

0 comments on commit 274d003

Please sign in to comment.