pub enum TypeSignature {
Variadic(Vec<DataType>),
UserDefined,
VariadicAny,
Uniform(usize, Vec<DataType>),
Exact(Vec<DataType>),
Coercible(Vec<DataType>),
Any(usize),
OneOf(Vec<TypeSignature>),
ArraySignature(ArrayFunctionSignature),
Numeric(usize),
String(usize),
}
Expand description
A function’s type signature defines the types of arguments the function supports.
Functions typically support only a few different types of arguments compared to the different datatypes in Arrow. To make functions easy to use, when possible DataFusion automatically coerces (add casts to) function arguments so they match the type signature.
For example, a function like cos
may only be implemented for Float64
arguments. To support a query
that calls cos
with a different argument type, such as cos(int_column)
, type coercion automatically
adds a cast such as cos(CAST int_column AS DOUBLE)
during planning.
§Data Types
Types to match are represented using Arrow’s DataType
. DataType::Timestamp
has an optional variable
timezone specification. To specify a function can handle a timestamp with ANY timezone, use
the TIMEZONE_WILDCARD
. For example:
let type_signature = TypeSignature::Exact(vec![
// A nanosecond precision timestamp with ANY timezone
// matches Timestamp(Nanosecond, Some("+0:00"))
// matches Timestamp(Nanosecond, Some("+5:00"))
// does not match Timestamp(Nanosecond, None)
DataType::Timestamp(TimeUnit::Nanosecond, Some(TIMEZONE_WILDCARD.into())),
]);
Variants§
Variadic(Vec<DataType>)
One or more arguments of a common type out of a list of valid types.
§Examples
A function such as concat
is Variadic(vec![DataType::Utf8, DataType::LargeUtf8])
UserDefined
The acceptable signature and coercions rules to coerce arguments to this
signature are special for this function. If this signature is specified,
DataFusion will call ScalarUDFImpl::coerce_types
to prepare argument types.
VariadicAny
One or more arguments with arbitrary types
Uniform(usize, Vec<DataType>)
Fixed number of arguments of an arbitrary but equal type out of a list of valid types.
§Examples
- A function of one argument of f64 is
Uniform(1, vec![DataType::Float64])
- A function of one argument of f64 or f32 is
Uniform(1, vec![DataType::Float32, DataType::Float64])
Exact(Vec<DataType>)
Exact number of arguments of an exact type
Coercible(Vec<DataType>)
The number of arguments that can be coerced to in order
For example, Coercible(vec![DataType::Float64])
accepts
arguments like vec![DataType::Int32]
or vec![DataType::Float32]
since i32 and f32 can be casted to f64
Any(usize)
Fixed number of arguments of arbitrary types
If a function takes 0 argument, its TypeSignature
should be Any(0)
OneOf(Vec<TypeSignature>)
Matches exactly one of a list of TypeSignature
s. Coercion is attempted to match
the signatures in order, and stops after the first success, if any.
§Examples
Function make_array
takes 0 or more arguments with arbitrary types, its TypeSignature
is OneOf(vec![Any(0), VariadicAny])
.
ArraySignature(ArrayFunctionSignature)
Specifies Signatures for array functions
Numeric(usize)
Fixed number of arguments of numeric types. See https://docs.rs/arrow/latest/arrow/datatypes/enum.DataType.html#method.is_numeric to know which type is considered numeric
String(usize)
Fixed number of arguments of all the same string types.
The precedence of type from high to low is Utf8View, LargeUtf8 and Utf8.
Null is considerd as Utf8
by default
Dictionary with string value type is also handled.
Implementations§
Source§impl TypeSignature
impl TypeSignature
pub fn to_string_repr(&self) -> Vec<String>
Sourcepub fn join_types<T>(types: &[T], delimiter: &str) -> Stringwhere
T: Display,
pub fn join_types<T>(types: &[T], delimiter: &str) -> Stringwhere
T: Display,
Helper function to join types with specified delimiter.
Sourcepub fn supports_zero_argument(&self) -> bool
pub fn supports_zero_argument(&self) -> bool
Check whether 0 input argument is valid for given TypeSignature
Trait Implementations§
Source§impl Clone for TypeSignature
impl Clone for TypeSignature
Source§fn clone(&self) -> TypeSignature
fn clone(&self) -> TypeSignature
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for TypeSignature
impl Debug for TypeSignature
Source§impl Hash for TypeSignature
impl Hash for TypeSignature
Source§impl PartialEq for TypeSignature
impl PartialEq for TypeSignature
Source§impl PartialOrd for TypeSignature
impl PartialOrd for TypeSignature
impl Eq for TypeSignature
impl StructuralPartialEq for TypeSignature
Auto Trait Implementations§
impl Freeze for TypeSignature
impl RefUnwindSafe for TypeSignature
impl Send for TypeSignature
impl Sync for TypeSignature
impl Unpin for TypeSignature
impl UnwindSafe for TypeSignature
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more