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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/torii/grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ message MemberClause {
string model = 2;
string member = 3;
ComparisonOperator operator = 4;
Primitive value = 5;
oneof value {
Primitive primitive = 5;
string string = 6;
}
}

message CompositeClause {
Expand Down
23 changes: 17 additions & 6 deletions crates/torii/grpc/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use self::subscriptions::event_message::EventMessageManager;
use self::subscriptions::model_diff::{ModelDiffRequest, StateDiffManager};
use crate::proto::types::clause::ClauseType;
use crate::proto::types::member_clause;
use crate::proto::world::world_server::WorldServer;
use crate::proto::world::{
SubscribeEntitiesRequest, SubscribeEntityResponse, SubscribeEventsResponse,
Expand Down Expand Up @@ -504,10 +505,14 @@
let comparison_operator = ComparisonOperator::from_repr(member_clause.operator as usize)
.expect("invalid comparison operator");

let primitive: Primitive =
member_clause.value.ok_or(QueryError::MissingParam("value".into()))?.try_into()?;

let comparison_value = primitive.to_sql_value()?;
let comparison_value =
match member_clause.value.ok_or(QueryError::MissingParam("value".into()))? {
member_clause::Value::String(value) => value,
member_clause::Value::Primitive(value) => {
let primitive: Primitive = value.try_into()?;
primitive.to_sql_value()?

Check warning on line 513 in crates/torii/grpc/src/server/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/server/mod.rs#L508-L513

Added lines #L508 - L513 were not covered by tests
}
};

let (namespace, model) = member_clause
.model
Expand Down Expand Up @@ -619,8 +624,14 @@
let comparison_operator =
ComparisonOperator::from_repr(member.operator as usize)
.expect("invalid comparison operator");
let value: Primitive = member.value.unwrap().try_into()?;
let comparison_value = value.to_sql_value()?;
let comparison_value =
match member.value.ok_or(QueryError::MissingParam("value".into()))? {
member_clause::Value::String(value) => value,
member_clause::Value::Primitive(value) => {
let primitive: Primitive = value.try_into()?;
primitive.to_sql_value()?

Check warning on line 632 in crates/torii/grpc/src/server/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/server/mod.rs#L627-L632

Added lines #L627 - L632 were not covered by tests
}
};

let column_name = format!("external_{}", member.member);

Expand Down
18 changes: 17 additions & 1 deletion crates/torii/grpc/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
};
use strum_macros::{AsRefStr, EnumIter, FromRepr};

use crate::proto::types::member_clause;
use crate::proto::{self};

pub mod schema;
Expand Down Expand Up @@ -54,12 +55,18 @@
VariableLen,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Hash, Eq, Clone)]

Check warning on line 58 in crates/torii/grpc/src/types/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/types/mod.rs#L58

Added line #L58 was not covered by tests
pub enum MemberValue {
Primitive(Primitive),
String(String),
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Hash, Eq, Clone)]
pub struct MemberClause {
pub model: String,
pub member: String,
pub operator: ComparisonOperator,
pub value: Primitive,
pub value: MemberValue,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Hash, Eq, Clone)]
Expand Down Expand Up @@ -298,6 +305,15 @@
}
}

impl From<MemberValue> for member_clause::Value {
fn from(value: MemberValue) -> Self {
match value {
MemberValue::Primitive(primitive) => member_clause::Value::Primitive(primitive.into()),
MemberValue::String(string) => member_clause::Value::String(string),

Check warning on line 312 in crates/torii/grpc/src/types/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/types/mod.rs#L309-L312

Added lines #L309 - L312 were not covered by tests
}
}

Check warning on line 314 in crates/torii/grpc/src/types/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/types/mod.rs#L314

Added line #L314 was not covered by tests
}

impl From<Value> for proto::types::Value {
fn from(value: Value) -> Self {
let value_type = match value.value_type {
Expand Down
Loading