You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/11 06:56:03 UTC
[GitHub] [arrow-rs] HaoYang670 commented on a diff in pull request #2040: Truncate IPC record batch
HaoYang670 commented on code in PR #2040:
URL: https://github.com/apache/arrow-rs/pull/2040#discussion_r917592629
##########
arrow/src/ipc/writer.rs:
##########
@@ -861,6 +863,145 @@ fn has_validity_bitmap(data_type: &DataType, write_options: &IpcWriteOptions) ->
}
}
+/// Whether to truncate the buffer
+#[inline]
+fn buffer_need_truncate(
+ array_offset: usize,
+ buffer: &Buffer,
+ spec: &BufferSpec,
+ min_length: usize,
+) -> bool {
+ if spec == &BufferSpec::AlwaysNull {
+ false
+ } else {
+ array_offset != 0 || min_length < buffer.len()
+ }
+}
+
+/// Returns byte width for a buffer spec. Only for `BufferSpec::FixedWidth`.
+#[inline]
+fn get_buffer_byte_width(spec: &BufferSpec) -> usize {
+ match spec {
+ BufferSpec::FixedWidth { byte_width } => *byte_width,
+ _ => 0,
+ }
+}
+
+/// Returns the number of total bytes in base binary arrays.
+fn get_total_bytes(array_data: &ArrayData) -> usize {
+ if array_data.is_empty() {
+ return 0;
+ }
+ match array_data.data_type() {
+ DataType::Binary => {
+ let array: BinaryArray = array_data.clone().into();
+ let offsets = array.value_offsets();
+ (offsets[array_data.len()] - offsets[0]) as usize
Review Comment:
Is this corrent when `array_data.offset() > 0`?
##########
arrow/src/ipc/writer.rs:
##########
@@ -861,6 +863,145 @@ fn has_validity_bitmap(data_type: &DataType, write_options: &IpcWriteOptions) ->
}
}
+/// Whether to truncate the buffer
+#[inline]
+fn buffer_need_truncate(
+ array_offset: usize,
+ buffer: &Buffer,
+ spec: &BufferSpec,
+ min_length: usize,
+) -> bool {
+ if spec == &BufferSpec::AlwaysNull {
+ false
+ } else {
+ array_offset != 0 || min_length < buffer.len()
+ }
+}
Review Comment:
nit: (not tested)
```rust
spec != &BufferSpec::AlwaysNull && (array_offset != 0 || min_length < buffer.len())
```
##########
arrow/src/ipc/writer.rs:
##########
@@ -1507,4 +1702,60 @@ mod tests {
IpcWriteOptions::try_new(8, false, MetadataVersion::V5).unwrap(),
);
}
+
+ #[test]
+ fn truncate_ipc_record_batch() {
+ pub fn serialize(record: &RecordBatch) -> Vec<u8> {
Review Comment:
Why do we need this function to be public?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org