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: filtering bytearrays with member clause #2425

Merged
merged 3 commits into from
Sep 15, 2024

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Sep 13, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced MemberClause to support both primitive values and strings, improving data representation flexibility.
    • Introduced a new MemberValue enum for better handling of different value types.
  • Bug Fixes

    • Improved type safety and error handling in the DojoWorld implementation by adding type checks for member_clause.value and member.value.

These updates enhance functionality and reliability within the application, allowing for more versatile data management.

Copy link

coderabbitai bot commented Sep 13, 2024

Walkthrough

Ohayo, sensei! The changes in this pull request modify the MemberClause message in the types.proto file to utilize a oneof construct for the value field, enabling it to hold either a Primitive or a String. Corresponding updates in the Rust implementation enhance type safety and error handling when processing member_clause.value. Additionally, a new MemberValue enum is introduced to facilitate this flexibility, and a From trait implementation is added for seamless type conversions.

Changes

File Change Summary
crates/torii/grpc/proto/types.proto Modified MemberClause to use oneof for the value field, allowing Primitive or String.
crates/torii/grpc/src/server/mod.rs Updated handling of member_clause.value using a match statement for type safety with Primitive and String.
crates/torii/grpc/src/types/mod.rs Changed MemberClause to use MemberValue enum; added From trait implementation for conversions.

Possibly related PRs


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>, please review it.
    -- 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 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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link

codecov bot commented Sep 13, 2024

Codecov Report

Attention: Patch coverage is 0% with 23 lines in your changes missing coverage. Please review.

Project coverage is 67.89%. Comparing base (d64fdae) to head (cbda51a).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/torii/grpc/src/server/mod.rs 0.00% 15 Missing ⚠️
crates/torii/grpc/src/types/mod.rs 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2425      +/-   ##
==========================================
- Coverage   67.92%   67.89%   -0.04%     
==========================================
  Files         364      364              
  Lines       47832    47927      +95     
==========================================
+ Hits        32490    32539      +49     
- Misses      15342    15388      +46     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

graphQL is not impacted by this change? Or already supported?

@Larkooo
Copy link
Collaborator Author

Larkooo commented Sep 14, 2024

graphQL is not impacted by this change? Or already supported?

This change is scoped to the protobuf/grpc for the member clause to support bytearrays (as it is not a primitive). GraphQL is completely separate

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (1)
crates/torii/grpc/proto/types.proto (1)

115-120: Ohayo sensei! 🌞

The new MemberValue message looks great! 👍

The oneof construct provides a clean way to represent either a primitive value or a string. This flexibility will be useful in various scenarios.

Just a friendly reminder to ensure that the code interacting with MemberClause is updated to handle the new MemberValue structure. This may include updates to serialization, deserialization, and any business logic that relies on the value field.

Also, consider adding some unit tests to verify the behavior of MemberValue and its integration with MemberClause.

Keep up the great work! 💪

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9dddef6 and cbda51a.

Files selected for processing (3)
  • crates/torii/grpc/proto/types.proto (1 hunks)
  • crates/torii/grpc/src/server/mod.rs (3 hunks)
  • crates/torii/grpc/src/types/mod.rs (4 hunks)
Additional comments not posted (7)
crates/torii/grpc/proto/types.proto (1)

126-126: Ohayo sensei! 🌞

The value field update in MemberClause looks perfect! 🎉

Changing the type from Primitive to MemberValue is the right move to support the new functionality.

To ensure a smooth integration, please verify the following:

  1. Update the code that constructs MemberClause instances to provide the value field as a MemberValue.
  2. Modify the query processing logic to handle filtering on both primitive values and strings based on the MemberValue type.
  3. Test the changes thoroughly, especially the scenarios where the value field is set as a string.

Here's a quick script to help you locate the relevant code:

This script searches for files that import and use the MemberClause message and prints the relevant lines. It should give you a good starting point for the verification process.

Let me know if you have any questions! 😊

Verification successful

Ohayo sensei! 🌞

It seems our previous attempt to find MemberClause usage didn't go as planned. No worries though, we'll try a different approach! Let's cast a wider net to catch those elusive MemberClause references.

