This is an automated email from the ASF dual-hosted git repository. mgrigorov pushed a commit to branch avro-3678-float-to-doable in repository https://gitbox.apache.org/repos/asf/avro.git
commit 6457dbb25c84dba545d390992c82772d406479e3 Author: Martin Tzvetanov Grigorov <[email protected]> AuthorDate: Wed Nov 30 10:58:12 2022 +0200 AVRO-3678: [Rust] Support writing float value to field defined as double Originally contributed by @shaeqahmed with #1985 Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> --- lang/rust/avro/src/types.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lang/rust/avro/src/types.rs b/lang/rust/avro/src/types.rs index 688af8eeb..9ee6b7b2d 100644 --- a/lang/rust/avro/src/types.rs +++ b/lang/rust/avro/src/types.rs @@ -403,6 +403,7 @@ impl Value { (&Value::Duration(_), &Schema::Duration) => None, (&Value::Uuid(_), &Schema::Uuid) => None, (&Value::Float(_), &Schema::Float) => None, + (&Value::Float(_), &Schema::Double) => None, (&Value::Double(_), &Schema::Double) => None, (&Value::Bytes(_), &Schema::Bytes) => None, (&Value::Bytes(_), &Schema::Decimal { .. }) => None, @@ -1011,6 +1012,9 @@ mod tests { fn validate() { let value_schema_valid = vec![ (Value::Int(42), Schema::Int, true, ""), + (Value::Int(43), Schema::Long, true, ""), + (Value::Float(43.2), Schema::Float, true, ""), + (Value::Float(45.9), Schema::Double, true, ""), ( Value::Int(42), Schema::Boolean, @@ -1565,6 +1569,12 @@ Field with name '"b"' is not a member of the map items"#, assert!(value.resolve(&Schema::TimestampMicros).is_err()); } + #[test] + fn avro_3678_resolve_float_to_double() { + let value = Value::Float(2345.1); + assert!(value.resolve(&Schema::Double).is_ok()); + } + #[test] fn test_avro_3621_resolve_to_nullable_union() { let schema = Schema::parse_str(
