From 5b00cccc1f18e585c94de948ed3f7061db69bd20 Mon Sep 17 00:00:00 2001 From: universalmind303 Date: Tue, 2 Apr 2024 13:16:01 -0500 Subject: [PATCH] refactor: make all udf function impls public (#9903) * refactor: make all udf function impls public * clippy --- datafusion/functions-array/src/array_has.rs | 24 +- datafusion/functions-array/src/concat.rs | 24 +- datafusion/functions-array/src/lib.rs | 44 +- datafusion/functions-array/src/make_array.rs | 6 + datafusion/functions-array/src/udf.rs | 828 ++++++++++++++++++ datafusion/functions/src/core/arrow_cast.rs | 8 +- datafusion/functions/src/core/arrowtypeof.rs | 8 +- datafusion/functions/src/core/getfield.rs | 8 +- datafusion/functions/src/core/mod.rs | 14 +- datafusion/functions/src/core/nullif.rs | 8 +- datafusion/functions/src/core/nvl.rs | 8 +- datafusion/functions/src/core/nvl2.rs | 8 +- datafusion/functions/src/core/struct.rs | 8 +- datafusion/functions/src/crypto/digest.rs | 8 +- datafusion/functions/src/crypto/md5.rs | 8 +- datafusion/functions/src/crypto/sha224.rs | 8 +- datafusion/functions/src/crypto/sha256.rs | 8 +- datafusion/functions/src/crypto/sha384.rs | 8 +- datafusion/functions/src/crypto/sha512.rs | 8 +- .../functions/src/datetime/current_date.rs | 8 +- .../functions/src/datetime/current_time.rs | 8 +- datafusion/functions/src/datetime/date_bin.rs | 8 +- .../functions/src/datetime/date_part.rs | 8 +- .../functions/src/datetime/date_trunc.rs | 8 +- .../functions/src/datetime/from_unixtime.rs | 8 +- .../functions/src/datetime/make_date.rs | 8 +- datafusion/functions/src/datetime/mod.rs | 26 +- datafusion/functions/src/datetime/now.rs | 8 +- datafusion/functions/src/datetime/to_char.rs | 8 +- datafusion/functions/src/datetime/to_date.rs | 8 +- .../functions/src/datetime/to_timestamp.rs | 40 +- .../functions/src/datetime/to_unixtime.rs | 8 +- datafusion/functions/src/encoding/inner.rs | 16 +- datafusion/functions/src/encoding/mod.rs | 2 +- datafusion/functions/src/math/abs.rs | 8 +- datafusion/functions/src/math/mod.rs | 4 +- datafusion/functions/src/math/nans.rs | 8 +- datafusion/functions/src/regex/regexplike.rs | 8 +- datafusion/functions/src/regex/regexpmatch.rs | 8 +- .../functions/src/regex/regexpreplace.rs | 8 +- datafusion/functions/src/string/ascii.rs | 2 +- datafusion/functions/src/string/bit_length.rs | 2 +- datafusion/functions/src/string/btrim.rs | 2 +- datafusion/functions/src/string/chr.rs | 2 +- .../functions/src/string/levenshtein.rs | 2 +- datafusion/functions/src/string/lower.rs | 2 +- datafusion/functions/src/string/ltrim.rs | 2 +- .../functions/src/string/octet_length.rs | 2 +- datafusion/functions/src/string/overlay.rs | 2 +- datafusion/functions/src/string/repeat.rs | 2 +- datafusion/functions/src/string/replace.rs | 2 +- datafusion/functions/src/string/rtrim.rs | 2 +- datafusion/functions/src/string/split_part.rs | 2 +- .../functions/src/string/starts_with.rs | 2 +- datafusion/functions/src/string/to_hex.rs | 2 +- datafusion/functions/src/string/upper.rs | 2 +- datafusion/functions/src/string/uuid.rs | 2 +- .../functions/src/unicode/character_length.rs | 2 +- 58 files changed, 1191 insertions(+), 105 deletions(-) create mode 100644 datafusion/functions-array/src/udf.rs diff --git a/datafusion/functions-array/src/array_has.rs b/datafusion/functions-array/src/array_has.rs index 4e4ebaf035fc..ee064335c1cc 100644 --- a/datafusion/functions-array/src/array_has.rs +++ b/datafusion/functions-array/src/array_has.rs @@ -54,11 +54,17 @@ make_udf_function!(ArrayHasAny, ); #[derive(Debug)] -pub(super) struct ArrayHas { +pub struct ArrayHas { signature: Signature, aliases: Vec, } +impl Default for ArrayHas { + fn default() -> Self { + Self::new() + } +} + impl ArrayHas { pub fn new() -> Self { Self { @@ -121,11 +127,17 @@ impl ScalarUDFImpl for ArrayHas { } #[derive(Debug)] -pub(super) struct ArrayHasAll { +pub struct ArrayHasAll { signature: Signature, aliases: Vec, } +impl Default for ArrayHasAll { + fn default() -> Self { + Self::new() + } +} + impl ArrayHasAll { pub fn new() -> Self { Self { @@ -178,11 +190,17 @@ impl ScalarUDFImpl for ArrayHasAll { } #[derive(Debug)] -pub(super) struct ArrayHasAny { +pub struct ArrayHasAny { signature: Signature, aliases: Vec, } +impl Default for ArrayHasAny { + fn default() -> Self { + Self::new() + } +} + impl ArrayHasAny { pub fn new() -> Self { Self { diff --git a/datafusion/functions-array/src/concat.rs b/datafusion/functions-array/src/concat.rs index cb76192e29c2..f9d9bf4356ff 100644 --- a/datafusion/functions-array/src/concat.rs +++ b/datafusion/functions-array/src/concat.rs @@ -45,11 +45,17 @@ make_udf_function!( ); #[derive(Debug)] -pub(super) struct ArrayAppend { +pub struct ArrayAppend { signature: Signature, aliases: Vec, } +impl Default for ArrayAppend { + fn default() -> Self { + Self::new() + } +} + impl ArrayAppend { pub fn new() -> Self { Self { @@ -99,11 +105,17 @@ make_udf_function!( ); #[derive(Debug)] -pub(super) struct ArrayPrepend { +pub struct ArrayPrepend { signature: Signature, aliases: Vec, } +impl Default for ArrayPrepend { + fn default() -> Self { + Self::new() + } +} + impl ArrayPrepend { pub fn new() -> Self { Self { @@ -152,11 +164,17 @@ make_udf_function!( ); #[derive(Debug)] -pub(super) struct ArrayConcat { +pub struct ArrayConcat { signature: Signature, aliases: Vec, } +impl Default for ArrayConcat { + fn default() -> Self { + Self::new() + } +} + impl ArrayConcat { pub fn new() -> Self { Self { diff --git a/datafusion/functions-array/src/lib.rs b/datafusion/functions-array/src/lib.rs index 7c261f958bf0..5914736773b7 100644 --- a/datafusion/functions-array/src/lib.rs +++ b/datafusion/functions-array/src/lib.rs @@ -28,28 +28,28 @@ #[macro_use] pub mod macros; -mod array_has; -mod cardinality; -mod concat; -mod dimension; -mod empty; -mod except; -mod extract; -mod flatten; -mod length; -mod make_array; -mod position; -mod range; -mod remove; -mod repeat; -mod replace; -mod resize; -mod reverse; -mod rewrite; -mod set_ops; -mod sort; -mod string; -mod utils; +pub mod array_has; +pub mod cardinality; +pub mod concat; +pub mod dimension; +pub mod empty; +pub mod except; +pub mod extract; +pub mod flatten; +pub mod length; +pub mod make_array; +pub mod position; +pub mod range; +pub mod remove; +pub mod repeat; +pub mod replace; +pub mod resize; +pub mod reverse; +pub mod rewrite; +pub mod set_ops; +pub mod sort; +pub mod string; +pub mod utils; use datafusion_common::Result; use datafusion_execution::FunctionRegistry; diff --git a/datafusion/functions-array/src/make_array.rs b/datafusion/functions-array/src/make_array.rs index 8eaae09f28f5..0439a736ee42 100644 --- a/datafusion/functions-array/src/make_array.rs +++ b/datafusion/functions-array/src/make_array.rs @@ -48,6 +48,12 @@ pub struct MakeArray { aliases: Vec, } +impl Default for MakeArray { + fn default() -> Self { + Self::new() + } +} + impl MakeArray { pub fn new() -> Self { Self { diff --git a/datafusion/functions-array/src/udf.rs b/datafusion/functions-array/src/udf.rs new file mode 100644 index 000000000000..1462b3efad33 --- /dev/null +++ b/datafusion/functions-array/src/udf.rs @@ -0,0 +1,828 @@ +// 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. + +//! [`ScalarUDFImpl`] definitions for array functions. + +use arrow::array::{NullArray, StringArray}; +use arrow::datatypes::DataType; +use arrow::datatypes::Field; +use arrow::datatypes::IntervalUnit::MonthDayNano; +use arrow_schema::DataType::{LargeUtf8, List, Utf8}; +use datafusion_common::exec_err; +use datafusion_common::plan_err; +use datafusion_common::Result; +use datafusion_expr::expr::ScalarFunction; +use datafusion_expr::Expr; +use datafusion_expr::TypeSignature; +use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility}; +use std::any::Any; +use std::sync::Arc; + +// Create static instances of ScalarUDFs for each function +make_udf_function!(ArrayToString, + array_to_string, + array delimiter, // arg name + "converts each element to its text representation.", // doc + array_to_string_udf // internal function name +); +#[derive(Debug)] +pub struct ArrayToString { + signature: Signature, + aliases: Vec, +} + +impl ArrayToString { + pub fn new() -> Self { + Self { + signature: Signature::variadic_any(Volatility::Immutable), + aliases: vec![ + String::from("array_to_string"), + String::from("list_to_string"), + String::from("array_join"), + String::from("list_join"), + ], + } + } +} + +impl ScalarUDFImpl for ArrayToString { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "array_to_string" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result { + use DataType::*; + Ok(match arg_types[0] { + List(_) | LargeList(_) | FixedSizeList(_, _) => Utf8, + _ => { + return plan_err!("The array_to_string function can only accept List/LargeList/FixedSizeList."); + } + }) + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result { + let args = ColumnarValue::values_to_arrays(args)?; + crate::kernels::array_to_string(&args).map(ColumnarValue::Array) + } + + fn aliases(&self) -> &[String] { + &self.aliases + } +} + +make_udf_function!(StringToArray, + string_to_array, + string delimiter null_string, // arg name + "splits a `string` based on a `delimiter` and returns an array of parts. Any parts matching the optional `null_string` will be replaced with `NULL`", // doc + string_to_array_udf // internal function name +); +#[derive(Debug)] +pub struct StringToArray { + signature: Signature, + aliases: Vec, +} + +impl StringToArray { + pub fn new() -> Self { + Self { + signature: Signature::variadic_any(Volatility::Immutable), + aliases: vec![ + String::from("string_to_array"), + String::from("string_to_list"), + ], + } + } +} + +impl ScalarUDFImpl for StringToArray { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "string_to_array" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result { + use DataType::*; + Ok(match arg_types[0] { + Utf8 | LargeUtf8 => { + List(Arc::new(Field::new("item", arg_types[0].clone(), true))) + } + _ => { + return plan_err!( + "The string_to_array function can only accept Utf8 or LargeUtf8." + ); + } + }) + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result { + let mut args = ColumnarValue::values_to_arrays(args)?; + // Case: delimiter is NULL, needs to be handled as well. + if args[1].as_any().is::() { + args[1] = Arc::new(StringArray::new_null(args[1].len())); + }; + + match args[0].data_type() { + Utf8 => { + crate::kernels::string_to_array::(&args).map(ColumnarValue::Array) + } + LargeUtf8 => { + crate::kernels::string_to_array::(&args).map(ColumnarValue::Array) + } + other => { + exec_err!("unsupported type for string_to_array function as {other}") + } + } + } + + fn aliases(&self) -> &[String] { + &self.aliases + } +} + +make_udf_function!( + Range, + range, + start stop step, + "create a list of values in the range between start and stop", + range_udf +); +#[derive(Debug)] +pub struct Range { + signature: Signature, + aliases: Vec, +} +impl Range { + pub fn new() -> Self { + use DataType::*; + Self { + signature: Signature::one_of( + vec![ + TypeSignature::Exact(vec![Int64]), + TypeSignature::Exact(vec![Int64, Int64]), + TypeSignature::Exact(vec![Int64, Int64, Int64]), + TypeSignature::Exact(vec![Date32, Date32, Interval(MonthDayNano)]), + ], + Volatility::Immutable, + ), + aliases: vec![String::from("range")], + } + } +} +impl ScalarUDFImpl for Range { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "range" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result { + use DataType::*; + Ok(List(Arc::new(Field::new( + "item", + arg_types[0].clone(), + true, + )))) + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result { + let args = ColumnarValue::values_to_arrays(args)?; + match args[0].data_type() { + arrow::datatypes::DataType::Int64 => { + crate::kernels::gen_range(&args, false).map(ColumnarValue::Array) + } + arrow::datatypes::DataType::Date32 => { + crate::kernels::gen_range_date(&args, false).map(ColumnarValue::Array) + } + _ => { + exec_err!("unsupported type for range") + } + } + } + + fn aliases(&self) -> &[String] { + &self.aliases + } +} + +make_udf_function!( + GenSeries, + gen_series, + start stop step, + "create a list of values in the range between start and stop, include upper bound", + gen_series_udf +); +#[derive(Debug)] +pub struct GenSeries { + signature: Signature, + aliases: Vec, +} +impl GenSeries { + pub fn new() -> Self { + use DataType::*; + Self { + signature: Signature::one_of( + vec![ + TypeSignature::Exact(vec![Int64]), + TypeSignature::Exact(vec![Int64, Int64]), + TypeSignature::Exact(vec![Int64, Int64, Int64]), + TypeSignature::Exact(vec![Date32, Date32, Interval(MonthDayNano)]), + ], + Volatility::Immutable, + ), + aliases: vec![String::from("generate_series")], + } + } +} +impl ScalarUDFImpl for GenSeries { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "generate_series" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result { + use DataType::*; + Ok(List(Arc::new(Field::new( + "item", + arg_types[0].clone(), + true, + )))) + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result { + let args = ColumnarValue::values_to_arrays(args)?; + match args[0].data_type() { + arrow::datatypes::DataType::Int64 => { + crate::kernels::gen_range(&args, true).map(ColumnarValue::Array) + } + arrow::datatypes::DataType::Date32 => { + crate::kernels::gen_range_date(&args, true).map(ColumnarValue::Array) + } + _ => { + exec_err!("unsupported type for range") + } + } + } + + fn aliases(&self) -> &[String] { + &self.aliases + } +} + +make_udf_function!( + ArrayDims, + array_dims, + array, + "returns an array of the array's dimensions.", + array_dims_udf +); + +#[derive(Debug)] +pub struct ArrayDims { + signature: Signature, + aliases: Vec, +} + +impl ArrayDims { + pub fn new() -> Self { + Self { + signature: Signature::array(Volatility::Immutable), + aliases: vec!["array_dims".to_string(), "list_dims".to_string()], + } + } +} + +impl ScalarUDFImpl for ArrayDims { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "array_dims" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result { + use DataType::*; + Ok(match arg_types[0] { + List(_) | LargeList(_) | FixedSizeList(_, _) => { + List(Arc::new(Field::new("item", UInt64, true))) + } + _ => { + return plan_err!("The array_dims function can only accept List/LargeList/FixedSizeList."); + } + }) + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result { + let args = ColumnarValue::values_to_arrays(args)?; + crate::kernels::array_dims(&args).map(ColumnarValue::Array) + } + + fn aliases(&self) -> &[String] { + &self.aliases + } +} + +make_udf_function!( + ArraySort, + array_sort, + array desc null_first, + "returns sorted array.", + array_sort_udf +); + +#[derive(Debug)] +pub struct ArraySort { + signature: Signature, + aliases: Vec, +} + +impl ArraySort { + pub fn new() -> Self { + Self { + signature: Signature::variadic_any(Volatility::Immutable), + aliases: vec!["array_sort".to_string(), "list_sort".to_string()], + } + } +} + +impl ScalarUDFImpl for ArraySort { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "array_sort" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result { + use DataType::*; + match &arg_types[0] { + List(field) | FixedSizeList(field, _) => Ok(List(Arc::new(Field::new( + "item", + field.data_type().clone(), + true, + )))), + LargeList(field) => Ok(LargeList(Arc::new(Field::new( + "item", + field.data_type().clone(), + true, + )))), + _ => exec_err!( + "Not reachable, data_type should be List, LargeList or FixedSizeList" + ), + } + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result { + let args = ColumnarValue::values_to_arrays(args)?; + crate::kernels::array_sort(&args).map(ColumnarValue::Array) + } + + fn aliases(&self) -> &[String] { + &self.aliases + } +} + +make_udf_function!( + Cardinality, + cardinality, + array, + "returns the total number of elements in the array.", + cardinality_udf +); + +impl Cardinality { + pub fn new() -> Self { + Self { + signature: Signature::array(Volatility::Immutable), + aliases: vec![String::from("cardinality")], + } + } +} + +#[derive(Debug)] +pub struct Cardinality { + signature: Signature, + aliases: Vec, +} +impl ScalarUDFImpl for Cardinality { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "cardinality" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result { + use DataType::*; + Ok(match arg_types[0] { + List(_) | LargeList(_) | FixedSizeList(_, _) => UInt64, + _ => { + return plan_err!("The cardinality function can only accept List/LargeList/FixedSizeList."); + } + }) + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result { + let args = ColumnarValue::values_to_arrays(args)?; + crate::kernels::cardinality(&args).map(ColumnarValue::Array) + } + + fn aliases(&self) -> &[String] { + &self.aliases + } +} + +make_udf_function!( + ArrayNdims, + array_ndims, + array, + "returns the number of dimensions of the array.", + array_ndims_udf +); + +#[derive(Debug)] +pub struct ArrayNdims { + signature: Signature, + aliases: Vec, +} +impl ArrayNdims { + pub fn new() -> Self { + Self { + signature: Signature::array(Volatility::Immutable), + aliases: vec![String::from("array_ndims"), String::from("list_ndims")], + } + } +} + +impl ScalarUDFImpl for ArrayNdims { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "array_ndims" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result { + use DataType::*; + Ok(match arg_types[0] { + List(_) | LargeList(_) | FixedSizeList(_, _) => UInt64, + _ => { + return plan_err!("The array_ndims function can only accept List/LargeList/FixedSizeList."); + } + }) + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result { + let args = ColumnarValue::values_to_arrays(args)?; + crate::kernels::array_ndims(&args).map(ColumnarValue::Array) + } + + fn aliases(&self) -> &[String] { + &self.aliases + } +} + +make_udf_function!( + ArrayEmpty, + array_empty, + array, + "returns true for an empty array or false for a non-empty array.", + array_empty_udf +); + +#[derive(Debug)] +pub struct ArrayEmpty { + signature: Signature, + aliases: Vec, +} +impl ArrayEmpty { + pub fn new() -> Self { + Self { + signature: Signature::array(Volatility::Immutable), + aliases: vec![String::from("empty")], + } + } +} + +impl ScalarUDFImpl for ArrayEmpty { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "empty" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result { + use DataType::*; + Ok(match arg_types[0] { + List(_) | LargeList(_) | FixedSizeList(_, _) => Boolean, + _ => { + return plan_err!("The array_empty function can only accept List/LargeList/FixedSizeList."); + } + }) + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result { + let args = ColumnarValue::values_to_arrays(args)?; + crate::kernels::array_empty(&args).map(ColumnarValue::Array) + } + + fn aliases(&self) -> &[String] { + &self.aliases + } +} + +make_udf_function!( + ArrayRepeat, + array_repeat, + element count, // arg name + "returns an array containing element `count` times.", // doc + array_repeat_udf // internal function name +); +#[derive(Debug)] +pub struct ArrayRepeat { + signature: Signature, + aliases: Vec, +} + +impl ArrayRepeat { + pub fn new() -> Self { + Self { + signature: Signature::variadic_any(Volatility::Immutable), + aliases: vec![String::from("array_repeat"), String::from("list_repeat")], + } + } +} + +impl ScalarUDFImpl for ArrayRepeat { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "array_repeat" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result { + Ok(List(Arc::new(Field::new( + "item", + arg_types[0].clone(), + true, + )))) + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result { + let args = ColumnarValue::values_to_arrays(args)?; + crate::kernels::array_repeat(&args).map(ColumnarValue::Array) + } + + fn aliases(&self) -> &[String] { + &self.aliases + } +} + +make_udf_function!( + ArrayLength, + array_length, + array, + "returns the length of the array dimension.", + array_length_udf +); + +#[derive(Debug)] +pub struct ArrayLength { + signature: Signature, + aliases: Vec, +} +impl ArrayLength { + pub fn new() -> Self { + Self { + signature: Signature::variadic_any(Volatility::Immutable), + aliases: vec![String::from("array_length"), String::from("list_length")], + } + } +} + +impl ScalarUDFImpl for ArrayLength { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "array_length" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result { + use DataType::*; + Ok(match arg_types[0] { + List(_) | LargeList(_) | FixedSizeList(_, _) => UInt64, + _ => { + return plan_err!("The array_length function can only accept List/LargeList/FixedSizeList."); + } + }) + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result { + let args = ColumnarValue::values_to_arrays(args)?; + crate::kernels::array_length(&args).map(ColumnarValue::Array) + } + + fn aliases(&self) -> &[String] { + &self.aliases + } +} + +make_udf_function!( + Flatten, + flatten, + array, + "flattens an array of arrays into a single array.", + flatten_udf +); + +#[derive(Debug)] +pub struct Flatten { + signature: Signature, + aliases: Vec, +} +impl Flatten { + pub fn new() -> Self { + Self { + signature: Signature::array(Volatility::Immutable), + aliases: vec![String::from("flatten")], + } + } +} + +impl ScalarUDFImpl for Flatten { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "flatten" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result { + use DataType::*; + fn get_base_type(data_type: &DataType) -> Result { + match data_type { + List(field) | FixedSizeList(field, _) + if matches!(field.data_type(), List(_) | FixedSizeList(_, _)) => + { + get_base_type(field.data_type()) + } + LargeList(field) if matches!(field.data_type(), LargeList(_)) => { + get_base_type(field.data_type()) + } + Null | List(_) | LargeList(_) => Ok(data_type.to_owned()), + FixedSizeList(field, _) => Ok(List(field.clone())), + _ => exec_err!( + "Not reachable, data_type should be List, LargeList or FixedSizeList" + ), + } + } + + let data_type = get_base_type(&arg_types[0])?; + Ok(data_type) + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result { + let args = ColumnarValue::values_to_arrays(args)?; + crate::kernels::flatten(&args).map(ColumnarValue::Array) + } + + fn aliases(&self) -> &[String] { + &self.aliases + } +} + +make_udf_function!( + ArrayDistinct, + array_distinct, + array, + "return distinct values from the array after removing duplicates.", + array_distinct_udf +); + +#[derive(Debug)] +pub struct ArrayDistinct { + signature: Signature, + aliases: Vec, +} + +impl crate::udf::ArrayDistinct { + pub fn new() -> Self { + Self { + signature: Signature::array(Volatility::Immutable), + aliases: vec!["array_distinct".to_string(), "list_distinct".to_string()], + } + } +} + +impl ScalarUDFImpl for crate::udf::ArrayDistinct { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "array_distinct" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result { + use DataType::*; + match &arg_types[0] { + List(field) | FixedSizeList(field, _) => Ok(List(Arc::new(Field::new( + "item", + field.data_type().clone(), + true, + )))), + LargeList(field) => Ok(LargeList(Arc::new(Field::new( + "item", + field.data_type().clone(), + true, + )))), + _ => exec_err!( + "Not reachable, data_type should be List, LargeList or FixedSizeList" + ), + } + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result { + let args = ColumnarValue::values_to_arrays(args)?; + crate::kernels::array_distinct(&args).map(ColumnarValue::Array) + } + + fn aliases(&self) -> &[String] { + &self.aliases + } +} diff --git a/datafusion/functions/src/core/arrow_cast.rs b/datafusion/functions/src/core/arrow_cast.rs index b6c1b5eb9a38..d641389e0ae3 100644 --- a/datafusion/functions/src/core/arrow_cast.rs +++ b/datafusion/functions/src/core/arrow_cast.rs @@ -51,10 +51,16 @@ use datafusion_expr::{ColumnarValue, Expr, ScalarUDFImpl, Signature, Volatility} /// select arrow_cast(column_x, 'Float64') /// ``` #[derive(Debug)] -pub(super) struct ArrowCastFunc { +pub struct ArrowCastFunc { signature: Signature, } +impl Default for ArrowCastFunc { + fn default() -> Self { + Self::new() + } +} + impl ArrowCastFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/core/arrowtypeof.rs b/datafusion/functions/src/core/arrowtypeof.rs index 89702d3267ec..cc5e7e619bd8 100644 --- a/datafusion/functions/src/core/arrowtypeof.rs +++ b/datafusion/functions/src/core/arrowtypeof.rs @@ -22,10 +22,16 @@ use datafusion_expr::{ScalarUDFImpl, Signature, Volatility}; use std::any::Any; #[derive(Debug)] -pub(super) struct ArrowTypeOfFunc { +pub struct ArrowTypeOfFunc { signature: Signature, } +impl Default for ArrowTypeOfFunc { + fn default() -> Self { + Self::new() + } +} + impl ArrowTypeOfFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/core/getfield.rs b/datafusion/functions/src/core/getfield.rs index e6313423867a..b00b8ea553f2 100644 --- a/datafusion/functions/src/core/getfield.rs +++ b/datafusion/functions/src/core/getfield.rs @@ -25,10 +25,16 @@ use datafusion_expr::{ScalarUDFImpl, Signature, Volatility}; use std::any::Any; #[derive(Debug)] -pub(super) struct GetFieldFunc { +pub struct GetFieldFunc { signature: Signature, } +impl Default for GetFieldFunc { + fn default() -> Self { + Self::new() + } +} + impl GetFieldFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/core/mod.rs b/datafusion/functions/src/core/mod.rs index 5a0bd2c77f63..0d212d289b85 100644 --- a/datafusion/functions/src/core/mod.rs +++ b/datafusion/functions/src/core/mod.rs @@ -17,13 +17,13 @@ //! "core" DataFusion functions -mod arrow_cast; -mod arrowtypeof; -mod getfield; -mod nullif; -mod nvl; -mod nvl2; -mod r#struct; +pub mod arrow_cast; +pub mod arrowtypeof; +pub mod getfield; +pub mod nullif; +pub mod nvl; +pub mod nvl2; +pub mod r#struct; // create UDFs make_udf_function!(arrow_cast::ArrowCastFunc, ARROW_CAST, arrow_cast); diff --git a/datafusion/functions/src/core/nullif.rs b/datafusion/functions/src/core/nullif.rs index 1e903d7a881d..dc9696bd8d72 100644 --- a/datafusion/functions/src/core/nullif.rs +++ b/datafusion/functions/src/core/nullif.rs @@ -27,7 +27,7 @@ use datafusion_expr::{ScalarUDFImpl, Signature, Volatility}; use std::any::Any; #[derive(Debug)] -pub(super) struct NullIfFunc { +pub struct NullIfFunc { signature: Signature, } @@ -50,6 +50,12 @@ static SUPPORTED_NULLIF_TYPES: &[DataType] = &[ DataType::LargeUtf8, ]; +impl Default for NullIfFunc { + fn default() -> Self { + Self::new() + } +} + impl NullIfFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/core/nvl.rs b/datafusion/functions/src/core/nvl.rs index 76b037eb81ba..274e36fbdecc 100644 --- a/datafusion/functions/src/core/nvl.rs +++ b/datafusion/functions/src/core/nvl.rs @@ -23,7 +23,7 @@ use datafusion_common::{internal_err, Result}; use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility}; #[derive(Debug)] -pub(super) struct NVLFunc { +pub struct NVLFunc { signature: Signature, aliases: Vec, } @@ -47,6 +47,12 @@ static SUPPORTED_NVL_TYPES: &[DataType] = &[ DataType::LargeUtf8, ]; +impl Default for NVLFunc { + fn default() -> Self { + Self::new() + } +} + impl NVLFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/core/nvl2.rs b/datafusion/functions/src/core/nvl2.rs index a65657eaeafd..66b9ef566a78 100644 --- a/datafusion/functions/src/core/nvl2.rs +++ b/datafusion/functions/src/core/nvl2.rs @@ -23,10 +23,16 @@ use datafusion_common::{internal_err, plan_datafusion_err, Result}; use datafusion_expr::{utils, ColumnarValue, ScalarUDFImpl, Signature, Volatility}; #[derive(Debug)] -pub(super) struct NVL2Func { +pub struct NVL2Func { signature: Signature, } +impl Default for NVL2Func { + fn default() -> Self { + Self::new() + } +} + impl NVL2Func { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/core/struct.rs b/datafusion/functions/src/core/struct.rs index ac300e0abde3..9d4b2e4a0b8b 100644 --- a/datafusion/functions/src/core/struct.rs +++ b/datafusion/functions/src/core/struct.rs @@ -54,10 +54,16 @@ fn struct_expr(args: &[ColumnarValue]) -> Result { Ok(ColumnarValue::Array(array_struct(arrays.as_slice())?)) } #[derive(Debug)] -pub(super) struct StructFunc { +pub struct StructFunc { signature: Signature, } +impl Default for StructFunc { + fn default() -> Self { + Self::new() + } +} + impl StructFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/crypto/digest.rs b/datafusion/functions/src/crypto/digest.rs index c6556787cb9c..c9dd3c1f56a2 100644 --- a/datafusion/functions/src/crypto/digest.rs +++ b/datafusion/functions/src/crypto/digest.rs @@ -25,9 +25,15 @@ use datafusion_expr::{ use std::any::Any; #[derive(Debug)] -pub(super) struct DigestFunc { +pub struct DigestFunc { signature: Signature, } +impl Default for DigestFunc { + fn default() -> Self { + Self::new() + } +} + impl DigestFunc { pub fn new() -> Self { use DataType::*; diff --git a/datafusion/functions/src/crypto/md5.rs b/datafusion/functions/src/crypto/md5.rs index 7b2936a37938..ccb6fbba80aa 100644 --- a/datafusion/functions/src/crypto/md5.rs +++ b/datafusion/functions/src/crypto/md5.rs @@ -23,9 +23,15 @@ use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility}; use std::any::Any; #[derive(Debug)] -pub(super) struct Md5Func { +pub struct Md5Func { signature: Signature, } +impl Default for Md5Func { + fn default() -> Self { + Self::new() + } +} + impl Md5Func { pub fn new() -> Self { use DataType::*; diff --git a/datafusion/functions/src/crypto/sha224.rs b/datafusion/functions/src/crypto/sha224.rs index ef0fae97cfa5..2795c4a25004 100644 --- a/datafusion/functions/src/crypto/sha224.rs +++ b/datafusion/functions/src/crypto/sha224.rs @@ -23,9 +23,15 @@ use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility}; use std::any::Any; #[derive(Debug)] -pub(super) struct SHA224Func { +pub struct SHA224Func { signature: Signature, } +impl Default for SHA224Func { + fn default() -> Self { + Self::new() + } +} + impl SHA224Func { pub fn new() -> Self { use DataType::*; diff --git a/datafusion/functions/src/crypto/sha256.rs b/datafusion/functions/src/crypto/sha256.rs index f763f925cc56..0a3f3b26e431 100644 --- a/datafusion/functions/src/crypto/sha256.rs +++ b/datafusion/functions/src/crypto/sha256.rs @@ -23,9 +23,15 @@ use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility}; use std::any::Any; #[derive(Debug)] -pub(super) struct SHA256Func { +pub struct SHA256Func { signature: Signature, } +impl Default for SHA256Func { + fn default() -> Self { + Self::new() + } +} + impl SHA256Func { pub fn new() -> Self { use DataType::*; diff --git a/datafusion/functions/src/crypto/sha384.rs b/datafusion/functions/src/crypto/sha384.rs index b382d42663be..c3f7845ce7bd 100644 --- a/datafusion/functions/src/crypto/sha384.rs +++ b/datafusion/functions/src/crypto/sha384.rs @@ -23,9 +23,15 @@ use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility}; use std::any::Any; #[derive(Debug)] -pub(super) struct SHA384Func { +pub struct SHA384Func { signature: Signature, } +impl Default for SHA384Func { + fn default() -> Self { + Self::new() + } +} + impl SHA384Func { pub fn new() -> Self { use DataType::*; diff --git a/datafusion/functions/src/crypto/sha512.rs b/datafusion/functions/src/crypto/sha512.rs index a852376fadd6..dc3bfac9d8bd 100644 --- a/datafusion/functions/src/crypto/sha512.rs +++ b/datafusion/functions/src/crypto/sha512.rs @@ -23,9 +23,15 @@ use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility}; use std::any::Any; #[derive(Debug)] -pub(super) struct SHA512Func { +pub struct SHA512Func { signature: Signature, } +impl Default for SHA512Func { + fn default() -> Self { + Self::new() + } +} + impl SHA512Func { pub fn new() -> Self { use DataType::*; diff --git a/datafusion/functions/src/datetime/current_date.rs b/datafusion/functions/src/datetime/current_date.rs index 5338234a8e49..8b180ff41b91 100644 --- a/datafusion/functions/src/datetime/current_date.rs +++ b/datafusion/functions/src/datetime/current_date.rs @@ -26,11 +26,17 @@ use datafusion_expr::simplify::{ExprSimplifyResult, SimplifyInfo}; use datafusion_expr::{ColumnarValue, Expr, ScalarUDFImpl, Signature, Volatility}; #[derive(Debug)] -pub(super) struct CurrentDateFunc { +pub struct CurrentDateFunc { signature: Signature, aliases: Vec, } +impl Default for CurrentDateFunc { + fn default() -> Self { + Self::new() + } +} + impl CurrentDateFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/datetime/current_time.rs b/datafusion/functions/src/datetime/current_time.rs index b8a8aa2acb53..803759d4e904 100644 --- a/datafusion/functions/src/datetime/current_time.rs +++ b/datafusion/functions/src/datetime/current_time.rs @@ -26,10 +26,16 @@ use datafusion_expr::simplify::{ExprSimplifyResult, SimplifyInfo}; use datafusion_expr::{ColumnarValue, Expr, ScalarUDFImpl, Signature, Volatility}; #[derive(Debug)] -pub(super) struct CurrentTimeFunc { +pub struct CurrentTimeFunc { signature: Signature, } +impl Default for CurrentTimeFunc { + fn default() -> Self { + Self::new() + } +} + impl CurrentTimeFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/datetime/date_bin.rs b/datafusion/functions/src/datetime/date_bin.rs index b7f20f68e89c..7f5d9bb5d921 100644 --- a/datafusion/functions/src/datetime/date_bin.rs +++ b/datafusion/functions/src/datetime/date_bin.rs @@ -40,10 +40,16 @@ use datafusion_expr::{ }; #[derive(Debug)] -pub(super) struct DateBinFunc { +pub struct DateBinFunc { signature: Signature, } +impl Default for DateBinFunc { + fn default() -> Self { + Self::new() + } +} + impl DateBinFunc { pub fn new() -> Self { let base_sig = |array_type: TimeUnit| { diff --git a/datafusion/functions/src/datetime/date_part.rs b/datafusion/functions/src/datetime/date_part.rs index b41f7e13cff2..111cdabe2bfb 100644 --- a/datafusion/functions/src/datetime/date_part.rs +++ b/datafusion/functions/src/datetime/date_part.rs @@ -39,11 +39,17 @@ use datafusion_expr::{ }; #[derive(Debug)] -pub(super) struct DatePartFunc { +pub struct DatePartFunc { signature: Signature, aliases: Vec, } +impl Default for DatePartFunc { + fn default() -> Self { + Self::new() + } +} + impl DatePartFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/datetime/date_trunc.rs b/datafusion/functions/src/datetime/date_trunc.rs index b4b25666516d..0414bf9c2a26 100644 --- a/datafusion/functions/src/datetime/date_trunc.rs +++ b/datafusion/functions/src/datetime/date_trunc.rs @@ -45,11 +45,17 @@ use datafusion_expr::{ }; #[derive(Debug)] -pub(super) struct DateTruncFunc { +pub struct DateTruncFunc { signature: Signature, aliases: Vec, } +impl Default for DateTruncFunc { + fn default() -> Self { + Self::new() + } +} + impl DateTruncFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/datetime/from_unixtime.rs b/datafusion/functions/src/datetime/from_unixtime.rs index f0d5016c0db9..d36ebe735ee7 100644 --- a/datafusion/functions/src/datetime/from_unixtime.rs +++ b/datafusion/functions/src/datetime/from_unixtime.rs @@ -25,10 +25,16 @@ use datafusion_common::{exec_err, Result}; use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility}; #[derive(Debug)] -pub(super) struct FromUnixtimeFunc { +pub struct FromUnixtimeFunc { signature: Signature, } +impl Default for FromUnixtimeFunc { + fn default() -> Self { + Self::new() + } +} + impl FromUnixtimeFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/datetime/make_date.rs b/datafusion/functions/src/datetime/make_date.rs index 8afb36538363..6aa72572bc4d 100644 --- a/datafusion/functions/src/datetime/make_date.rs +++ b/datafusion/functions/src/datetime/make_date.rs @@ -30,10 +30,16 @@ use datafusion_common::{exec_err, Result, ScalarValue}; use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility}; #[derive(Debug)] -pub(super) struct MakeDateFunc { +pub struct MakeDateFunc { signature: Signature, } +impl Default for MakeDateFunc { + fn default() -> Self { + Self::new() + } +} + impl MakeDateFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/datetime/mod.rs b/datafusion/functions/src/datetime/mod.rs index a2dfc93b05a3..c6939976eb02 100644 --- a/datafusion/functions/src/datetime/mod.rs +++ b/datafusion/functions/src/datetime/mod.rs @@ -21,19 +21,19 @@ use std::sync::Arc; use datafusion_expr::ScalarUDF; -mod common; -mod current_date; -mod current_time; -mod date_bin; -mod date_part; -mod date_trunc; -mod from_unixtime; -mod make_date; -mod now; -mod to_char; -mod to_date; -mod to_timestamp; -mod to_unixtime; +pub mod common; +pub mod current_date; +pub mod current_time; +pub mod date_bin; +pub mod date_part; +pub mod date_trunc; +pub mod from_unixtime; +pub mod make_date; +pub mod now; +pub mod to_char; +pub mod to_date; +pub mod to_timestamp; +pub mod to_unixtime; // create UDFs make_udf_function!(current_date::CurrentDateFunc, CURRENT_DATE, current_date); diff --git a/datafusion/functions/src/datetime/now.rs b/datafusion/functions/src/datetime/now.rs index cc7979df0d86..b2221215b94b 100644 --- a/datafusion/functions/src/datetime/now.rs +++ b/datafusion/functions/src/datetime/now.rs @@ -26,10 +26,16 @@ use datafusion_expr::simplify::{ExprSimplifyResult, SimplifyInfo}; use datafusion_expr::{ColumnarValue, Expr, ScalarUDFImpl, Signature, Volatility}; #[derive(Debug)] -pub(super) struct NowFunc { +pub struct NowFunc { signature: Signature, } +impl Default for NowFunc { + fn default() -> Self { + Self::new() + } +} + impl NowFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/datetime/to_char.rs b/datafusion/functions/src/datetime/to_char.rs index ef5c45a5ad9c..f2e5af978ca0 100644 --- a/datafusion/functions/src/datetime/to_char.rs +++ b/datafusion/functions/src/datetime/to_char.rs @@ -35,11 +35,17 @@ use datafusion_expr::{ }; #[derive(Debug)] -pub(super) struct ToCharFunc { +pub struct ToCharFunc { signature: Signature, aliases: Vec, } +impl Default for ToCharFunc { + fn default() -> Self { + Self::new() + } +} + impl ToCharFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/datetime/to_date.rs b/datafusion/functions/src/datetime/to_date.rs index 077ad8f087b3..e491c0b55508 100644 --- a/datafusion/functions/src/datetime/to_date.rs +++ b/datafusion/functions/src/datetime/to_date.rs @@ -26,10 +26,16 @@ use datafusion_common::{exec_err, internal_datafusion_err, Result}; use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility}; #[derive(Debug)] -pub(super) struct ToDateFunc { +pub struct ToDateFunc { signature: Signature, } +impl Default for ToDateFunc { + fn default() -> Self { + Self::new() + } +} + impl ToDateFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/datetime/to_timestamp.rs b/datafusion/functions/src/datetime/to_timestamp.rs index b9cf8f3c604b..a7bcca62944c 100644 --- a/datafusion/functions/src/datetime/to_timestamp.rs +++ b/datafusion/functions/src/datetime/to_timestamp.rs @@ -30,30 +30,36 @@ use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility}; use crate::datetime::common::*; #[derive(Debug)] -pub(super) struct ToTimestampFunc { +pub struct ToTimestampFunc { signature: Signature, } #[derive(Debug)] -pub(super) struct ToTimestampSecondsFunc { +pub struct ToTimestampSecondsFunc { signature: Signature, } #[derive(Debug)] -pub(super) struct ToTimestampMillisFunc { +pub struct ToTimestampMillisFunc { signature: Signature, } #[derive(Debug)] -pub(super) struct ToTimestampMicrosFunc { +pub struct ToTimestampMicrosFunc { signature: Signature, } #[derive(Debug)] -pub(super) struct ToTimestampNanosFunc { +pub struct ToTimestampNanosFunc { signature: Signature, } +impl Default for ToTimestampFunc { + fn default() -> Self { + Self::new() + } +} + impl ToTimestampFunc { pub fn new() -> Self { Self { @@ -62,6 +68,12 @@ impl ToTimestampFunc { } } +impl Default for ToTimestampSecondsFunc { + fn default() -> Self { + Self::new() + } +} + impl ToTimestampSecondsFunc { pub fn new() -> Self { Self { @@ -70,6 +82,12 @@ impl ToTimestampSecondsFunc { } } +impl Default for ToTimestampMillisFunc { + fn default() -> Self { + Self::new() + } +} + impl ToTimestampMillisFunc { pub fn new() -> Self { Self { @@ -78,6 +96,12 @@ impl ToTimestampMillisFunc { } } +impl Default for ToTimestampMicrosFunc { + fn default() -> Self { + Self::new() + } +} + impl ToTimestampMicrosFunc { pub fn new() -> Self { Self { @@ -86,6 +110,12 @@ impl ToTimestampMicrosFunc { } } +impl Default for ToTimestampNanosFunc { + fn default() -> Self { + Self::new() + } +} + impl ToTimestampNanosFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/datetime/to_unixtime.rs b/datafusion/functions/src/datetime/to_unixtime.rs index ed56cdf8d0af..396dadccb4b3 100644 --- a/datafusion/functions/src/datetime/to_unixtime.rs +++ b/datafusion/functions/src/datetime/to_unixtime.rs @@ -26,10 +26,16 @@ use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility}; use super::to_timestamp::ToTimestampSecondsFunc; #[derive(Debug)] -pub(super) struct ToUnixtimeFunc { +pub struct ToUnixtimeFunc { signature: Signature, } +impl Default for ToUnixtimeFunc { + fn default() -> Self { + Self::new() + } +} + impl ToUnixtimeFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/encoding/inner.rs b/datafusion/functions/src/encoding/inner.rs index a49a64228d2f..d9ce299a2602 100644 --- a/datafusion/functions/src/encoding/inner.rs +++ b/datafusion/functions/src/encoding/inner.rs @@ -37,10 +37,16 @@ use datafusion_expr::{ScalarUDFImpl, Signature, Volatility}; use std::any::Any; #[derive(Debug)] -pub(super) struct EncodeFunc { +pub struct EncodeFunc { signature: Signature, } +impl Default for EncodeFunc { + fn default() -> Self { + Self::new() + } +} + impl EncodeFunc { pub fn new() -> Self { use DataType::*; @@ -91,10 +97,16 @@ impl ScalarUDFImpl for EncodeFunc { } #[derive(Debug)] -pub(super) struct DecodeFunc { +pub struct DecodeFunc { signature: Signature, } +impl Default for DecodeFunc { + fn default() -> Self { + Self::new() + } +} + impl DecodeFunc { pub fn new() -> Self { use DataType::*; diff --git a/datafusion/functions/src/encoding/mod.rs b/datafusion/functions/src/encoding/mod.rs index 9d9f07dff7ce..49f914a68774 100644 --- a/datafusion/functions/src/encoding/mod.rs +++ b/datafusion/functions/src/encoding/mod.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -mod inner; +pub mod inner; // create `encode` and `decode` UDFs make_udf_function!(inner::EncodeFunc, ENCODE, encode); diff --git a/datafusion/functions/src/math/abs.rs b/datafusion/functions/src/math/abs.rs index 8aa48460ff69..e05dc8665285 100644 --- a/datafusion/functions/src/math/abs.rs +++ b/datafusion/functions/src/math/abs.rs @@ -104,10 +104,16 @@ fn create_abs_function(input_data_type: &DataType) -> Result } } #[derive(Debug)] -pub(super) struct AbsFunc { +pub struct AbsFunc { signature: Signature, } +impl Default for AbsFunc { + fn default() -> Self { + Self::new() + } +} + impl AbsFunc { pub fn new() -> Self { Self { diff --git a/datafusion/functions/src/math/mod.rs b/datafusion/functions/src/math/mod.rs index 27deb7d68427..bad2c56c2f2f 100644 --- a/datafusion/functions/src/math/mod.rs +++ b/datafusion/functions/src/math/mod.rs @@ -17,8 +17,8 @@ //! "math" DataFusion functions -mod abs; -mod nans; +pub mod abs; +pub mod nans; // Create UDFs make_udf_function!(nans::IsNanFunc, ISNAN, isnan); diff --git a/datafusion/functions/src/math/nans.rs b/datafusion/functions/src/math/nans.rs index 3f3d7d197c33..2bd704a7de2e 100644 --- a/datafusion/functions/src/math/nans.rs +++ b/datafusion/functions/src/math/nans.rs @@ -28,10 +28,16 @@ use std::any::Any; use std::sync::Arc; #[derive(Debug)] -pub(super) struct IsNanFunc { +pub struct IsNanFunc { signature: Signature, } +impl Default for IsNanFunc { + fn default() -> Self { + Self::new() + } +} + impl IsNanFunc { pub fn new() -> Self { use DataType::*; diff --git a/datafusion/functions/src/regex/regexplike.rs b/datafusion/functions/src/regex/regexplike.rs index 94dd7529e8ff..09b96a28c107 100644 --- a/datafusion/functions/src/regex/regexplike.rs +++ b/datafusion/functions/src/regex/regexplike.rs @@ -32,9 +32,15 @@ use std::any::Any; use std::sync::Arc; #[derive(Debug)] -pub(super) struct RegexpLikeFunc { +pub struct RegexpLikeFunc { signature: Signature, } +impl Default for RegexpLikeFunc { + fn default() -> Self { + Self::new() + } +} + impl RegexpLikeFunc { pub fn new() -> Self { use DataType::*; diff --git a/datafusion/functions/src/regex/regexpmatch.rs b/datafusion/functions/src/regex/regexpmatch.rs index 5178188424fb..73228e608143 100644 --- a/datafusion/functions/src/regex/regexpmatch.rs +++ b/datafusion/functions/src/regex/regexpmatch.rs @@ -33,9 +33,15 @@ use std::any::Any; use std::sync::Arc; #[derive(Debug)] -pub(super) struct RegexpMatchFunc { +pub struct RegexpMatchFunc { signature: Signature, } +impl Default for RegexpMatchFunc { + fn default() -> Self { + Self::new() + } +} + impl RegexpMatchFunc { pub fn new() -> Self { use DataType::*; diff --git a/datafusion/functions/src/regex/regexpreplace.rs b/datafusion/functions/src/regex/regexpreplace.rs index d90996e04b3f..4e21883c9752 100644 --- a/datafusion/functions/src/regex/regexpreplace.rs +++ b/datafusion/functions/src/regex/regexpreplace.rs @@ -38,9 +38,15 @@ use std::collections::HashMap; use std::sync::Arc; use std::sync::OnceLock; #[derive(Debug)] -pub(super) struct RegexpReplaceFunc { +pub struct RegexpReplaceFunc { signature: Signature, } +impl Default for RegexpReplaceFunc { + fn default() -> Self { + Self::new() + } +} + impl RegexpReplaceFunc { pub fn new() -> Self { use DataType::*; diff --git a/datafusion/functions/src/string/ascii.rs b/datafusion/functions/src/string/ascii.rs index 9a07f4c19cf1..15a3c2391ac6 100644 --- a/datafusion/functions/src/string/ascii.rs +++ b/datafusion/functions/src/string/ascii.rs @@ -44,7 +44,7 @@ pub fn ascii(args: &[ArrayRef]) -> Result { } #[derive(Debug)] -pub(super) struct AsciiFunc { +pub struct AsciiFunc { signature: Signature, } impl AsciiFunc { diff --git a/datafusion/functions/src/string/bit_length.rs b/datafusion/functions/src/string/bit_length.rs index 6a200471d42d..17c49216553b 100644 --- a/datafusion/functions/src/string/bit_length.rs +++ b/datafusion/functions/src/string/bit_length.rs @@ -27,7 +27,7 @@ use datafusion_expr::{ScalarUDFImpl, Signature}; use crate::utils::utf8_to_int_type; #[derive(Debug)] -pub(super) struct BitLengthFunc { +pub struct BitLengthFunc { signature: Signature, } diff --git a/datafusion/functions/src/string/btrim.rs b/datafusion/functions/src/string/btrim.rs index 573a23d07021..b0a85eab6d83 100644 --- a/datafusion/functions/src/string/btrim.rs +++ b/datafusion/functions/src/string/btrim.rs @@ -35,7 +35,7 @@ fn btrim(args: &[ArrayRef]) -> Result { } #[derive(Debug)] -pub(super) struct BTrimFunc { +pub struct BTrimFunc { signature: Signature, aliases: Vec, } diff --git a/datafusion/functions/src/string/chr.rs b/datafusion/functions/src/string/chr.rs index d1f8dc398a2b..21d79cf6b0f1 100644 --- a/datafusion/functions/src/string/chr.rs +++ b/datafusion/functions/src/string/chr.rs @@ -61,7 +61,7 @@ pub fn chr(args: &[ArrayRef]) -> Result { } #[derive(Debug)] -pub(super) struct ChrFunc { +pub struct ChrFunc { signature: Signature, } diff --git a/datafusion/functions/src/string/levenshtein.rs b/datafusion/functions/src/string/levenshtein.rs index 8f497e73e393..390b0d72bee2 100644 --- a/datafusion/functions/src/string/levenshtein.rs +++ b/datafusion/functions/src/string/levenshtein.rs @@ -30,7 +30,7 @@ use datafusion_expr::TypeSignature::*; use datafusion_expr::{ScalarUDFImpl, Signature, Volatility}; #[derive(Debug)] -pub(super) struct LevenshteinFunc { +pub struct LevenshteinFunc { signature: Signature, } diff --git a/datafusion/functions/src/string/lower.rs b/datafusion/functions/src/string/lower.rs index 327772bd808d..a1eff7042211 100644 --- a/datafusion/functions/src/string/lower.rs +++ b/datafusion/functions/src/string/lower.rs @@ -27,7 +27,7 @@ use crate::string::common::handle; use crate::utils::utf8_to_str_type; #[derive(Debug)] -pub(super) struct LowerFunc { +pub struct LowerFunc { signature: Signature, } diff --git a/datafusion/functions/src/string/ltrim.rs b/datafusion/functions/src/string/ltrim.rs index e6926e5bd56e..ad86259d0d7e 100644 --- a/datafusion/functions/src/string/ltrim.rs +++ b/datafusion/functions/src/string/ltrim.rs @@ -35,7 +35,7 @@ fn ltrim(args: &[ArrayRef]) -> Result { } #[derive(Debug)] -pub(super) struct LtrimFunc { +pub struct LtrimFunc { signature: Signature, } diff --git a/datafusion/functions/src/string/octet_length.rs b/datafusion/functions/src/string/octet_length.rs index 639bf6cb48a9..bdd262b7e37e 100644 --- a/datafusion/functions/src/string/octet_length.rs +++ b/datafusion/functions/src/string/octet_length.rs @@ -27,7 +27,7 @@ use datafusion_expr::{ScalarUDFImpl, Signature}; use crate::utils::utf8_to_int_type; #[derive(Debug)] -pub(super) struct OctetLengthFunc { +pub struct OctetLengthFunc { signature: Signature, } diff --git a/datafusion/functions/src/string/overlay.rs b/datafusion/functions/src/string/overlay.rs index 8b9cc03afc4d..3f92a73c1af9 100644 --- a/datafusion/functions/src/string/overlay.rs +++ b/datafusion/functions/src/string/overlay.rs @@ -30,7 +30,7 @@ use datafusion_expr::{ScalarUDFImpl, Signature}; use crate::utils::{make_scalar_function, utf8_to_str_type}; #[derive(Debug)] -pub(super) struct OverlayFunc { +pub struct OverlayFunc { signature: Signature, } diff --git a/datafusion/functions/src/string/repeat.rs b/datafusion/functions/src/string/repeat.rs index f4319af0a5c4..77521120d9d8 100644 --- a/datafusion/functions/src/string/repeat.rs +++ b/datafusion/functions/src/string/repeat.rs @@ -30,7 +30,7 @@ use datafusion_expr::{ScalarUDFImpl, Signature}; use crate::utils::{make_scalar_function, utf8_to_str_type}; #[derive(Debug)] -pub(super) struct RepeatFunc { +pub struct RepeatFunc { signature: Signature, } diff --git a/datafusion/functions/src/string/replace.rs b/datafusion/functions/src/string/replace.rs index e869ac205440..01a3762acaf4 100644 --- a/datafusion/functions/src/string/replace.rs +++ b/datafusion/functions/src/string/replace.rs @@ -30,7 +30,7 @@ use datafusion_expr::{ScalarUDFImpl, Signature}; use crate::utils::{make_scalar_function, utf8_to_str_type}; #[derive(Debug)] -pub(super) struct ReplaceFunc { +pub struct ReplaceFunc { signature: Signature, } diff --git a/datafusion/functions/src/string/rtrim.rs b/datafusion/functions/src/string/rtrim.rs index d04d15ce8847..607e647b2615 100644 --- a/datafusion/functions/src/string/rtrim.rs +++ b/datafusion/functions/src/string/rtrim.rs @@ -35,7 +35,7 @@ fn rtrim(args: &[ArrayRef]) -> Result { } #[derive(Debug)] -pub(super) struct RtrimFunc { +pub struct RtrimFunc { signature: Signature, } diff --git a/datafusion/functions/src/string/split_part.rs b/datafusion/functions/src/string/split_part.rs index 0aa968a1ef5b..4396386afff5 100644 --- a/datafusion/functions/src/string/split_part.rs +++ b/datafusion/functions/src/string/split_part.rs @@ -30,7 +30,7 @@ use datafusion_expr::{ScalarUDFImpl, Signature}; use crate::utils::{make_scalar_function, utf8_to_str_type}; #[derive(Debug)] -pub(super) struct SplitPartFunc { +pub struct SplitPartFunc { signature: Signature, } diff --git a/datafusion/functions/src/string/starts_with.rs b/datafusion/functions/src/string/starts_with.rs index f1b03907f8d8..edbf5c9217a7 100644 --- a/datafusion/functions/src/string/starts_with.rs +++ b/datafusion/functions/src/string/starts_with.rs @@ -40,7 +40,7 @@ pub fn starts_with(args: &[ArrayRef]) -> Result { } #[derive(Debug)] -pub(super) struct StartsWithFunc { +pub struct StartsWithFunc { signature: Signature, } impl StartsWithFunc { diff --git a/datafusion/functions/src/string/to_hex.rs b/datafusion/functions/src/string/to_hex.rs index ab320c68d493..feedeb47f564 100644 --- a/datafusion/functions/src/string/to_hex.rs +++ b/datafusion/functions/src/string/to_hex.rs @@ -60,7 +60,7 @@ where } #[derive(Debug)] -pub(super) struct ToHexFunc { +pub struct ToHexFunc { signature: Signature, } impl ToHexFunc { diff --git a/datafusion/functions/src/string/upper.rs b/datafusion/functions/src/string/upper.rs index 066174abf277..c21824d30d53 100644 --- a/datafusion/functions/src/string/upper.rs +++ b/datafusion/functions/src/string/upper.rs @@ -24,7 +24,7 @@ use datafusion_expr::{ScalarUDFImpl, Signature, Volatility}; use std::any::Any; #[derive(Debug)] -pub(super) struct UpperFunc { +pub struct UpperFunc { signature: Signature, } diff --git a/datafusion/functions/src/string/uuid.rs b/datafusion/functions/src/string/uuid.rs index 791ad6d3c4f3..c68871d42e9f 100644 --- a/datafusion/functions/src/string/uuid.rs +++ b/datafusion/functions/src/string/uuid.rs @@ -29,7 +29,7 @@ use datafusion_expr::{ColumnarValue, Volatility}; use datafusion_expr::{ScalarUDFImpl, Signature}; #[derive(Debug)] -pub(super) struct UuidFunc { +pub struct UuidFunc { signature: Signature, } diff --git a/datafusion/functions/src/unicode/character_length.rs b/datafusion/functions/src/unicode/character_length.rs index 51331bf9a586..7e2723771ff2 100644 --- a/datafusion/functions/src/unicode/character_length.rs +++ b/datafusion/functions/src/unicode/character_length.rs @@ -28,7 +28,7 @@ use std::any::Any; use std::sync::Arc; #[derive(Debug)] -pub(super) struct CharacterLengthFunc { +pub struct CharacterLengthFunc { signature: Signature, aliases: Vec, }