This script will:

  1. Find all .proto files in the repository
  2. Search within those files for 'MemberClause' or 'member_clause' (case-insensitive)
  3. Display the filename and the matching lines

Let's see what we can find with this new approach, sensei! 🕵️‍♂️


Ohayo sensei! 🌞

Great news! The MemberClause change looks well-contained. 🎉

Our investigation shows that the MemberClause is only directly referenced within the types.proto file. This means the change from Primitive to MemberValue for the value field is nicely isolated.

Here's what we found:

  • types.proto: Contains the MemberClause message definition and uses it as a field.
  • No direct usage of MemberClause in other .proto files.

While this is promising, I'd recommend a quick manual check:

  1. Verify any code that implements or uses the MemberClause message, especially in non-proto files.
  2. Ensure that any serialization/deserialization logic is updated if necessary.

Overall, the change appears to be safe and well-scoped. Nice work, sensei! 👍

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash

# Find files that import and use the `MemberClause` message
rg --type proto 'MemberClause' -l | xargs -I {} sh -c 'echo "File: {}"; rg --type proto "MemberClause" {}'

Length of output: 138


Script:

#!/bin/bash

# Find .proto files and search for MemberClause
fd -e proto | xargs -I {} sh -c 'echo "File: {}"; rg -i "memberclause|member_clause" {}'

Length of output: 275

crates/torii/grpc/src/types/mod.rs (3)

58-62: Ohayo sensei! The new MemberValue enum looks great.

It enhances the flexibility of the MemberClause to handle both Primitive and String values. This is a nice improvement in the data representation.


294-294: Ohayo sensei! The MemberClause update is spot on.

Using the new MemberValue enum for the value field aligns perfectly with the enum's purpose. It enables MemberClause to handle a wider range of value types. Great work!


308-317: Ohayo sensei! The From trait implementation for MemberValue is awesome.

The conversion logic handles both Primitive and String variants elegantly, ensuring smooth integration with the protocol buffer types. This is a crucial piece for the overall functionality. Excellent job!

crates/torii/grpc/src/server/mod.rs (3)

44-44: Ohayo sensei! This import looks good to me.

The ValueType enum import is necessary for the code changes that follow.


508-516: Ohayo sensei! The match statement for handling value_type is implemented correctly.

The code segment properly extracts the comparison value based on the ValueType variant and returns an error if value_type is missing. Great work!


628-639: Ohayo sensei! This match statement is implemented correctly, just like the previous one.

The code segment properly extracts the comparison value based on the ValueType variant and returns an error if value_type is missing. It's consistent with the similar code at line range 508-516.

Comment on lines +508 to +516
let comparison_value =
match member_clause.value.ok_or(QueryError::MissingParam("value".into()))?.value_type {
Some(ValueType::String(value)) => value,
Some(ValueType::Primitive(value)) => {
let primitive: Primitive = value.try_into()?;
primitive.to_sql_value()?
}
None => return Err(QueryError::MissingParam("value_type".into()).into()),
};
Copy link

Choose a reason for hiding this comment

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

Ohayo sensei! Consider refactoring the duplicated code into a separate function.

The code segments at line ranges 508-516 and 628-639 are very similar. They both match on value.value_type to extract the comparison value. To improve code reuse and maintainability, consider extracting the common logic into a separate function. Here's a suggestion:

fn extract_comparison_value(value: &proto::types::Value) -> Result<String, Error> {
    match value.value_type {
        Some(ValueType::String(value)) => Ok(value),
        Some(ValueType::Primitive(value)) => {
            let primitive: Primitive = value.try_into()?;
            Ok(primitive.to_sql_value()?)
        }
        None => Err(QueryError::MissingParam("value_type".into()).into()),
    }
}

Then, you can replace the duplicated code with calls to this function:

let comparison_value = extract_comparison_value(&member_clause.value.ok_or(QueryError::MissingParam("value".into()))?)?;
let comparison_value = extract_comparison_value(&member.value.ok_or(QueryError::MissingParam("value".into()))?)?;

This will make the code more DRY and easier to maintain. What do you think, sensei?

Also applies to: 628-639

@Larkooo Larkooo merged commit 069bc1a into dojoengine:main Sep 15, 2024
13 of 15 checks passed
@kariy kariy mentioned this pull request Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants