You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2022/11/30 09:10:51 UTC

[avro] branch branch-1.11 updated: AVRO-3678: [Rust] Support writing float value to field defined as double (#1991)

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new 6eb723419 AVRO-3678: [Rust] Support writing float value to field defined as double (#1991)
6eb723419 is described below

commit 6eb72341912ac3858f56531e457de77213eafd02
Author: Martin Grigorov <ma...@users.noreply.github.com>
AuthorDate: Wed Nov 30 11:10:20 2022 +0200

    AVRO-3678: [Rust] Support writing float value to field defined as double (#1991)
    
    Originally contributed by @shaeqahmed with #1985
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    (cherry picked from commit b8897c60ce990d15564a850e3aaf22945c4e7788)
---
 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(