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

Add support for multiple trees in the query builder #4979

Closed
Tracked by #4833
grantfitzsimmons opened this issue Jun 3, 2024 · 0 comments · Fixed by #5036 · May be fixed by #5251
Closed
Tracked by #4833

Add support for multiple trees in the query builder #4979

grantfitzsimmons opened this issue Jun 3, 2024 · 0 comments · Fixed by #5036 · May be fixed by #5251
Assignees
Labels
1 - Request Improvements or extensions to existing behavior 2 - Queries Issues that are related to the query builder or queries in general 2 - Trees Issues that are related to the tree system and related functionalities.
Milestone

Comments

@grantfitzsimmons
Copy link
Member

Component of #4833

From @realVinayak:

regarding query builder backend, this can be very simply (and naively) accomplished by passing the object type and getting the appropriate treedef here:

treedef = get_treedef(query.collection, table.name)

Figure out why it will "just work". the above assumes that defitems cannot be shared (like same rank ITSELF wouldn't appear in two trees). Like if Kingdom is treedefitemid=1 in one treedef, it is also not treedefitemid=1 in another treedef. basically, how the trees in specify works currently (so no worries I believe)

BUT, I think that'll be inefficient. You can make it considerably more efficient (think why the above isn't) very simply, by including the objecttype equality to the join criterion (well, technically just the first node, but you get the point)
(

query = query.outerjoin(ancestor, ancestors[-1].ParentID == getattr(ancestor, ancestor._id))
)

^ofc that's for querying a specific tree. querying all trees at once is simpler (but I guess you can't say (any tree) -> species), like you could have (Fossil) -> species)

theoretically, doing something like (any tree) -> species is also straightforward (will think about perf impact). you could have an OR condition here (look up all treedefitemids which have species, put them in the OR below

treedefitem_param = sql.bindparam('tdi_%s' % query.param_count, value=treedef.treedefitems.get(name=tree_rank).id)

@grantfitzsimmons grantfitzsimmons added 1 - Request Improvements or extensions to existing behavior 2 - Queries Issues that are related to the query builder or queries in general 2 - Trees Issues that are related to the tree system and related functionalities. labels Jun 3, 2024
@CarolineDenis CarolineDenis added this to the 7.9.7 milestone Jun 17, 2024
@CarolineDenis CarolineDenis self-assigned this Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - Request Improvements or extensions to existing behavior 2 - Queries Issues that are related to the query builder or queries in general 2 - Trees Issues that are related to the tree system and related functionalities.
Projects
None yet
2 participants