contracts icon indicating copy to clipboard operation
contracts copied to clipboard

feat(cognitarium)!: add query expression filters

Open amimart opened this issue 1 year ago • 2 comments

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 :)

amimart avatar Aug 12 '24 09:08 amimart

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?

Share
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 @coderabbitai in 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 @coderabbitai in 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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to 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.yaml file 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.

coderabbitai[bot] avatar Aug 12 '24 09:08 coderabbitai[bot]

Sounds good 👍

ccamel avatar Aug 14 '24 07:08 ccamel

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% 🔺)

bot-anik avatar Aug 22 '24 13:08 bot-anik