From e9ee52a94099d802a692ade3904a881d3d022c50 Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Mon, 11 Nov 2024 14:26:23 -0800 Subject: [PATCH] you guys it works! --- crates/cli/src/native_query/pipeline/match_stage.rs | 13 ++++--------- crates/cli/src/native_query/tests.rs | 1 - .../native_query/type_solver/constraint_to_type.rs | 1 + crates/test-helpers/src/configuration.rs | 1 + 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/crates/cli/src/native_query/pipeline/match_stage.rs b/crates/cli/src/native_query/pipeline/match_stage.rs index d6a1408..41cf1f8 100644 --- a/crates/cli/src/native_query/pipeline/match_stage.rs +++ b/crates/cli/src/native_query/pipeline/match_stage.rs @@ -162,18 +162,13 @@ fn analyze_match_operator( &TypeConstraint::Scalar(BsonScalarType::Bool), match_expression, )?, + // In MongoDB $type accepts either a number, a string, an array of numbers, or an array of + // strings - for simplicity we're only accepting an array of strings since this form can + // express all comparisons that can be expressed with the other forms. "$type" => analyze_match_expression( context, desired_object_type_name, - &TypeConstraint::OneOf( - [ - TypeConstraint::Scalar(BsonScalarType::String), - TypeConstraint::ArrayOf(Box::new(TypeConstraint::Scalar( - BsonScalarType::String, - ))), - ] - .into(), - ), + &TypeConstraint::ArrayOf(Box::new(TypeConstraint::Scalar(BsonScalarType::String))), match_expression, )?, "$mod" => match match_expression { diff --git a/crates/cli/src/native_query/tests.rs b/crates/cli/src/native_query/tests.rs index 4fb6bd2..b30d36b 100644 --- a/crates/cli/src/native_query/tests.rs +++ b/crates/cli/src/native_query/tests.rs @@ -193,7 +193,6 @@ fn supports_various_query_predicate_operators() -> googletest::Result<()> { "num_mflix_comments": { "$in": "{{ num_comments_options }}" }, "$not": { "runtime": { "$lt": "{{ runtime }}" } }, "tomatoes.critic": { "$exists": "{{ critic_exists }}" }, - "lastUpdated": { "$type": "date" }, "released": { "$type": ["date", "{{ other_type }}"] }, "$or": [ { "$and": [ diff --git a/crates/cli/src/native_query/type_solver/constraint_to_type.rs b/crates/cli/src/native_query/type_solver/constraint_to_type.rs index b38370e..bc0d455 100644 --- a/crates/cli/src/native_query/type_solver/constraint_to_type.rs +++ b/crates/cli/src/native_query/type_solver/constraint_to_type.rs @@ -212,6 +212,7 @@ fn element_of(array_type: Type) -> Result { let element_type = match array_type { Type::ArrayOf(elem_type) => Ok(*elem_type), Type::Nullable(t) => element_of(*t).map(|t| Type::Nullable(Box::new(t))), + Type::ExtendedJSON => Ok(Type::ExtendedJSON), _ => Err(Error::ExpectedArray { actual_type: array_type, }), diff --git a/crates/test-helpers/src/configuration.rs b/crates/test-helpers/src/configuration.rs index 9a1e44e..42ce4c7 100644 --- a/crates/test-helpers/src/configuration.rs +++ b/crates/test-helpers/src/configuration.rs @@ -29,6 +29,7 @@ pub fn mflix_config() -> Configuration { ("num_mflix_comments", named_type("Int")), ("rated", named_type("String")), ("released", named_type("Date")), + ("runtime", named_type("Int")), ("title", named_type("String")), ("writers", array_of(named_type("String"))), ("year", named_type("Int")),