This is an automated email from the ASF dual-hosted git repository.

wjones127 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new a88d70dc14 feat: utility functions for creating fsl dtype (#5373)
a88d70dc14 is described below

commit a88d70dc14cd6d3bf5ceeeb8263a62358bf8722a
Author: universalmind303 <[email protected]>
AuthorDate: Wed Feb 14 22:53:13 2024 -0600

    feat: utility functions for creating fsl dtype (#5373)
---
 arrow-array/src/array/list_array.rs |  9 +++------
 arrow-ipc/src/convert.rs            |  6 ++++++
 arrow-schema/src/datatype.rs        | 18 ++++++++++++++++++
 arrow-schema/src/field.rs           | 15 +++++++++++++++
 arrow-schema/src/fields.rs          |  6 +-----
 arrow-select/src/filter.rs          |  6 ++----
 6 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/arrow-array/src/array/list_array.rs 
b/arrow-array/src/array/list_array.rs
index 9758c112a1..ba3719392e 100644
--- a/arrow-array/src/array/list_array.rs
+++ b/arrow-array/src/array/list_array.rs
@@ -705,8 +705,7 @@ mod tests {
         let value_offsets = Buffer::from_slice_ref([0i64, 3, 6, 8]);
 
         // Construct a list array from the above two
-        let list_data_type =
-            DataType::LargeList(Arc::new(Field::new("item", DataType::Int32, 
false)));
+        let list_data_type = DataType::new_large_list(DataType::Int32, false);
         let list_data = ArrayData::builder(list_data_type.clone())
             .len(3)
             .add_buffer(value_offsets.clone())
@@ -863,8 +862,7 @@ mod tests {
         bit_util::set_bit(&mut null_bits, 8);
 
         // Construct a list array from the above two
-        let list_data_type =
-            DataType::LargeList(Arc::new(Field::new("item", DataType::Int32, 
false)));
+        let list_data_type = DataType::new_large_list(DataType::Int32, false);
         let list_data = ArrayData::builder(list_data_type)
             .len(9)
             .add_buffer(value_offsets)
@@ -929,8 +927,7 @@ mod tests {
         bit_util::set_bit(&mut null_bits, 8);
 
         // Construct a list array from the above two
-        let list_data_type =
-            DataType::LargeList(Arc::new(Field::new("item", DataType::Int32, 
false)));
+        let list_data_type = DataType::new_large_list(DataType::Int32, false);
         let list_data = ArrayData::builder(list_data_type)
             .len(9)
             .add_buffer(value_offsets)
diff --git a/arrow-ipc/src/convert.rs b/arrow-ipc/src/convert.rs
index b290a09acf..505541f7d5 100644
--- a/arrow-ipc/src/convert.rs
+++ b/arrow-ipc/src/convert.rs
@@ -877,6 +877,12 @@ mod tests {
                 Field::new("utf8", DataType::Utf8, false),
                 Field::new("binary", DataType::Binary, false),
                 Field::new_list("list[u8]", Field::new("item", 
DataType::UInt8, false), true),
+                Field::new_fixed_size_list(
+                    "fixed_size_list[u8]",
+                    Field::new("item", DataType::UInt8, false),
+                    2,
+                    true,
+                ),
                 Field::new_list(
                     "list[struct<float32, int32, bool>]",
                     Field::new_struct(
diff --git a/arrow-schema/src/datatype.rs b/arrow-schema/src/datatype.rs
index a5bd66b50c..079b855ce9 100644
--- a/arrow-schema/src/datatype.rs
+++ b/arrow-schema/src/datatype.rs
@@ -608,6 +608,24 @@ impl DataType {
     pub fn new_list(data_type: DataType, nullable: bool) -> Self {
         DataType::List(Arc::new(Field::new_list_field(data_type, nullable)))
     }
+
+    /// Create a [`DataType::LargeList`] with elements of the specified type
+    /// and nullability, and conventionally named inner [`Field`] (`"item"`).
+    ///
+    /// To specify field level metadata, construct the inner [`Field`]
+    /// directly via [`Field::new`] or [`Field::new_list_field`].
+    pub fn new_large_list(data_type: DataType, nullable: bool) -> Self {
+        DataType::LargeList(Arc::new(Field::new_list_field(data_type, 
nullable)))
+    }
+
+    /// Create a [`DataType::FixedSizeList`] with elements of the specified 
type, size
+    /// and nullability, and conventionally named inner [`Field`] (`"item"`).
+    ///
+    /// To specify field level metadata, construct the inner [`Field`]
+    /// directly via [`Field::new`] or [`Field::new_list_field`].
+    pub fn new_fixed_size_list(data_type: DataType, size: i32, nullable: bool) 
-> Self {
+        DataType::FixedSizeList(Arc::new(Field::new_list_field(data_type, 
nullable)), size)
+    }
 }
 
 /// The maximum precision for [DataType::Decimal128] values
diff --git a/arrow-schema/src/field.rs b/arrow-schema/src/field.rs
index eebaf0e3c1..5cb2399f38 100644
--- a/arrow-schema/src/field.rs
+++ b/arrow-schema/src/field.rs
@@ -217,6 +217,21 @@ impl Field {
         Self::new(name, DataType::LargeList(value.into()), nullable)
     }
 
+    /// Create a new [`Field`] with [`DataType::FixedSizeList`]
+    ///
+    /// - `name`: the name of the [`DataType::FixedSizeList`] field
+    /// - `value`: the description of each list element
+    /// - `size`: the size of the fixed size list
+    /// - `nullable`: if the [`DataType::FixedSizeList`] array is nullable
+    pub fn new_fixed_size_list(
+        name: impl Into<String>,
+        value: impl Into<FieldRef>,
+        size: i32,
+        nullable: bool,
+    ) -> Self {
+        Self::new(name, DataType::FixedSizeList(value.into(), size), nullable)
+    }
+
     /// Create a new [`Field`] with [`DataType::Map`]
     ///
     /// - `name`: the name of the [`DataType::Map`] field
diff --git a/arrow-schema/src/fields.rs b/arrow-schema/src/fields.rs
index 400f42c59c..59b7e76c78 100644
--- a/arrow-schema/src/fields.rs
+++ b/arrow-schema/src/fields.rs
@@ -444,11 +444,7 @@ mod tests {
                 Field::new("floats", DataType::Struct(floats.clone()), true),
                 true,
             ),
-            Field::new(
-                "f",
-                DataType::FixedSizeList(Arc::new(Field::new("item", 
DataType::Int32, false)), 3),
-                false,
-            ),
+            Field::new_fixed_size_list("f", Field::new("item", 
DataType::Int32, false), 3, false),
             Field::new_map(
                 "g",
                 "entries",
diff --git a/arrow-select/src/filter.rs b/arrow-select/src/filter.rs
index ce51ecb58a..c365d0b841 100644
--- a/arrow-select/src/filter.rs
+++ b/arrow-select/src/filter.rs
@@ -1261,8 +1261,7 @@ mod tests {
             .add_buffer(Buffer::from_slice_ref([0, 1, 2, 3, 4, 5, 6, 7, 8]))
             .build()
             .unwrap();
-        let list_data_type =
-            DataType::FixedSizeList(Arc::new(Field::new("item", 
DataType::Int32, false)), 3);
+        let list_data_type = DataType::new_fixed_size_list(DataType::Int32, 3, 
false);
         let list_data = ArrayData::builder(list_data_type)
             .len(3)
             .add_child_data(value_data)
@@ -1318,8 +1317,7 @@ mod tests {
         bit_util::set_bit(&mut null_bits, 3);
         bit_util::set_bit(&mut null_bits, 4);
 
-        let list_data_type =
-            DataType::FixedSizeList(Arc::new(Field::new("item", 
DataType::Int32, false)), 2);
+        let list_data_type = DataType::new_fixed_size_list(DataType::Int32, 2, 
false);
         let list_data = ArrayData::builder(list_data_type)
             .len(5)
             .add_child_data(value_data)

Reply via email to