Repository: jorgecarleitao/arrow2
Pull request #1340 (2022-12-21 09:20:05)

make finish_eq_validities public
I have use for those functions downstream.

codecov[bot]: # [Codecov](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1340?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) Report
Base: **83.12**% // Head: **83.14**% // Increases project coverage by **`+0.01%`** :tada:
> Coverage data is based on head [(`2bb0654`)](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1340?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) compared to base [(`e698d48`)](https://codecov.io/gh/jorgecarleitao/arrow2/commit/e698d4870546572de8b3f4fe71fef21ff3d63eb8?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao).
> Patch has no changes to coverable lines.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #1340      +/-   ##
==========================================
+ Coverage   83.12%   83.14%   +0.01%     
==========================================
  Files         370      370              
  Lines       40196    40196              
==========================================
+ Hits        33414    33420       +6     
+ Misses       6782     6776       -6     
```


| [Impacted Files](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1340?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) | Coverage Δ | |
|---|---|---|
| [src/compute/comparison/mod.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1340/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2NvbXB1dGUvY29tcGFyaXNvbi9tb2QucnM=) | `64.51% <ø> (ø)` | |
| [src/io/ipc/read/file.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1340/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2lvL2lwYy9yZWFkL2ZpbGUucnM=) | `96.87% <0.00%> (ø)` | |
| [src/offset.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1340/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL29mZnNldC5ycw==) | `84.89% <0.00%> (+0.35%)` | :arrow_up: |
| [src/bitmap/immutable.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1340/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2JpdG1hcC9pbW11dGFibGUucnM=) | `86.66% <0.00%> (+0.60%)` | :arrow_up: |
| [src/array/utf8/mod.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1340/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2FycmF5L3V0ZjgvbW9kLnJz) | `85.95% <0.00%> (+1.00%)` | :arrow_up: |
| [src/bitmap/utils/slice\_iterator.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1340/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2JpdG1hcC91dGlscy9zbGljZV9pdGVyYXRvci5ycw==) | `98.78% <0.00%> (+1.21%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1340?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao).


Patch:
diff --git a/src/array/growable/structure.rs b/src/array/growable/structure.rs
index e7f997024d..8e91cf03ce 100644
--- a/src/array/growable/structure.rs
+++ b/src/array/growable/structure.rs
@@ -3,7 +3,6 @@ use std::sync::Arc;
 use crate::{
     array::{Array, StructArray},
     bitmap::MutableBitmap,
-    datatypes::DataType,
 };
 
 use super::{
@@ -25,6 +24,8 @@ impl<'a> GrowableStruct<'a> {
     /// # Panics
     /// If `arrays` is empty.
     pub fn new(arrays: Vec<&'a StructArray>, mut use_validity: bool, capacity: usize) -> Self {
+        assert!(!arrays.is_empty());
+
         // if any of the arrays has nulls, insertions from any array requires setting bits
         // as there is at least one array with nulls.
         if arrays.iter().any(|array| array.null_count() > 0) {
@@ -68,11 +69,7 @@ impl<'a> GrowableStruct<'a> {
         let values = std::mem::take(&mut self.values);
         let values = values.into_iter().map(|mut x| x.as_box()).collect();
 
-        StructArray::new(
-            DataType::Struct(self.arrays[0].fields().to_vec()),
-            values,
-            validity.into(),
-        )
+        StructArray::new(self.arrays[0].data_type().clone(), values, validity.into())
     }
 }
 
@@ -121,7 +118,7 @@ impl<'a> From<GrowableStruct<'a>> for StructArray {
         let values = val.values.into_iter().map(|mut x| x.as_box()).collect();
 
         StructArray::new(
-            DataType::Struct(val.arrays[0].fields().to_vec()),
+            val.arrays[0].data_type().clone(),
             values,
             val.validity.into(),
         )
diff --git a/src/array/struct_/mod.rs b/src/array/struct_/mod.rs
index 1938338659..a8848bb557 100644
--- a/src/array/struct_/mod.rs
+++ b/src/array/struct_/mod.rs
@@ -122,7 +122,7 @@ impl StructArray {
 
     /// Creates an empty [`StructArray`].
     pub fn new_empty(data_type: DataType) -> Self {
-        if let DataType::Struct(fields) = &data_type {
+        if let DataType::Struct(fields) = &data_type.to_logical_type() {
             let values = fields
                 .iter()
                 .map(|field| new_empty_array(field.data_type().clone()))
diff --git a/src/array/union/mod.rs b/src/array/union/mod.rs
index 3aa963c00a..e767aac2b2 100644
--- a/src/array/union/mod.rs
+++ b/src/array/union/mod.rs
@@ -195,7 +195,7 @@ impl UnionArray {
 
     /// Creates a new empty [`UnionArray`].
     pub fn new_empty(data_type: DataType) -> Self {
-        if let DataType::Union(f, _, mode) = &data_type {
+        if let DataType::Union(f, _, mode) = data_type.to_logical_type() {
             let fields = f
                 .iter()
                 .map(|x| new_empty_array(x.data_type().clone()))
diff --git a/src/compute/comparison/mod.rs b/src/compute/comparison/mod.rs
index 6c7714f587..b364ed8822 100644
--- a/src/compute/comparison/mod.rs
+++ b/src/compute/comparison/mod.rs
@@ -508,7 +508,10 @@ fn can_partial_eq_scalar(data_type: &DataType) -> bool {
         )
 }
 
-fn finish_eq_validities(
+/// Utility for low level end users that implement their own comparison functions
+/// A comparison on the data column can be applied on masked out values
+/// This function will correct equality for the validities.
+pub fn finish_eq_validities(
     output_without_validities: BooleanArray,
     validity_lhs: Option<Bitmap>,
     validity_rhs: Option<Bitmap>,
@@ -565,7 +568,10 @@ fn finish_eq_validities(
     }
 }
 
-fn finish_neq_validities(
+/// Utility for low level end users that implement their own comparison functions
+/// A comparison on the data column can be applied on masked out values
+/// This function will correct non-equality for the validities.
+pub fn finish_neq_validities(
     output_without_validities: BooleanArray,
     validity_lhs: Option<Bitmap>,
     validity_rhs: Option<Bitmap>,
diff --git a/src/io/parquet/read/indexes/mod.rs b/src/io/parquet/read/indexes/mod.rs
index e890f27d69..045482a831 100644
--- a/src/io/parquet/read/indexes/mod.rs
+++ b/src/io/parquet/read/indexes/mod.rs
@@ -245,7 +245,7 @@ pub fn has_indexes(row_group: &RowGroupMetaData) -> bool {
 /// This function is IO-bounded and calls `reader.read_exact` exactly once.
 /// # Error
 /// Errors iff the indexes can't be read or their deserialization to arrow is incorrect (e.g. invalid utf-8)
-fn read_columns_indexes<R: Read + Seek>(
+pub fn read_columns_indexes<R: Read + Seek>(
     reader: &mut R,
     chunks: &[ColumnChunkMetaData],
     fields: &[Field],
@@ -264,7 +264,7 @@ fn read_columns_indexes<R: Read + Seek>(
 }
 
 /// Returns the set of (row) intervals of the pages.
-fn compute_page_row_intervals(
+pub fn compute_page_row_intervals(
     locations: &[PageLocation],
     num_rows: usize,
 ) -> Result<Vec<Interval>, ParquetError> {


Test patch:
diff --git a/tests/it/array/growable/list.rs b/tests/it/array/growable/list.rs
index ef18365457..9aa56b109a 100644
--- a/tests/it/array/growable/list.rs
+++ b/tests/it/array/growable/list.rs
@@ -1,6 +1,9 @@
-use arrow2::array::{
-    growable::{Growable, GrowableList},
-    ListArray, MutableListArray, MutablePrimitiveArray, TryExtend,
+use arrow2::{
+    array::{
+        growable::{Growable, GrowableList},
+        Array, ListArray, MutableListArray, MutablePrimitiveArray, TryExtend,
+    },
+    datatypes::DataType,
 };
 
 fn create_list_array(data: Vec<Option<Vec<Option<i32>>>>) -> ListArray<i32> {
@@ -9,6 +12,33 @@ fn create_list_array(data: Vec<Option<Vec<Option<i32>>>>) -> ListArray<i32> {
     array.into()
 }
 
+#[test]
+fn extension() {
+    let data = vec![
+        Some(vec![Some(1i32), Some(2), Some(3)]),
+        Some(vec![Some(4), Some(5)]),
+        Some(vec![Some(6i32), Some(7), Some(8)]),
+    ];
+
+    let array = create_list_array(data);
+
+    let data_type =
+        DataType::Extension("ext".to_owned(), Box::new(array.data_type().clone()), None);
+    let array_ext = ListArray::new(
+        data_type,
+        array.offsets().clone(),
+        array.values().clone(),
+        array.validity().cloned(),
+    );
+
+    let mut a = GrowableList::new(vec![&array_ext], false, 0);
+    a.extend(0, 0, 1);
+
+    let result: ListArray<i32> = a.into();
+    assert_eq!(array_ext.data_type(), result.data_type());
+    dbg!(result);
+}
+
 #[test]
 fn basic() {
     let data = vec![
diff --git a/tests/it/array/growable/mod.rs b/tests/it/array/growable/mod.rs
index a6e25ecba3..480bcf06c3 100644
--- a/tests/it/array/growable/mod.rs
+++ b/tests/it/array/growable/mod.rs
@@ -12,7 +12,7 @@ mod utf8;
 
 use arrow2::array::growable::make_growable;
 use arrow2::array::*;
-use arrow2::datatypes::DataType;
+use arrow2::datatypes::{DataType, Field};
 
 #[test]
 fn test_make_growable() {
@@ -37,11 +37,36 @@ fn test_make_growable() {
     let array =
         FixedSizeBinaryArray::new(DataType::FixedSizeBinary(2), b"abcd".to_vec().into(), None);
     make_growable(&[&array], false, 2);
+}
 
+#[test]
+fn test_make_growable_extension() {
     let array = DictionaryArray::try_from_keys(
         Int32Array::from_slice([1, 0]),
         Int32Array::from_slice([1, 2]).boxed(),
     )
     .unwrap();
     make_growable(&[&array], false, 2);
+
+    let data_type = DataType::Extension("ext".to_owned(), Box::new(DataType::Int32), None);
+    let array = Int32Array::from_slice([1, 2]).to(data_type.clone());
+    let array_grown = make_growable(&[&array], false, 2).as_box();
+    assert_eq!(array_grown.data_type(), &data_type);
+
+    let data_type = DataType::Extension(
+        "ext".to_owned(),
+        Box::new(DataType::Struct(vec![Field::new(
+            "a",
+            DataType::Int32,
+            false,
+        )])),
+        None,
+    );
+    let array = StructArray::new(
+        data_type.clone(),
+        vec![Int32Array::from_slice([1, 2]).boxed()],
+        None,
+    );
+    let array_grown = make_growable(&[&array], false, 2).as_box();
+    assert_eq!(array_grown.data_type(), &data_type);
 }
diff --git a/tests/it/array/mod.rs b/tests/it/array/mod.rs
index 9df7c53d02..85318ba628 100644
--- a/tests/it/array/mod.rs
+++ b/tests/it/array/mod.rs
@@ -58,6 +58,11 @@ fn empty() {
         DataType::Utf8,
         DataType::Binary,
         DataType::List(Box::new(Field::new("a", DataType::Binary, true))),
+        DataType::List(Box::new(Field::new(
+            "a",
+            DataType::Extension("ext".to_owned(), Box::new(DataType::Int32), None),
+            true,
+        ))),
         DataType::Union(
             vec![Field::new("a", DataType::Binary, true)],
             None,
@@ -68,11 +73,42 @@ fn empty() {
             None,
             UnionMode::Dense,
         ),
+        DataType::Struct(vec![Field::new("a", DataType::Int32, true)]),
     ];
     let a = datatypes.into_iter().all(|x| new_empty_array(x).len() == 0);
     assert!(a);
 }
 
+#[test]
+fn empty_extension() {
+    let datatypes = vec![
+        DataType::Int32,
+        DataType::Float64,
+        DataType::Utf8,
+        DataType::Binary,
+        DataType::List(Box::new(Field::new("a", DataType::Binary, true))),
+        DataType::Union(
+            vec![Field::new("a", DataType::Binary, true)],
+            None,
+            UnionMode::Sparse,
+        ),
+        DataType::Union(
+            vec![Field::new("a", DataType::Binary, true)],
+            None,
+            UnionMode::Dense,
+        ),
+        DataType::Struct(vec![Field::new("a", DataType::Int32, true)]),
+    ];
+    let a = datatypes
+        .into_iter()
+        .map(|dt| DataType::Extension("ext".to_owned(), Box::new(dt), None))
+        .all(|x| {
+            let a = new_empty_array(x);
+            a.len() == 0 && matches!(a.data_type(), DataType::Extension(_, _, _))
+        });
+    assert!(a);
+}
+
 #[test]
 fn test_clone() {
     let datatypes = vec![