cj-zhukov commented on code in PR #16104:
URL: https://github.com/apache/datafusion/pull/16104#discussion_r2106088882


##########
datafusion/common/src/array_conversion.rs:
##########
@@ -0,0 +1,145 @@
+// 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::sync::Arc;
+
+use arrow::array::{ArrayRef, BooleanArray, Float32Array, Int32Array, 
StringArray};
+
+/// Converts a vector or array into an ArrayRef.
+pub trait IntoArrayRef {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef;
+}
+
+impl IntoArrayRef for Vec<i32> {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(Int32Array::from(*self))
+    }
+}
+
+impl IntoArrayRef for Vec<Option<i32>> {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(Int32Array::from(*self))
+    }
+}
+
+impl<const N: usize> IntoArrayRef for [i32; N] {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(Int32Array::from(Vec::from(*self)))
+    }
+}
+
+impl<const N: usize> IntoArrayRef for [Option<i32>; N] {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(Int32Array::from(Vec::from(*self)))
+    }
+}
+
+impl IntoArrayRef for Vec<f32> {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(Float32Array::from(*self))
+    }
+}
+
+impl IntoArrayRef for Vec<Option<f32>> {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(Float32Array::from(*self))
+    }
+}
+
+impl<const N: usize> IntoArrayRef for [f32; N] {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(Float32Array::from(Vec::from(*self)))
+    }
+}
+
+impl<const N: usize> IntoArrayRef for [Option<f32>; N] {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(Float32Array::from(Vec::from(*self)))
+    }
+}
+
+impl IntoArrayRef for Vec<&str> {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(StringArray::from(*self))
+    }
+}
+
+impl IntoArrayRef for Vec<Option<&str>> {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(StringArray::from(*self))
+    }
+}
+
+impl<const N: usize> IntoArrayRef for [&'static str; N] {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(StringArray::from(Vec::from(*self)))
+    }
+}
+
+impl<const N: usize> IntoArrayRef for [Option<&'static str>; N] {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(StringArray::from(Vec::from(*self)))
+    }
+}
+
+impl IntoArrayRef for Vec<String> {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(StringArray::from(*self))
+    }
+}
+
+impl IntoArrayRef for Vec<Option<String>> {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(StringArray::from(*self))
+    }
+}
+
+impl<const N: usize> IntoArrayRef for [String; N] {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(StringArray::from(Vec::from(*self)))
+    }
+}
+
+impl<const N: usize> IntoArrayRef for [Option<String>; N] {
+    fn into_array_ref(self: Box<Self>) -> ArrayRef {
+        Arc::new(StringArray::from(Vec::from(*self)))
+    }

Review Comment:
   Great point! I'm going to try to reuse it. 



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to