Enum datafusion_expr::TypeSignature
source · pub enum TypeSignature {
Variadic(Vec<DataType>),
UserDefined,
VariadicAny,
Uniform(usize, Vec<DataType>),
Exact(Vec<DataType>),
Any(usize),
OneOf(Vec<TypeSignature>),
ArraySignature(ArrayFunctionSignature),
Numeric(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 an 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
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
Implementations§
source§impl TypeSignature
impl TypeSignature
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
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default 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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.