Skip to content

Conversation

yxu-lanl
Copy link
Collaborator

@yxu-lanl yxu-lanl commented Aug 5, 2025

Closes microbiomedata/issues#1134

The problem is in Biosample query ORDER BY clause (order_by(desc(self.table.model.multiomics))). The 'multiomics' is not a unique column.

Solution:
Order by a unique column or a combination of columns that guarantees uniqueness.

Not sure ordering by name is better?
order_by(self.table.model.name, self.table.model.id)

@yxu-lanl yxu-lanl requested review from naglepuff and marySalvi August 5, 2025 20:35
@naglepuff
Copy link
Collaborator

Great catch! Thanks for taking this on.

I'm wondering if its valuable to preserve grouping biosamples by their data types (multiomics column). What if we sorted first by multiomics, and then something unique, like name or id? Maybe @aclum can weigh in on this.

@aclum
Copy link
Contributor

aclum commented Aug 6, 2025

I thought we were previously sorting on completed workflow results?

@naglepuff
Copy link
Collaborator

I thought we were previously sorting on completed workflow results?

I think that's what the multiomics column represents. Its a bitmap where each bit is a data type, so we set the corresponding bit to 1 if the biosample has workflow results for that data type. The precedence can be gleaned from looking at the bitmap definition.

@yxu-lanl
Copy link
Collaborator Author

yxu-lanl commented Aug 7, 2025

The name is not unique. Will use id.
.order_by(self.table.model.multiomics.desc(), self.table.model.id) # type: ignore

nmdc_a=# select count(*) from biosample;
count

13248
(1 row)

nmdc_a=# select count(DISTINCT name) from biosample;
count

13049
(1 row)

nmdc_a=# select count(DISTINCT (multiomics, name)) from biosample;
count

13051
(1 row)

@yxu-lanl
Copy link
Collaborator Author

yxu-lanl commented Aug 8, 2025

@naglepuff Could you approve this PR? Thanks.

@yxu-lanl yxu-lanl merged commit 5b97a8d into main Aug 11, 2025
2 checks passed
@yxu-lanl yxu-lanl deleted the 1134-sample-list-issue branch August 11, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Sample appearing twice in portal list
3 participants