-
Notifications
You must be signed in to change notification settings - Fork 3
add uuid scalar type #148
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
Merged
hallettj
merged 8 commits into
v1
from
jessehallett/eng-1604-mongodb-comparisons-for-uuids-serialized-as-strings
Mar 1, 2025
Merged
add uuid scalar type #148
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
82b44f9
add uuid scalar type
hallettj b9acfae
update introspection to infer UUID type
hallettj c914e29
update round-trip serialization tests to include UUID
hallettj 33db8e5
scalar type serialization and bson_name have same behavior - make tha…
hallettj 3364d04
tests
hallettj 6673cd7
update changelog
hallettj 1f5ea66
Merge branch 'v1' into jessehallett/eng-1604-mongodb-comparisons-for-…
hallettj c3c9291
ensure proptest uuids always have 16 bytes
hallettj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ation-tests/src/tests/snapshots/integration_tests__tests__filtering__filters_by_uuid.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
source: crates/integration-tests/src/tests/filtering.rs | ||
expression: "run_connector_query(Connector::TestCases,\nquery_request().collection(\"uuids\").query(query().predicate(binop(\"_eq\",\ntarget!(\"uuid\"),\nvalue!(\"40a693d0-c00a-425d-af5c-535e37fdfe9c\"))).fields([field!(\"name\"),\nfield!(\"uuid\"), field!(\"uuid_as_string\")]),)).await?" | ||
--- | ||
- rows: | ||
- name: peristeria elata | ||
uuid: 40a693d0-c00a-425d-af5c-535e37fdfe9c | ||
uuid_as_string: 40a693d0-c00a-425d-af5c-535e37fdfe9c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,11 +71,12 @@ pub fn json_to_bson(expected_type: &Type, value: Value) -> Result<Bson> { | |
|
||
/// Works like json_to_bson, but only converts BSON scalar types. | ||
pub fn json_to_bson_scalar(expected_type: BsonScalarType, value: Value) -> Result<Bson> { | ||
use BsonScalarType as S; | ||
let result = match expected_type { | ||
BsonScalarType::Double => Bson::Double(deserialize(expected_type, value)?), | ||
BsonScalarType::Int => Bson::Int32(deserialize(expected_type, value)?), | ||
BsonScalarType::Long => convert_long(&from_string(expected_type, value)?)?, | ||
BsonScalarType::Decimal => Bson::Decimal128( | ||
S::Double => Bson::Double(deserialize(expected_type, value)?), | ||
S::Int => Bson::Int32(deserialize(expected_type, value)?), | ||
S::Long => convert_long(&from_string(expected_type, value)?)?, | ||
S::Decimal => Bson::Decimal128( | ||
Decimal128::from_str(&from_string(expected_type, value.clone())?).map_err(|err| { | ||
JsonToBsonError::ConversionErrorWithContext( | ||
Type::Scalar(MongoScalarType::Bson(expected_type)), | ||
|
@@ -84,37 +85,34 @@ pub fn json_to_bson_scalar(expected_type: BsonScalarType, value: Value) -> Resul | |
) | ||
})?, | ||
), | ||
BsonScalarType::String => Bson::String(deserialize(expected_type, value)?), | ||
BsonScalarType::Date => convert_date(&from_string(expected_type, value)?)?, | ||
BsonScalarType::Timestamp => { | ||
deserialize::<json_formats::Timestamp>(expected_type, value)?.into() | ||
} | ||
BsonScalarType::BinData => { | ||
deserialize::<json_formats::BinData>(expected_type, value)?.into() | ||
} | ||
BsonScalarType::ObjectId => Bson::ObjectId(deserialize(expected_type, value)?), | ||
BsonScalarType::Bool => match value { | ||
S::String => Bson::String(deserialize(expected_type, value)?), | ||
S::Date => convert_date(&from_string(expected_type, value)?)?, | ||
S::Timestamp => deserialize::<json_formats::Timestamp>(expected_type, value)?.into(), | ||
S::BinData => deserialize::<json_formats::BinData>(expected_type, value)?.into(), | ||
S::UUID => convert_uuid(&from_string(expected_type, value)?)?, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry about the churn in this function. This is the only added line. The logic in other lines is unchanged. |
||
S::ObjectId => Bson::ObjectId(deserialize(expected_type, value)?), | ||
S::Bool => match value { | ||
Value::Bool(b) => Bson::Boolean(b), | ||
_ => incompatible_scalar_type(BsonScalarType::Bool, value)?, | ||
_ => incompatible_scalar_type(S::Bool, value)?, | ||
}, | ||
BsonScalarType::Null => match value { | ||
S::Null => match value { | ||
Value::Null => Bson::Null, | ||
_ => incompatible_scalar_type(BsonScalarType::Null, value)?, | ||
_ => incompatible_scalar_type(S::Null, value)?, | ||
}, | ||
BsonScalarType::Undefined => match value { | ||
S::Undefined => match value { | ||
Value::Null => Bson::Undefined, | ||
_ => incompatible_scalar_type(BsonScalarType::Undefined, value)?, | ||
_ => incompatible_scalar_type(S::Undefined, value)?, | ||
}, | ||
BsonScalarType::Regex => deserialize::<json_formats::Regex>(expected_type, value)?.into(), | ||
BsonScalarType::Javascript => Bson::JavaScriptCode(deserialize(expected_type, value)?), | ||
BsonScalarType::JavascriptWithScope => { | ||
S::Regex => deserialize::<json_formats::Regex>(expected_type, value)?.into(), | ||
S::Javascript => Bson::JavaScriptCode(deserialize(expected_type, value)?), | ||
S::JavascriptWithScope => { | ||
deserialize::<json_formats::JavaScriptCodeWithScope>(expected_type, value)?.into() | ||
} | ||
BsonScalarType::MinKey => Bson::MinKey, | ||
BsonScalarType::MaxKey => Bson::MaxKey, | ||
BsonScalarType::Symbol => Bson::Symbol(deserialize(expected_type, value)?), | ||
S::MinKey => Bson::MinKey, | ||
S::MaxKey => Bson::MaxKey, | ||
S::Symbol => Bson::Symbol(deserialize(expected_type, value)?), | ||
// dbPointer is deprecated | ||
BsonScalarType::DbPointer => Err(JsonToBsonError::NotImplemented(expected_type))?, | ||
S::DbPointer => Err(JsonToBsonError::NotImplemented(expected_type))?, | ||
}; | ||
Ok(result) | ||
} | ||
|
@@ -191,6 +189,17 @@ fn convert_long(value: &str) -> Result<Bson> { | |
Ok(Bson::Int64(n)) | ||
} | ||
|
||
fn convert_uuid(value: &str) -> Result<Bson> { | ||
let uuid = bson::Uuid::parse_str(value).map_err(|err| { | ||
JsonToBsonError::ConversionErrorWithContext( | ||
Type::Scalar(MongoScalarType::Bson(BsonScalarType::UUID)), | ||
value.into(), | ||
err.into(), | ||
) | ||
})?; | ||
Ok(bson::binary::Binary::from_uuid(uuid).into()) | ||
} | ||
|
||
fn deserialize<T>(expected_type: BsonScalarType, value: Value) -> Result<T> | ||
where | ||
T: DeserializeOwned, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I moved this to a method on
BsonScalarType