viirya commented on code in PR #9445:
URL: https://github.com/apache/arrow-rs/pull/9445#discussion_r3221384624
##########
arrow-array/src/record_batch.rs:
##########
@@ -451,6 +513,42 @@ impl RecordBatch {
&mut schema.metadata
}
+ /// Returns the per-batch custom metadata, or `None` if not set.
+ ///
+ /// This corresponds to the `custom_metadata` field on the IPC `Message`
+ /// flatbuffer, separate from schema-level metadata.
+ pub fn custom_metadata(&self) -> Option<&HashMap<String, String>> {
+ self.custom_metadata.as_deref()
+ }
+
+ /// Returns a mutable reference to the per-batch custom metadata,
allocating
+ /// an empty map on first access.
+ ///
+ /// Cheap if this [`RecordBatch`] uniquely owns the metadata; otherwise the
+ /// underlying map is cloned via [`Arc::make_mut`]. An empty map left after
+ /// clearing entries still reports as `Some(_)` from
+ /// [`Self::custom_metadata`]; two batches that differ only in this respect
+ /// still compare equal.
+ pub fn custom_metadata_mut(&mut self) -> &mut HashMap<String, String> {
+ Arc::make_mut(
+ self.custom_metadata
+ .get_or_insert_with(|| Arc::new(HashMap::new())),
+ )
+ }
+
+ /// Sets the per-batch custom metadata, returning `self`.
+ ///
+ /// An empty map is normalized to "no metadata", so a batch built with an
+ /// empty map compares equal to one built without calling this method.
+ pub fn with_custom_metadata(mut self, metadata: HashMap<String, String>)
-> Self {
Review Comment:
Should we use `Arc<HashMap<String, String>>` as the custom metadata type?
Otherwise, if you want to attach same metadata for all record batches, you need
to copy the same metadata map and the `Arc` here is useless as it is only for
one record batch?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]