harshmotw-db commented on code in PR #7783:
URL: https://github.com/apache/arrow-rs/pull/7783#discussion_r2167848191


##########
parquet-variant/src/variant_buffer_manager.rs:
##########
@@ -0,0 +1,124 @@
+use arrow_schema::ArrowError;
+
+pub trait VariantBufferManager {
+    /// Returns the slice where the variant metadata needs to be written to. 
This method may be
+    /// called several times during the construction of a new `metadata` field 
in a variant. The
+    /// implementation must make sure that on every call, all the data written 
to the metadata
+    /// buffer so far are preserved.
+    fn borrow_metadata_buffer(&mut self) -> &mut [u8];
+
+    /// Returns the slice where value needs to be written to. This method may 
be called several
+    /// times during the construction of a new `value` field in a variant. The 
implementation must
+    /// make sure that on every call, all the data written to the value buffer 
so far are preserved.
+    fn borrow_value_buffer(&mut self) -> &mut [u8];
+
+    /// Ensures that the next call to `borrow_metadata_buffer` returns a slice 
having at least
+    /// `size` bytes. Also ensures that the value metadata written so far are 
persisted - this means
+    /// that if `borrow_metadata_buffer` is to return a new buffer from the 
next call onwards, the
+    /// new buffer must have the contents of the old metadata buffer.
+    fn ensure_metadata_buffer_size(&mut self, size: usize) -> Result<(), 
ArrowError>;
+
+    /// Ensures that the next call to `borrow_value_buffer` returns a slice 
having at least `size`
+    /// bytes. Also ensures that the value bytes written so far are persisted 
- this means that
+    /// if `borrow_value_buffer` is to return a new buffer from the next call 
onwards, the new
+    /// buffer must have the contents of the old value buffer.
+    fn ensure_value_buffer_size(&mut self, size: usize) -> Result<(), 
ArrowError>;
+
+    fn get_immutable_metadata_buffer(&self) -> &[u8] {
+        unimplemented!("Optional method not implemented in 
VariantBufferManager")
+    }
+
+    fn get_immutable_value_buffer(&self) -> &[u8] {
+        unimplemented!("Optional method not implemented in 
VariantBufferManager")
+    }
+}
+
+pub struct SampleBoxBasedVariantBufferManager {
+    pub value_buffer: Box<[u8]>,
+    pub metadata_buffer: Box<[u8]>,

Review Comment:
   Yes, I do plan on adding an arrow-based sample buffer manager. I currently 
do not fully understand arrow though but I believe the trait is simple enough 
that it could be extended to such use cases. I will do that as a follow up if 
you agree with the general design.



##########
parquet-variant/src/variant_buffer_manager.rs:
##########
@@ -0,0 +1,124 @@
+use arrow_schema::ArrowError;
+
+pub trait VariantBufferManager {
+    /// Returns the slice where the variant metadata needs to be written to. 
This method may be
+    /// called several times during the construction of a new `metadata` field 
in a variant. The
+    /// implementation must make sure that on every call, all the data written 
to the metadata
+    /// buffer so far are preserved.
+    fn borrow_metadata_buffer(&mut self) -> &mut [u8];
+
+    /// Returns the slice where value needs to be written to. This method may 
be called several
+    /// times during the construction of a new `value` field in a variant. The 
implementation must
+    /// make sure that on every call, all the data written to the value buffer 
so far are preserved.
+    fn borrow_value_buffer(&mut self) -> &mut [u8];
+
+    /// Ensures that the next call to `borrow_metadata_buffer` returns a slice 
having at least
+    /// `size` bytes. Also ensures that the value metadata written so far are 
persisted - this means
+    /// that if `borrow_metadata_buffer` is to return a new buffer from the 
next call onwards, the
+    /// new buffer must have the contents of the old metadata buffer.
+    fn ensure_metadata_buffer_size(&mut self, size: usize) -> Result<(), 
ArrowError>;
+
+    /// Ensures that the next call to `borrow_value_buffer` returns a slice 
having at least `size`
+    /// bytes. Also ensures that the value bytes written so far are persisted 
- this means that
+    /// if `borrow_value_buffer` is to return a new buffer from the next call 
onwards, the new
+    /// buffer must have the contents of the old value buffer.
+    fn ensure_value_buffer_size(&mut self, size: usize) -> Result<(), 
ArrowError>;
+
+    fn get_immutable_metadata_buffer(&self) -> &[u8] {
+        unimplemented!("Optional method not implemented in 
VariantBufferManager")
+    }
+
+    fn get_immutable_value_buffer(&self) -> &[u8] {
+        unimplemented!("Optional method not implemented in 
VariantBufferManager")
+    }
+}
+
+pub struct SampleBoxBasedVariantBufferManager {
+    pub value_buffer: Box<[u8]>,
+    pub metadata_buffer: Box<[u8]>,

Review Comment:
   Yes, I do plan on adding an arrow-compliant sample buffer manager. I 
currently do not fully understand arrow though but I believe the trait is 
simple enough that it could be extended to such use cases. I will do that as a 
follow up if you agree with the general design.



-- 
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]

Reply via email to