Mola-maker commented on code in PR #12268:
URL: https://github.com/apache/arrow-rs/pull/12268#discussion_r4690252985


##########
arrow-ipc/src/writer.rs:
##########
@@ -1274,21 +1274,52 @@ fn ensure_supported_ipc_data_type(
     }
 }
 
-fn append_variadic_buffer_counts(counts: &mut Vec<i64>, array: &ArrayData) {
+fn append_variadic_buffer_counts(
+    counts: &mut Vec<i64>,
+    array: &ArrayData,
+) -> Result<(), ArrowError> {
     match array.data_type() {
         DataType::BinaryView | DataType::Utf8View => {
             // The spec documents the counts only includes the variadic 
buffers, not the view/null buffers.
             // 
https://arrow.apache.org/docs/format/Columnar.html#variadic-buffers
             counts.push(array.buffers().len() as i64 - 1);
+            Ok(())
         }
         DataType::Dictionary(_, _) => {
             // Do nothing
             // Dictionary values are handled in special dictionary messages
+            Ok(())
+        }
+        DataType::RunEndEncoded(_, _) => {
+            // The writer writes the children of the unsliced run array, so

Review Comment:
   Thanks @alamb. I think the naming is misleading here: `unslice_run_array` 
doesn't restore the
   unsliced data. It rebases the run ends to offset 0 and slices `values` to 
the physical range
   (`values().slice(start_physical_index, physical_length)`), so the writer 
already writes the
   sliced values.
   
   The mismatch comes from the empty case. For a zero-length run array (and an 
empty list child),
   the writer replaces the array with `ArrayData::new_empty`, which has no 
variadic buffers, while
   `append_variadic_buffer_counts` still counted the buffers on the original 
array.
   
   This PR makes the counting follow the same transformations as the writer. A 
more robust option
   would be to record the variadic counts inside `write_array_data` while the 
view buffers are
   written, and drop the separate traversal, so the two can't drift apart. I'm 
happy to do that
   here or in a follow-up. Which would you prefer? I'll also update the comment 
so it doesn't say
   "unsliced".
   



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