-
Notifications
You must be signed in to change notification settings - Fork 21
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(cognitarium)!: add query expression filters #616
Conversation
WalkthroughThe changes introduce a more flexible and robust query handling system by modifying how Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant QueryEngine
participant PlanBuilder
participant ExpressionEvaluator
User->>QueryEngine: Execute Query with Optional WhereClause
QueryEngine->>PlanBuilder: Build Query Plan
PlanBuilder->>ExpressionEvaluator: Evaluate Expressions
ExpressionEvaluator-->>PlanBuilder: Return Results
PlanBuilder-->>QueryEngine: Return Query Plan
QueryEngine-->>User: Return Query Results
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
Sounds good 👍 |
adopt a more specific naming for the type of clauses and allow to combine multiple ones, simplifying the addition of new ones
2c882ca
to
87b53fa
Compare
87b53fa
to
e179988
Compare
a374a14
to
73df19c
Compare
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Outside diff range, codebase verification and nitpick comments (3)
contracts/axone-cognitarium/src/querier/mod.rs (1)
2-2
: Consider documenting the newexpression
module.The addition of the
expression
module suggests new functionality. Consider adding documentation to clarify its purpose and usage.contracts/axone-cognitarium/src/state/test_util.rs (1)
1-3
: Consider adding documentation forInMemoryNamespaceSolver
.Adding documentation will help clarify the purpose and usage of this in-memory solver for future developers.
contracts/axone-cognitarium/src/msg.rs (1)
469-482
: Enhance documentation forWhereClause
.The
WhereClause
enum now supportsBgp
,LateralJoin
, andFilter
. Ensure that the documentation clearly explains each variant's purpose and usage, especially the newFilter
variant.Consider adding examples to illustrate how each variant can be used in queries.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (17)
- contracts/axone-cognitarium/src/contract.rs (45 hunks)
- contracts/axone-cognitarium/src/msg.rs (4 hunks)
- contracts/axone-cognitarium/src/querier/engine.rs (23 hunks)
- contracts/axone-cognitarium/src/querier/expression.rs (1 hunks)
- contracts/axone-cognitarium/src/querier/mapper.rs (3 hunks)
- contracts/axone-cognitarium/src/querier/mod.rs (1 hunks)
- contracts/axone-cognitarium/src/querier/plan.rs (6 hunks)
- contracts/axone-cognitarium/src/querier/plan_builder.rs (12 hunks)
- contracts/axone-cognitarium/src/querier/variable.rs (7 hunks)
- contracts/axone-cognitarium/src/state/mod.rs (1 hunks)
- contracts/axone-cognitarium/src/state/namespaces.rs (5 hunks)
- contracts/axone-cognitarium/src/state/test_util.rs (1 hunks)
- contracts/axone-cognitarium/src/state/triples.rs (2 hunks)
- contracts/axone-cognitarium/src/storer/engine.rs (2 hunks)
- contracts/axone-dataverse/src/contract.rs (2 hunks)
- contracts/axone-dataverse/src/registrar/registry.rs (2 hunks)
- docs/axone-cognitarium.md (8 hunks)
Additional context used
GitHub Check: codecov/patch
contracts/axone-cognitarium/src/state/test_util.rs
[warning] 35-40: contracts/axone-cognitarium/src/state/test_util.rs#L35-L40
Added lines #L35 - L40 were not covered by testscontracts/axone-cognitarium/src/querier/plan.rs
[warning] 115-118: contracts/axone-cognitarium/src/querier/plan.rs#L115-L118
Added lines #L115 - L118 were not covered by testscontracts/axone-cognitarium/src/state/namespaces.rs
[warning] 220-222: contracts/axone-cognitarium/src/state/namespaces.rs#L220-L222
Added lines #L220 - L222 were not covered by testscontracts/axone-cognitarium/src/querier/engine.rs
[warning] 163-172: contracts/axone-cognitarium/src/querier/engine.rs#L163-L172
Added lines #L163 - L172 were not covered by tests
[warning] 223-223: contracts/axone-cognitarium/src/querier/engine.rs#L223
Added line #L223 was not covered by tests
[warning] 773-773: contracts/axone-cognitarium/src/querier/engine.rs#L773
Added line #L773 was not covered by testscontracts/axone-cognitarium/src/contract.rs
[warning] 106-106: contracts/axone-cognitarium/src/contract.rs#L106
Added line #L106 was not covered by tests
[warning] 230-232: contracts/axone-cognitarium/src/contract.rs#L230-L232
Added lines #L230 - L232 were not covered by tests
[warning] 291-291: contracts/axone-cognitarium/src/contract.rs#L291
Added line #L291 was not covered by tests
Markdownlint
docs/axone-cognitarium.md
420-420: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
421-421: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
422-422: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
525-525: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
526-526: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
550-550: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
551-551: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
552-552: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
571-571: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
572-572: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
599-599: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
600-600: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
601-601: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
644-644: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
645-645: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
646-646: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
741-741: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
924-924: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
Additional comments not posted (40)
contracts/axone-cognitarium/src/querier/mod.rs (1)
9-9
: Ensure theplan
module export is necessary.The
plan
module is now publicly exported. Verify that this export is required and aligns with the intended architecture.contracts/axone-cognitarium/src/state/mod.rs (1)
11-14
: Good practice: Conditional compilation for testing utilities.The use of
#[cfg(test)]
for thetest_util
module is a good practice, ensuring it only compiles during testing.contracts/axone-cognitarium/src/querier/mapper.rs (3)
Line range hint
9-20
: Simplification and renaming approved.The changes to
literal_as_object
simplify the function by removing thestorage
dependency and align with the newNamespaceSolver
naming convention.
Line range hint
26-39
: Simplification and renaming approved.The changes to
iri_as_node
simplify the function by removing thestorage
dependency and align with the newNamespaceSolver
naming convention.
43-48
: New function addition approved.The
iri_as_string
function provides a useful utility for convertingIRI
types into strings. The implementation is straightforward and aligns with existing patterns.contracts/axone-dataverse/src/registrar/registry.rs (1)
39-47
: Enhanced query flexibility approved.The use of
WhereClause::Bgp
allows for more complex graph patterns, aligning with the PR objectives of enhancing querying capabilities. The changes maintain the intended functionality.contracts/axone-cognitarium/src/querier/plan.rs (4)
24-29
: New method addition approved.The
empty_plan
method provides a straightforward way to create an emptyQueryPlan
, enhancing usability. The implementation is simple and aligns with the intended functionality.
77-78
: New variant addition approved.The
Filter
variant inQueryNode
enhances query capabilities by allowing filtering based on anExpression
. This aligns with the PR objectives of improving query precision.
88-91
: New method addition approved.The
noop
method provides a way to create a no-operation node, improving the flexibility of constructing query nodes. The implementation is straightforward and aligns with the intended functionality.
115-118
: Modification forFilter
variant approved.The changes to
lookup_bound_variables
ensure that theFilter
variant is correctly handled, maintaining the integrity of variable management. The implementation is consistent with existing patterns.Tools
GitHub Check: codecov/patch
[warning] 115-118: contracts/axone-cognitarium/src/querier/plan.rs#L115-L118
Added lines #L115 - L118 were not covered by testscontracts/axone-cognitarium/src/state/triples.rs (1)
154-155
: LGTM! VerifyNamespaceSolver
implementation.The change to use
NamespaceSolver
enhances type safety and clarity. Ensure that theNamespaceSolver
trait is correctly implemented for all necessary structures.Run the following script to verify the
NamespaceSolver
trait implementation:contracts/axone-cognitarium/src/storer/engine.rs (1)
283-286
: LGTM!The refactoring of the
node_size
function improves readability and reduces code complexity while maintaining functionality.contracts/axone-cognitarium/src/state/namespaces.rs (1)
44-47
: LGTM!The renaming of
NamespaceResolver
toNamespaceQuerier
and the introduction ofNamespaceSolver
enhance modularity and clarity in namespace management.contracts/axone-cognitarium/src/querier/variable.rs (3)
Line range hint
54-99
: LGTM! Theas_value
method changes enhance flexibility.The update to accept a mutable reference to a
NamespaceSolver
trait object improves the method's extensibility.
101-124
: LGTM! Theas_term
method is well-implemented.The method effectively converts
ResolvedVariable
instances intoTerm
objects using theNamespaceSolver
.
177-187
: LGTM! TheHasBoundVariables
trait adds useful abstraction.The trait provides a structured approach for handling variable lookups, enhancing the module's functionality.
contracts/axone-dataverse/src/contract.rs (2)
145-146
: LGTM! The import forWhereClause
is necessary.The addition of the
WhereClause
import reflects its new usage in query construction.
306-314
: LGTM! The test case update improves clarity.The use of
WhereClause::Bgp
allows for more structured query conditions in the test.contracts/axone-cognitarium/src/querier/expression.rs (3)
10-70
: LGTM! TheExpression
enum andevaluate
method are well-implemented.The enum provides a comprehensive set of logical operations, and the
evaluate
method effectively handles different expression types.
100-153
: LGTM! TheTerm
enum and its methods are well-designed.The enum provides necessary conversions and comparisons, and the methods are implemented correctly.
155-512
: LGTM! The test cases are comprehensive and thorough.The tests cover various scenarios, ensuring the correctness of the
Expression
andTerm
implementations.contracts/axone-cognitarium/src/msg.rs (2)
76-76
: Ensure backward compatibility with optionalWhereClause
.The
r#where
field in bothDeleteData
andDescribeQuery
has been changed toOption<WhereClause>
. Ensure that any existing code handling these structures can accommodate the possibility of aNone
value.Consider adding tests to verify the behavior when
r#where
isNone
.Also applies to: 428-428
485-514
: Verify logical operations inExpression
.The
Expression
enum supports various logical operations. Ensure that these operations are correctly implemented and tested, especially complex combinations ofAnd
,Or
, andNot
.Consider adding tests to cover edge cases and complex logical expressions.
contracts/axone-cognitarium/src/querier/plan_builder.rs (2)
14-14
: Initializens_resolver
correctly inPlanBuilder
.The
ns_resolver
field is initialized usingNamespaceResolver::new
. Ensure that the initialization correctly handles the providedstorage
andns_cache
.Consider adding tests to verify the behavior of
PlanBuilder
with different namespace configurations.
68-87
: Ensure comprehensive testing ofbuild_node
.The
build_node
method handles differentWhereClause
variants. Ensure that each variant is correctly processed and that error handling, especially for unbound variables, is robust.Consider adding tests to cover each
WhereClause
variant and potential error scenarios.contracts/axone-cognitarium/src/querier/engine.rs (3)
22-22
: Ensurens_cache
is correctly utilized inQueryEngine
.The
ns_cache
field is introduced to manage namespaces. Ensure that it is correctly initialized and used throughout theQueryEngine
.Consider adding tests to verify the behavior of
QueryEngine
with different namespace configurations.
163-172
: Add test coverage forFilterIterator
.The
FilterIterator
is a new addition that implements filtering logic. Ensure that it is thoroughly tested, especially for edge cases and complex expressions.Consider adding tests to cover the filtering logic and potential error scenarios.
Tools
GitHub Check: codecov/patch
[warning] 163-172: contracts/axone-cognitarium/src/querier/engine.rs#L163-L172
Added lines #L163 - L172 were not covered by tests
773-773
: Add test coverage forliteral_as_object
.The
literal_as_object
function is used inbuild_object_template
. Ensure that it is correctly implemented and tested, especially for different literal types.Consider adding tests to cover various literal conversions and potential error scenarios.
Tools
GitHub Check: codecov/patch
[warning] 773-773: contracts/axone-cognitarium/src/querier/engine.rs#L773
Added line #L773 was not covered by testsdocs/axone-cognitarium.md (6)
423-423
: Verify thedelete_data.where
parameter description.Ensure that the
WhereClause
type and its usage are accurately described in the documentation.
552-552
: Verify thewhere
parameter inconstruct
query description.Ensure that the
WhereClause
type and its usage in theconstruct
query are accurately described in the documentation.Tools
Markdownlint
552-552: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
573-573
: Verify thewhere
parameter indescribe
query description.Ensure that the
WhereClause
type and its usage in thedescribe
query are accurately described in the documentation.
910-910
: Verify consistency ofWhereCondition
toWhereClause
renaming.Ensure that the renaming is consistently applied throughout the documentation.
519-527
: Verify the newBgp
section description.Ensure that the
Bgp
construct and its usage are accurately described in the new section.Tools
Markdownlint
525-525: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
526-526: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
Line range hint
575-647
: Verify the new sections forExpression
,Filter
, andLateralJoin
.Ensure that the constructs and their usage are accurately described in the new sections.
Tools
Markdownlint
571-571: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
572-572: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
599-599: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
600-600: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
601-601: null
Spaces inside emphasis markers(MD037, no-space-in-emphasis)
contracts/axone-cognitarium/src/contract.rs (6)
96-107
: Verify the correctness of theexecute
function changes.Ensure that the changes to handle an optional
WhereClause
are correctly implemented and consistent with the PR objectives.Tools
GitHub Check: codecov/patch
[warning] 106-106: contracts/axone-cognitarium/src/contract.rs#L106
Added line #L106 was not covered by tests
101-107
: Verify the logic of thedelete
function.Ensure that the logic for handling the
delete
vector andr#where
parameter is correctly implemented.Tools
GitHub Check: codecov/patch
[warning] 106-106: contracts/axone-cognitarium/src/contract.rs#L106
Added line #L106 was not covered by tests
223-233
: Verify the correctness of thedescribe
function changes.Ensure that the usage of
WhereClause
for query construction is correctly implemented.Tools
GitHub Check: codecov/patch
[warning] 230-232: contracts/axone-cognitarium/src/contract.rs#L230-L232
Added lines #L230 - L232 were not covered by tests
282-292
: Verify the correctness of theconstruct
function changes.Ensure that the usage of
WhereClause
for query construction is correctly implemented.Tools
GitHub Check: codecov/patch
[warning] 291-291: contracts/axone-cognitarium/src/contract.rs#L291
Added line #L291 was not covered by tests
203-203
: Verify the correctness of theselect
function changes.Ensure that the usage of
WhereClause
for query construction is correctly implemented.
Line range hint
354-363
: Verify the correctness of themap_select_solutions
function.Ensure that the function correctly maps query solutions to the expected response format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems very good ! Great job ! 👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's good 👍
Closes #614
Description
Here is an API evolution to integrate expression filtering capabilities in the cognitarium querying mechanism. The changes are breaking.
The idea is to enhance the
WhereClause
type by renaming the oldSimple
byBgp
for basic graph patterns and adding a newFilter
clause allowing to filter another clause based on expressions, this would allow to filter with specific variable values.Here is an example using this to filter on a range of a
height
value:In this example the BGP will provide the resolution of the
height
variable and the filter will then limit the possibilities for those between 1000 and 2000.@ccamel @bdeneux I'd appreciate your insights on this design before going further in the implementation :)
Details
The
WhereClause::Filter
takes an inner clause and filtering matching the providedExpression
. An expression internally resolves as a term, which can currently be either aString
or abool
. A term can be built from a variable so it can be constructed from object literals for example, the construction of the resulting string is opinionated and impact the behaviour of comparison operators, so I'll let you juge the proposed implementation.This implementation is very simplistic, it'd make sense in the future to provide more types of
Term
for a fine grained control on expression operators...Misc
A
WhereClause::LateralJoin
clause has also been added to allow to join two clauses as a for loop, this was needed to make theDescribe
message to work with the refactoring.The namespace resolution mechanism has been reworked by providing trait abstraction to ease tests and integration with the new filtering capabilities, it brings a lot of additional changes sorry for that..
Summary by CodeRabbit
New Features
WhereClause
in query operations.Expression
type for complex logical operations in queries.Filter
variant in query plans to enable conditional filtering of results.Bug Fixes
WhereClause
is provided.Documentation
WhereClause
,Bgp
, andExpression
.Chores