AtlasOfLivingAustralia / specieslist-webapp

Species lists and traits tool
https://lists.ala.org.au
Mozilla Public License 2.0
6 stars 21 forks source link

Issues with query on a species with max param #271

Closed qifeng-bai closed 1 year ago

qifeng-bai commented 1 year ago

The data structure of a species is like: species (1 : 1) data resource , (1 : ) -> lists , (1 : ) kv pairs.

Error reproduce: Here is an example: https://lists-test.ala.org.au//ws/species/https://biodiversity.org.au/afd/taxa/76f4ad27-475e-4a93-bc61-3fbe2a896283

It returns 3 records, each record has a unique data resource id, and with an array of lists, an array of KV pairs

However, after we added max=2 https://lists-test.ala.org.au//ws/species/https://biodiversity.org.au/afd/taxa/76f4ad27-475e-4a93-bc61-3fbe2a896283?max=2

We expected it returns 2 records, each record should contain a full set of lists and KV pairs

However, this query only returns the first one record with two KV pairs

Possible Reason: The way of current query returns, for example:

a species A  is from 2 data resources, dr1 and dr2.   
dr1 has 3 KV pairs, K1-V1, K2-V2, K3-V3. 
dr2 has 1 KV pairs k21-V21.

The results returned from Hibernate are:

dr1, A, K1-V1
dr1, A, K2-V2
dr1, A, K3-V3
dr2, A, K21-V21

and then a hibernate transformer is applied to the results.

setResultTransformer(org.hibernate.criterion.CriteriaSpecification.DISTINCT_ROOT_ENTITY)

This result transformer will reconstruct the results to

dr1 -> A -> [K1-V1, K2-V2, K3-V3]
dr2 -> A -> [K21-V21]

So when we apply max=2 to the query, only two records will be returned from hibernate:

dr1, A, K1-V1
dr1, A,  K2-V2

And eventually transformed to dr1 -> A -> [K1-V1, K2-V2]

The data resource dr2 will not be returned to the user

And I also think this transform process may cause some performance issue

qifeng-bai commented 1 year ago

PR: https://github.com/AtlasOfLivingAustralia/specieslist-webapp/pull/272