This is an automated email from the ASF dual-hosted git repository.
Jefffrey pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 3b75eb04a3 Add `ListArray::value_field` accessor (#10661)
3b75eb04a3 is described below
commit 3b75eb04a394a7d4b1e0cd15df9c5492b2dc8293
Author: Emil Ernerfeldt <[email protected]>
AuthorDate: Fri Aug 14 01:12:27 2026 -0700
Add `ListArray::value_field` accessor (#10661)
# Which issue does this PR close?
None
# Rationale for this change
Given a `ListArray` I want to easily answer questions like "is the field
nullable?" and "what is the underlying data type?". Now we can!
Same for other arrays (`FixedSizeListArray` etc)
# What changes are included in this PR?
- `ListArray::value_field()`
- `FixedSizeListArray::value_field()`
- `GenericListViewArray::value_field() (ListView + LargeListView)`
- `MapArray::entries_field(), MapArray::ordered()`
- `RunArray::run_ends_field(), RunArray::values_field()`
# Are these changes tested?
No
# Are there any user-facing changes?
Yes
---------
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
---
arrow-array/src/array/fixed_size_list_array.rs | 8 ++++++++
arrow-array/src/array/list_array.rs | 8 ++++++++
arrow-array/src/array/list_view_array.rs | 8 ++++++++
arrow-array/src/array/map_array.rs | 19 +++++++++++++++++++
arrow-array/src/array/run_array.rs | 18 +++++++++++++++++-
5 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/arrow-array/src/array/fixed_size_list_array.rs
b/arrow-array/src/array/fixed_size_list_array.rs
index 84e3e0bc22..667546a852 100644
--- a/arrow-array/src/array/fixed_size_list_array.rs
+++ b/arrow-array/src/array/fixed_size_list_array.rs
@@ -339,6 +339,14 @@ impl FixedSizeListArray {
(f, self.value_length, self.values, self.nulls)
}
+ /// The field that describes the values of this list.
+ pub fn value_field(&self) -> &FieldRef {
+ match &self.data_type {
+ DataType::FixedSizeList(f, _) => f,
+ _ => unreachable!(),
+ }
+ }
+
/// Returns a reference to the values of this list.
pub fn values(&self) -> &ArrayRef {
&self.values
diff --git a/arrow-array/src/array/list_array.rs
b/arrow-array/src/array/list_array.rs
index c099eecfaa..33bf88e171 100644
--- a/arrow-array/src/array/list_array.rs
+++ b/arrow-array/src/array/list_array.rs
@@ -322,6 +322,14 @@ impl<OffsetSize: OffsetSizeTrait>
GenericListArray<OffsetSize> {
(f, self.value_offsets, self.values, self.nulls)
}
+ /// The field that describes the values of this list.
+ pub fn value_field(&self) -> &FieldRef {
+ match &self.data_type {
+ DataType::List(f) | DataType::LargeList(f) => f,
+ _ => unreachable!(),
+ }
+ }
+
/// Returns a reference to the offsets of this list
///
/// Unlike [`Self::value_offsets`] this returns the [`OffsetBuffer`]
diff --git a/arrow-array/src/array/list_view_array.rs
b/arrow-array/src/array/list_view_array.rs
index 65be4edc07..7dcd6755e7 100644
--- a/arrow-array/src/array/list_view_array.rs
+++ b/arrow-array/src/array/list_view_array.rs
@@ -287,6 +287,14 @@ impl<OffsetSize: OffsetSizeTrait>
GenericListViewArray<OffsetSize> {
)
}
+ /// The field that describes the values of this list.
+ pub fn value_field(&self) -> &FieldRef {
+ match &self.data_type {
+ DataType::ListView(f) | DataType::LargeListView(f) => f,
+ _ => unreachable!(),
+ }
+ }
+
/// Returns a reference to the offsets of this list
///
/// Unlike [`Self::value_offsets`] this returns the [`ScalarBuffer`]
diff --git a/arrow-array/src/array/map_array.rs
b/arrow-array/src/array/map_array.rs
index 1254ac32bf..0e604dd0c7 100644
--- a/arrow-array/src/array/map_array.rs
+++ b/arrow-array/src/array/map_array.rs
@@ -188,6 +188,25 @@ impl MapArray {
(f, self.value_offsets, self.entries, self.nulls, ordered)
}
+ /// The field that describes the entries of this map.
+ ///
+ /// The field's type is always a [`DataType::Struct`] of the key and value
fields,
+ /// see [`Self::entries_fields`].
+ pub fn entries_field(&self) -> &FieldRef {
+ match &self.data_type {
+ DataType::Map(f, _) => f,
+ _ => unreachable!(),
+ }
+ }
+
+ /// Are the entries of this map sorted by key?
+ pub fn ordered(&self) -> bool {
+ match &self.data_type {
+ DataType::Map(_, ordered) => *ordered,
+ _ => unreachable!(),
+ }
+ }
+
/// Returns a reference to the offsets of this map
///
/// Unlike [`Self::value_offsets`] this returns the [`OffsetBuffer`]
diff --git a/arrow-array/src/array/run_array.rs
b/arrow-array/src/array/run_array.rs
index 1a4b780c91..305814f8b0 100644
--- a/arrow-array/src/array/run_array.rs
+++ b/arrow-array/src/array/run_array.rs
@@ -20,7 +20,7 @@ use std::sync::Arc;
use arrow_buffer::{ArrowNativeType, BooleanBufferBuilder, NullBuffer,
RunEndBuffer, ScalarBuffer};
use arrow_data::{ArrayData, ArrayDataBuilder};
-use arrow_schema::{ArrowError, DataType, Field};
+use arrow_schema::{ArrowError, DataType, Field, FieldRef};
use crate::{
Array, ArrayAccessor, ArrayRef, PrimitiveArray,
@@ -206,6 +206,22 @@ impl<R: RunEndIndexType> RunArray<R> {
(self.data_type, self.run_ends, self.values)
}
+ /// The field that describes the run ends of this array.
+ pub fn run_ends_field(&self) -> &FieldRef {
+ match &self.data_type {
+ DataType::RunEndEncoded(f, _) => f,
+ _ => unreachable!(),
+ }
+ }
+
+ /// The field that describes the values of this array.
+ pub fn values_field(&self) -> &FieldRef {
+ match &self.data_type {
+ DataType::RunEndEncoded(_, f) => f,
+ _ => unreachable!(),
+ }
+ }
+
/// Returns a reference to the [`RunEndBuffer`].
pub fn run_ends(&self) -> &RunEndBuffer<R::Native> {
&self.run_ends