-
Notifications
You must be signed in to change notification settings - Fork 182
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
Conversation
WalkthroughOhayo, sensei! The changes in this pull request modify the Changes
Possibly related PRs
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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
Codecov ReportAttention: Patch coverage is
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. |
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.
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 |
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: 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 newMemberValue
structure. This may include updates to serialization, deserialization, and any business logic that relies on thevalue
field.Also, consider adding some unit tests to verify the behavior of
MemberValue
and its integration withMemberClause
.Keep up the great work! 💪
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
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 inMemberClause
looks perfect! 🎉Changing the type from
Primitive
toMemberValue
is the right move to support the new functionality.To ensure a smooth integration, please verify the following:
- Update the code that constructs
MemberClause
instances to provide thevalue
field as aMemberValue
.- Modify the query processing logic to handle filtering on both primitive values and strings based on the
MemberValue
type.- 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 elusiveMemberClause
references.This script will:
- Find all .proto files in the repository
- Search within those files for 'MemberClause' or 'member_clause' (case-insensitive)
- 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 thetypes.proto
file. This means the change fromPrimitive
toMemberValue
for thevalue
field is nicely isolated.Here's what we found:
types.proto
: Contains theMemberClause
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:
- Verify any code that implements or uses the
MemberClause
message, especially in non-proto files.- 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 newMemberValue
enum looks great.It enhances the flexibility of the
MemberClause
to handle bothPrimitive
andString
values. This is a nice improvement in the data representation.
294-294
: Ohayo sensei! TheMemberClause
update is spot on.Using the new
MemberValue
enum for thevalue
field aligns perfectly with the enum's purpose. It enablesMemberClause
to handle a wider range of value types. Great work!
308-317
: Ohayo sensei! TheFrom
trait implementation forMemberValue
is awesome.The conversion logic handles both
Primitive
andString
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 handlingvalue_type
is implemented correctly.The code segment properly extracts the comparison value based on the
ValueType
variant and returns an error ifvalue_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 ifvalue_type
is missing. It's consistent with the similar code at line range 508-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()), | ||
}; |
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.
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
Summary by CodeRabbit
New Features
MemberClause
to support both primitive values and strings, improving data representation flexibility.MemberValue
enum for better handling of different value types.Bug Fixes
DojoWorld
implementation by adding type checks formember_clause.value
andmember.value
.These updates enhance functionality and reliability within the application, allowing for more versatile data management.