This is an automated email from the ASF dual-hosted git repository.
kriskras99 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro-rs.git
The following commit(s) were added to refs/heads/main by this push:
new cebcf04 Issue #252: Add an `Option<String>` field with a
`#[avro(default = "null")]` (#260)
cebcf04 is described below
commit cebcf0459352354f7f299efa049ce025a806cd9e
Author: Martin Grigorov <[email protected]>
AuthorDate: Tue Oct 28 23:00:00 2025 +0200
Issue #252: Add an `Option<String>` field with a `#[avro(default =
"null")]` (#260)
* Issue #252: Add an `Option<String>` field with a `#[avro(default =
"null")]`
https://github.com/apache/avro-rs/issues/252#issuecomment-3177888121
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
* Use non-raw string
* Fix the default value for an union schema
It should be `null` instead of `"null"`
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
* Fix the name of the default schema equality implementation in log message
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
---------
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
---
avro/src/schema_equality.rs | 2 +-
avro_derive/tests/derive.rs | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/avro/src/schema_equality.rs b/avro/src/schema_equality.rs
index b884a0f..1097594 100644
--- a/avro/src/schema_equality.rs
+++ b/avro/src/schema_equality.rs
@@ -240,7 +240,7 @@ pub fn set_schemata_equality_comparator(
pub(crate) fn compare_schemata(schema_one: &Schema, schema_two: &Schema) ->
bool {
SCHEMATA_COMPARATOR_ONCE
.get_or_init(|| {
- debug!("Going to use the default schemata equality comparator:
SpecificationEq.",);
+ debug!("Going to use the default schemata equality comparator:
StructFieldEq.",);
Box::new(StructFieldEq {
include_attributes: false,
})
diff --git a/avro_derive/tests/derive.rs b/avro_derive/tests/derive.rs
index 69c0aef..4e0e0fb 100644
--- a/avro_derive/tests/derive.rs
+++ b/avro_derive/tests/derive.rs
@@ -1390,6 +1390,9 @@ mod test_derive {
#[avro(default = r#""Foo""#)]
myenum: MyEnum,
+
+ #[avro(default = "null")]
+ optional: Option<String>,
}
let schema = r#"
@@ -1443,6 +1446,11 @@ mod test_derive {
"symbols":["Foo", "Bar", "Baz"]
},
"default":"Foo"
+ },
+ {
+ "name":"optional",
+ "type": ["null", "string"],
+ "default": null
}
]
}
@@ -1472,6 +1480,7 @@ mod test_derive {
),
"c" => assert_eq!(None, field.default),
"myenum" => assert_eq!(Some(json!("Foo")), field.default),
+ "optional" => assert_eq!(Some(json!(null)), field.default),
_ => panic!("Unexpected field name"),
}
}
@@ -1491,6 +1500,7 @@ mod test_derive {
.collect(),
array: vec![4, 5, 6],
myenum: MyEnum::Bar,
+ optional: None,
});
}