brancz commented on code in PR #7671:
URL: https://github.com/apache/arrow-rs/pull/7671#discussion_r2156657050


##########
arrow-data/src/transform/run.rs:
##########
@@ -0,0 +1,560 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use super::{ArrayData, Extend, _MutableArrayData};
+use arrow_buffer::{ArrowNativeType, Buffer, ToByteSlice};
+use arrow_schema::DataType;
+
+/// Generic helper to get the last run end value from a run ends array
+fn get_last_run_end<T: ArrowNativeType>(run_ends_data: 
&super::MutableArrayData) -> T {
+    if run_ends_data.data.len == 0 {
+        T::default()
+    } else {
+        // Convert buffer to typed slice and get the last element
+        let buffer = Buffer::from(run_ends_data.data.buffer1.as_slice());
+        let typed_slice: &[T] = buffer.typed_data();
+        if typed_slice.len() >= run_ends_data.data.len {
+            typed_slice[run_ends_data.data.len - 1]
+        } else {
+            T::default()
+        }
+    }
+}
+
+/// Extends the `MutableArrayData` with null values.
+///
+/// For RunEndEncoded, this adds nulls by extending the run_ends array
+/// and values array appropriately.
+pub fn extend_nulls(mutable: &mut _MutableArrayData, len: usize) {
+    if len == 0 {
+        return;
+    }
+
+    // For REE, we always need to add a value entry when adding a new run
+    // The values array should have one entry per run, not per logical element
+    mutable.child_data[1].extend_nulls(1);
+
+    // Determine the run end type from the data type
+    let run_end_type = if let DataType::RunEndEncoded(run_ends_field, _) = 
&mutable.data_type {
+        run_ends_field.data_type()
+    } else {
+        panic!("extend_nulls called on non-RunEndEncoded array");
+    };
+
+    // Use a macro to handle all run end types generically
+    macro_rules! extend_nulls_impl {
+        ($run_end_type:ty) => {{
+            let last_run_end = 
get_last_run_end::<$run_end_type>(&mutable.child_data[0]);
+            let new_value = last_run_end + <$run_end_type as 
ArrowNativeType>::usize_as(len);

Review Comment:
   Good point! Added implementation + test.



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