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

feat(queries)!: Query projections #5242

Merged
merged 9 commits into from
Nov 27, 2024

Conversation

DCNick3
Copy link
Contributor

@DCNick3 DCNick3 commented Nov 18, 2024

Context

Closes #5063. Helps to continue #4933.

Some of the singular queries are there to select a small sub-object (like FindXxxMetadata queries). A solution is needed for the iterable queries to do the same.

Solution

A projection system, which allows one to query a sub-object (or multiple sub-objects) of the query. This is done by sending a query selector along with the predicate.

Changes

  • Predicates are now split into atomic predicates and projections
  • The projections are shared with the selectors. The accept a Marker type parameter to determine which kind of object they should store inside
  • more macros (than in older predicates impl), should be easier to modify the data model. The predicates, prototypes and projections are now all in one place too.
  • Ast predicates are removed, prototype helper methods now return CompoundPredicates directly
  • CompoundPredicate's generic now accepts the predicated type and not the predicate type itself
  • Some prototype fields were renamed to be in line with the names in the data model

Migration Guide

  • Other than some odd renames, regular rust SDK code should not be affected
  • The SDKs will require updates for the refactored predicates

Review notes

As with #4833, I tried documenting the system as a whole in iroha_data_model::query::dsl module documentation, so this might be a good place to start to understand the system.

An example use of the API can be found in the smart_contract_can_filter_queries integration test.

Each of the commit represents a logical step towards implementing the new query system. I ensured the tests would pass between those. This might make it easier to review the commits separately than in one big clump.

Checklist

  • I've read CONTRIBUTING.md.
  • I've written unit tests for the code changes.
  • All review comments have been resolved.
  • All CI checks pass.
  • Fix pytests

@github-actions github-actions bot added the api-changes Changes in the API for client libraries label Nov 18, 2024
@DCNick3 DCNick3 self-assigned this Nov 18, 2024
@DCNick3 DCNick3 added Enhancement New feature or request queries labels Nov 18, 2024
@s8sato s8sato self-assigned this Nov 19, 2024
@0x009922 0x009922 self-assigned this Nov 19, 2024
Copy link
Contributor

@s8sato s8sato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insightful and well-planned work. Very little to comment on

crates/iroha_data_model/src/query/dsl/mod.rs Outdated Show resolved Hide resolved
crates/iroha_data_model/src/query/dsl/mod.rs Outdated Show resolved Hide resolved
docs/source/references/schema.json Outdated Show resolved Hide resolved
This is done in preparation of landing query, projections, which will share some of the types with the predicates.

The API is mostly the same, with some fields in prototypes being renamed to mirror the actual data types

Signed-off-by: ⭐️NINIKA⭐️ <[email protected]>
For now iroha only produces 1-tuples, but the client code can already receive actual tuples and downcast them into iterators over typed tuples

Signed-off-by: ⭐️NINIKA⭐️ <[email protected]>
This will let the user select (possibly multiple) projections of the object being queried. The selectors are ignored for now though

Signed-off-by: ⭐️NINIKA⭐️ <[email protected]>
Signed-off-by: ⭐️NINIKA⭐️ <[email protected]>
This is more natural for humans than the columnar format iroha uses in transit

Signed-off-by: ⭐️NINIKA⭐️ <[email protected]>
Copy link
Contributor

@mversic mversic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incredibly powerful stuff. Great API design.

crates/iroha_schema/src/lib.rs Show resolved Hide resolved
@mversic mversic merged commit 485ef91 into hyperledger-iroha:main Nov 27, 2024
16 checks passed
@s8sato s8sato mentioned this pull request Nov 27, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-changes Changes in the API for client libraries Enhancement New feature or request queries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement query projections
5 participants