pub enum TypeSignature {
}
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
§Timestamps
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.
For functions that take no arguments (e.g. random()
see TypeSignature::Nullary
).
§Examples
A function such as concat
is Variadic(vec![DataType::Utf8, DataType::LargeUtf8])
UserDefined
The acceptable signature and coercions rules 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>)
One or more 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>)
One or more arguments with exactly the specified types in order.
For functions that take no arguments (e.g. random()
) use TypeSignature::Nullary
.
Coercible(Vec<TypeSignatureClass>)
One or more arguments belonging to the TypeSignatureClass
, in order.
For example, Coercible(vec![logical_float64()])
accepts
arguments like vec![Int32]
or vec![Float32]
since i32 and f32 can be cast to f64
For functions that take no arguments (e.g. random()
) see TypeSignature::Nullary
.
Comparable(usize)
One or more arguments coercible to a single, comparable type.
Each argument will be coerced to a single type using the
coercion rules described in comparison_coercion_numeric
.
§Examples
If the nullif(1, 2)
function is called with i32
and i64
arguments
the types will both be coerced to i64
before the function is invoked.
If the nullif('1', 2)
function is called with Utf8
and i64
arguments
the types will both be coerced to Utf8
before the function is invoked.
Note:
- For functions that take no arguments (e.g.
random()
seeTypeSignature::Nullary
). - If all arguments have type
DataType::Null
, they are coerced toUtf8
Any(usize)
One or more arguments of arbitrary types.
For functions that take no arguments (e.g. random()
) use TypeSignature::Nullary
.
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
Since make_array
takes 0 or more arguments with arbitrary types, its TypeSignature
is OneOf(vec![Any(0), VariadicAny])
.
ArraySignature(ArrayFunctionSignature)
A function that has an ArrayFunctionSignature
Numeric(usize)
One or more arguments of numeric types.
See NativeType::is_numeric
to know which type is considered numeric
For functions that take no arguments (e.g. random()
) use TypeSignature::Nullary
.
String(usize)
One or arguments of all the same string types.
The precedence of type from high to low is Utf8View, LargeUtf8 and Utf8.
Null is considered as Utf8
by default
Dictionary with string value type is also handled.
For example, if a function is called with (utf8, large_utf8), all
arguments will be coerced to LargeUtf8
For functions that take no arguments (e.g. random()
use TypeSignature::Nullary
).
Nullary
No arguments
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
Sourcepub fn used_to_support_zero_arguments(&self) -> bool
pub fn used_to_support_zero_arguments(&self) -> bool
Returns true if the signature currently supports or used to supported 0 input arguments in a previous version of DataFusion.
Sourcepub fn get_possible_types(&self) -> Vec<Vec<DataType>>
pub fn get_possible_types(&self) -> Vec<Vec<DataType>>
get all possible types for the 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§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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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