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

  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>)

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

source

pub fn supports_zero_argument(&self) -> bool

Check whether 0 input argument is valid for 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

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

impl Hash for TypeSignature

source§

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

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

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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

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<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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.
source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,