Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.16] Fix calc_dataset_view join with label values #2219

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,6 @@ public void recalculateDatasets(int testId) {
RecalculationStatus status = new RecalculationStatus(RunDAO.count("testid = ?1 AND trashed = false", testId));
// we don't have to care about races with new runs
RecalculationStatus prev = recalculations.putIfAbsent(testId, status);
// ensure the recalculation is removed, with this approach we should guarantee
// it gets removed even if transaction-level exception occurs, e.g., timeout
Util.registerTxSynchronization(tm, txStatus -> recalculations.remove(testId, status));
if (prev != null) {
log.infof("Recalculation for test %d (%s) already in progress", testId, test.name);
return;
Expand All @@ -652,7 +649,8 @@ public void recalculateDatasets(int testId) {
log.debugf("Deleted %d datasets for trashed runs in test %s (%d)", deleted, test.name, (Object) testId);
}

try (ScrollableResults results = em
log.infof("Recalculating datasets for test %d (%s)", testId, test.name);
try (ScrollableResults<Integer> results = em
.createNativeQuery("SELECT id FROM run WHERE testid = ?1 AND NOT trashed ORDER BY start")
.setParameter(1, testId)
.unwrap(NativeQuery.class).setReadOnly(true).setFetchSize(100)
Expand Down
23 changes: 23 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,27 @@
<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
AND vc.view_id IN (SELECT view.id FROM view JOIN dataset ON view.test_id = dataset.testid WHERE 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>
Loading