tustvold commented on code in PR #3553:
URL: https://github.com/apache/arrow-rs/pull/3553#discussion_r1084291090


##########
arrow-array/src/array/run_array.rs:
##########
@@ -0,0 +1,499 @@
+// 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 std::any::Any;
+
+use arrow_data::{ArrayData, ArrayDataBuilder};
+use arrow_schema::{ArrowError, DataType, Field};
+
+use crate::{
+    builder::StringRunBuilder,
+    make_array,
+    types::{Int16Type, Int32Type, Int64Type, RunEndIndexType},
+    Array, ArrayRef, PrimitiveArray,
+};
+
+///
+/// A run-end encoding (REE) is a variation of [run-length encoding 
(RLE)](https://en.wikipedia.org/wiki/Run-length_encoding).
+///
+/// This encoding is good for representing data containing same values 
repeated consecutively.
+///
+/// [`RunArray`] contains `run_ends` array and `values` array of same length.
+/// The `run_ends` array stores the indexes at which the run ends. The 
`values` array
+/// stores the value of each run. Below example illustrates how a logical 
array is represented in
+/// [`RunArray`]
+///
+///
+/// ```text
+/// ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┐
+///   ┌─────────────────┐  ┌─────────┐       ┌─────────────────┐
+/// │ │        A        │  │    2    │ │     │        A        │     
+///   ├─────────────────┤  ├─────────┤       ├─────────────────┤
+/// │ │        D        │  │    3    │ │     │        A        │    run length 
of 'A' = runs_ends[0] - 0 = 2
+///   ├─────────────────┤  ├─────────┤       ├─────────────────┤
+/// │ │        B        │  │    6    │ │     │        D        │    run length 
of 'D' = run_ends[1] - run_ends[0] = 1
+///   └─────────────────┘  └─────────┘       ├─────────────────┤
+/// │        values          run_ends  │     │        B        │     
+///                                          ├─────────────────┤
+/// └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┘     │        B        │     
+///                                          ├─────────────────┤
+///                RunArray                  │        B        │    run length 
of 'B' = run_ends[2] - run_ends[1] = 3
+///               length = 3                 └─────────────────┘
+///  
+///                                             Logical array
+///                                                Contents
+/// ```
+
+pub struct RunArray<R: RunEndIndexType> {
+    data: ArrayData,
+    run_ends: PrimitiveArray<R>,
+    values: ArrayRef,
+}
+
+impl<R: RunEndIndexType> RunArray<R> {
+    /// Attempts to create RunArray using given run_ends (index where a run 
ends)
+    /// and the values (value of the run). Returns an error if the given data 
is not compatible
+    /// with RunEndEncoded specification.
+    pub fn try_new(
+        run_ends: &PrimitiveArray<R>,
+        values: &dyn Array,
+    ) -> Result<Self, ArrowError> {
+        let run_ends_type = run_ends.data_type().clone();
+        let values_type = values.data_type().clone();
+        let ree_array_type = DataType::RunEndEncoded(
+            Box::new(Field::new("run_ends", run_ends_type, false)),
+            Box::new(Field::new("values", values_type, true)),
+        );
+        let builder = ArrayDataBuilder::new(ree_array_type)

Review Comment:
   This doesn't appear to set the length?



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