Enum TypeSignature

Source
pub enum TypeSignature {
Show 13 variants Variadic(Vec<DataType>), UserDefined, VariadicAny, Uniform(usize, Vec<DataType>), Exact(Vec<DataType>), Coercible(Vec<TypeSignatureClass>), Comparable(usize), Any(usize), OneOf(Vec<TypeSignature>), ArraySignature(ArrayFunctionSignature), Numeric(usize), String(usize), Nullary,
}
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

  1. A function of one argument of f64 is Uniform(1, vec![DataType::Float64])
  2. 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:

§

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 TypeSignatures.

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

Source

pub fn is_one_of(&self) -> bool

Source§

impl TypeSignature

Source

pub fn to_string_repr(&self) -> Vec<String>

Source

pub fn join_types<T>(types: &[T], delimiter: &str) -> String
where T: Display,

Helper function to join types with specified delimiter.

Source

pub fn supports_zero_argument(&self) -> bool

Check whether 0 input argument is valid for given TypeSignature

Source

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.

Source

pub fn get_possible_types(&self) -> Vec<Vec<DataType>>

get all possible types for the given TypeSignature

Trait Implementations§

Source§

impl Clone for TypeSignature

Source§

fn clone(&self) -> TypeSignature

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TypeSignature

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Hash for TypeSignature

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TypeSignature

Source§

fn eq(&self, other: &TypeSignature) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for TypeSignature

Source§

fn partial_cmp(&self, other: &TypeSignature) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for TypeSignature

Source§

impl StructuralPartialEq for TypeSignature

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> DynEq for T
where T: Eq + Any,

Source§

fn dyn_eq(&self, other: &(dyn Any + 'static)) -> bool

Source§

impl<T> DynHash for T
where T: Hash + Any,

Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.