arrow_udf/
types.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
15//! Data types for user-defined functions.
16
17use arrow_array::builder::StructBuilder;
18use arrow_schema::Fields;
19pub use arrow_udf_macros::StructType;
20
21// re-export common types
22pub use chrono;
23#[doc(no_inline)]
24pub use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
25pub use rust_decimal;
26#[doc(no_inline)]
27pub use rust_decimal::Decimal;
28pub use serde_json;
29
30/// Interval type.
31#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
32pub struct Interval {
33    pub months: i32,
34    pub days: i32,
35    pub nanos: i64,
36}
37
38/// A trait for user-defined struct types.
39///
40/// This trait can be automatically derived with [`#[derive(StructType)]`](derive@StructType).
41pub trait StructType {
42    /// Returns the fields of the struct type.
43    fn fields() -> Fields;
44    /// Appends the struct value to the builder.
45    fn append_to(self, builder: &mut StructBuilder);
46    /// Appends a null value to the builder.
47    fn append_null(builder: &mut StructBuilder);
48}