feat(cognitarium)!: add query expression filters
Closes #614
Details
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 old Simple by Bgp for basic graph patterns and adding a new Filter clause allowing to filter another clause based on expressions, this would allow to filter with specific variable values.
Example
Here is an example using this to filter on a range of a height value:
{
"filter": {
"expr": {
"and": [
{
"greater_or_equal": [
{"variable": "height"},
{"literal": "1000"}
]
},
{
"less_or_equal": [
{"variable": "height"},
{"literal": "2000"}
]
}
]
},
"inner": {
"bgp": [
{
"subject": {"variable": "subject"},
"predicate": {"named": {"full": "height"}},
"object": {"variable": "height"}
}
]
}
}
}
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 :)
Walkthrough
The changes introduce a more flexible and robust query handling system by modifying how WhereClause is utilized across various modules. The execute function now accepts an optional WhereClause, enabling queries without explicit conditions. Additionally, the Expression and Term structures enhance the logical evaluation of expressions in queries, expanding the capabilities of the query engine. Overall, the codebase has been refactored for improved clarity and efficiency in query construction and execution.
Changes
| Files | Change Summary |
|---|---|
| contracts/axone-cognitarium/src/contract.rs contracts/axone-cognitarium/src/msg.rs contracts/axone-cognitarium/src/querier/engine.rs contracts/axone-cognitarium/src/querier/expression.rs contracts/axone-cognitarium/src/querier/mapper.rs contracts/axone-cognitarium/src/querier/mod.rs contracts/axone-cognitarium/src/querier/plan.rs contracts/axone-cognitarium/src/querier/plan_builder.rs contracts/axone-cognitarium/src/querier/variable.rs contracts/axone-cognitarium/src/state/mod.rs contracts/axone-cognitarium/src/state/namespaces.rs contracts/axone-cognitarium/src/state/test_util.rs contracts/axone-cognitarium/src/state/triples.rs contracts/axone-cognitarium/src/storer/engine.rs |
Major refactor of query handling, introducing optional WhereClause, enhancing expression evaluation capabilities, and modifying namespace handling and resolution methods. This includes the addition of new structures like Expression and InMemoryNamespaceSolver. |
| contracts/axone-dataverse/src/contract.rs contracts/axone-dataverse/src/registrar/registry.rs |
Updated query conditions to use the new WhereClause structure, replacing older formats for improved query construction. |
| docs/axone-cognitarium.md | Documentation updates to reflect changes in query parameters and the introduction of new expression types. |
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
| Objective | Addressed | Explanation |
|---|---|---|
| Extend querying capabilities by evaluating expressions against resolved variables (614) | ✅ |
Poem
🐇 In fields of code, where queries play,
New clauses hop and dance today.
With expressions bright, they twist and twirl,
In logic’s embrace, new patterns unfurl.
For every byte and every line,
A rabbit’s joy—this code is divine! 🐇✨
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?
Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>. -
Generate unit testing code for this file. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai generate unit testing code for this file. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai generate interesting stats about this repository and render them as a table. -
@coderabbitai show all the console.log statements in this repository. -
@coderabbitai read src/utils.ts and generate unit testing code. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
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)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Sounds good 👍
size-limit report 📦
| Path | Size |
|---|---|
| target/wasm32-unknown-unknown/release/axone_objectarium.wasm | 458.07 KB (0%) |
| target/wasm32-unknown-unknown/release/axone_law_stone.wasm | 648.51 KB (0%) |
| target/wasm32-unknown-unknown/release/axone_cognitarium.wasm | 877.09 KB (+5.51% 🔺) |
| target/wasm32-unknown-unknown/release/axone_dataverse.wasm | 678.36 KB (+1.19% 🔺) |
Codecov Report
Attention: Patch coverage is 97.92961% with 30 lines in your changes missing coverage. Please review.
| Files | Coverage Δ | |
|---|---|---|
| contracts/axone-cognitarium/src/msg.rs | 91.42% <ø> (-0.96%) |
:arrow_down: |
| ...tracts/axone-cognitarium/src/querier/expression.rs | 100.00% <100.00%> (ø) |
|
| contracts/axone-cognitarium/src/querier/mapper.rs | 100.00% <100.00%> (ø) |
|
| ...acts/axone-cognitarium/src/querier/plan_builder.rs | 99.65% <100.00%> (+0.11%) |
:arrow_up: |
| ...ontracts/axone-cognitarium/src/querier/variable.rs | 99.75% <100.00%> (+0.49%) |
:arrow_up: |
| contracts/axone-cognitarium/src/state/triples.rs | 100.00% <100.00%> (ø) |
|
| contracts/axone-cognitarium/src/storer/engine.rs | 98.70% <100.00%> (+1.68%) |
:arrow_up: |
| contracts/axone-dataverse/src/contract.rs | 96.22% <100.00%> (ø) |
|
| ...ontracts/axone-dataverse/src/registrar/registry.rs | 100.00% <100.00%> (ø) |
|
| ...ontracts/axone-cognitarium/src/state/namespaces.rs | 94.11% <87.50%> (-0.94%) |
:arrow_down: |
| ... and 4 more |