arrow_udf_python/
into_field.rs

1// Copyright 2024 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use arrow_schema::{DataType, Field};
16
17/// Converts a type into a [`Field`].
18/// Implementors are [`DataType`] and [`Field`].
19pub trait IntoField: private::Sealed {
20    /// Converts into a [`Field`].
21    ///
22    /// - For [`Field`], it is returned as is.
23    /// - For [`DataType`], a new [`Field`] is created with the given `default_name`.
24    fn into_field(self, default_name: &str) -> Field;
25}
26
27impl IntoField for Field {
28    fn into_field(self, _default_name: &str) -> Field {
29        self
30    }
31}
32
33impl IntoField for DataType {
34    fn into_field(self, default_name: &str) -> Field {
35        Field::new(default_name, self, true)
36    }
37}
38
39mod private {
40    use arrow_schema::{DataType, Field};
41
42    pub trait Sealed {}
43    impl Sealed for Field {}
44    impl Sealed for DataType {}
45}