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 2023/10/10 07:04:04 UTC
[avro] branch main updated: AVRO-3881: [rust] Writer should write user metadata even if the body is empty (#2545)
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/main by this push:
new 4d1ac461b AVRO-3881: [rust] Writer should write user metadata even if the body is empty (#2545)
4d1ac461b is described below
commit 4d1ac461b94ca6e28312bc3b3c06f9982001ffef
Author: tom <no...@gmail.com>
AuthorDate: Tue Oct 10 15:03:57 2023 +0800
AVRO-3881: [rust] Writer should write user metadata even if the body is empty (#2545)
* writer should write user metadata even if the body is empty
* AVRO-3881: Give a better name to a new test case
---------
Co-authored-by: Martin Grigorov <ma...@users.noreply.github.com>
---
lang/rust/avro/src/writer.rs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/lang/rust/avro/src/writer.rs b/lang/rust/avro/src/writer.rs
index 83b7d8b00..8802ce604 100644
--- a/lang/rust/avro/src/writer.rs
+++ b/lang/rust/avro/src/writer.rs
@@ -323,6 +323,7 @@ impl<'a, W: Write> Writer<'a, W> {
/// **NOTE** This function forces the written data to be flushed (an implicit
/// call to [`flush`](struct.Writer.html#method.flush) is performed).
pub fn into_inner(mut self) -> AvroResult<W> {
+ self.maybe_write_header()?;
self.flush()?;
Ok(self.writer)
}
@@ -635,6 +636,7 @@ mod tests {
schema::{DecimalSchema, FixedSchema, Name},
types::Record,
util::zig_i64,
+ Reader,
};
use pretty_assertions::assert_eq;
use serde::{Deserialize, Serialize};
@@ -1139,6 +1141,22 @@ mod tests {
Ok(())
}
+ #[test]
+ fn test_avro_3881_metadata_empty_body() -> TestResult {
+ let schema = Schema::parse_str(SCHEMA)?;
+ let mut writer = Writer::new(&schema, Vec::new());
+ writer.add_user_metadata("a".to_string(), "b")?;
+ let result = writer.into_inner()?;
+
+ let reader = Reader::with_schema(&schema, &result[..])?;
+ let mut expected = HashMap::new();
+ expected.insert("a".to_string(), vec![b'b']);
+ assert_eq!(reader.user_metadata(), &expected);
+ assert_eq!(reader.into_iter().count(), 0);
+
+ Ok(())
+ }
+
#[test]
fn test_avro_3405_writer_add_metadata_failure() -> TestResult {
let schema = Schema::parse_str(SCHEMA)?;