Skip to content

Tools for joining Query objects #1658

Closed
@alice-i-cecile

Description

What problem does this solve or what need does it fill?

As users attempt to filter their data more finely in more complex applications, they may need to combine data from multiple queries in order to get precisely the data they need.

In the simple cases, adding more parameters and types to your query is the correct choice. But this fails when:

  1. You need the data from the queries separately as well.
  2. You want to express more complex compound queries, like "has component A or component B in this particular slot"

What solution would you like?

The standard relational database tools and/or set operations should be added, providing a set of (Query, Query) -> Query functions or methods.

The tools provided by Option<C> components already should be a heavy inspiration for the implementation and handling of the possibly ragged tables produced.

What alternative(s) have you considered?

We could provide for this behavior at the type level (see Or and the proposed Not query filters from #1471), allowing you to merge queries in complicated ways using the type system. This is less flexible and results in extremely complicated nested types, but does in theory mean we can restrict the data faster.

As a workaround, you could extract the list of entities in each query, perform the set operations on those entity lists, and then use query.get to extract the desired entities and data from each query separately.

Additional context

This came up in the context of #1627 with @BoxyUwU, discussing how to search for entities that have two parents. We can't sensibly have two Relation<ChildOf> types in the type parameter of a single Query argument without a great deal of API complication, but looking for intersections etc. of the same relation across multiple entities is a sensible and common operation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    • Status

      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions