@@ -74,6 +74,9 @@ pub enum Volatility {
74
74
/// adds a cast such as `cos(CAST int_column AS DOUBLE)` during planning.
75
75
///
76
76
/// # Data Types
77
+ ///
78
+ /// ## Timestamps
79
+ ///
77
80
/// Types to match are represented using Arrow's [`DataType`]. [`DataType::Timestamp`] has an optional variable
78
81
/// timezone specification. To specify a function can handle a timestamp with *ANY* timezone, use
79
82
/// the [`TIMEZONE_WILDCARD`]. For example:
@@ -93,60 +96,89 @@ pub enum Volatility {
93
96
pub enum TypeSignature {
94
97
/// One or more arguments of a common type out of a list of valid types.
95
98
///
99
+ /// For functions that take no arguments (e.g. `random()` see [`TypeSignature::Nullary`]).
100
+ ///
96
101
/// # Examples
97
- /// A function such as `concat` is `Variadic(vec![DataType::Utf8, DataType::LargeUtf8])`
102
+ ///
103
+ /// A function such as `concat` is `Variadic(vec![DataType::Utf8,
104
+ /// DataType::LargeUtf8])`
98
105
Variadic ( Vec < DataType > ) ,
99
106
/// The acceptable signature and coercions rules to coerce arguments to this
100
107
/// signature are special for this function. If this signature is specified,
101
108
/// DataFusion will call `ScalarUDFImpl::coerce_types` to prepare argument types.
102
109
UserDefined ,
103
110
/// One or more arguments with arbitrary types
104
111
VariadicAny ,
105
- /// Fixed number of arguments of an arbitrary but equal type out of a list of valid types.
112
+ /// One or more arguments of an arbitrary but equal type out of a list of valid types.
106
113
///
107
114
/// # Examples
115
+ ///
108
116
/// 1. A function of one argument of f64 is `Uniform(1, vec![DataType::Float64])`
109
117
/// 2. A function of one argument of f64 or f32 is `Uniform(1, vec![DataType::Float32, DataType::Float64])`
110
118
Uniform ( usize , Vec < DataType > ) ,
111
- /// Exact number of arguments of an exact type
119
+ /// One or more arguments with exactly the specified types in order.
120
+ ///
121
+ /// For functions that take no arguments (e.g. `random()`) use [`TypeSignature::Nullary`].
112
122
Exact ( Vec < DataType > ) ,
113
- /// The number of arguments that can be coerced to in order
123
+ /// One or more arguments belonging to the [`TypeSignatureClass`], in order.
124
+ ///
114
125
/// For example, `Coercible(vec![logical_float64()])` accepts
115
126
/// arguments like `vec![DataType::Int32]` or `vec![DataType::Float32]`
116
- /// since i32 and f32 can be casted to f64
127
+ /// since i32 and f32 can be cast to f64
128
+ ///
129
+ /// For functions that take no arguments (e.g. `random()`) see [`TypeSignature::Nullary`].
117
130
Coercible ( Vec < TypeSignatureClass > ) ,
118
- /// The arguments will be coerced to a single type based on the comparison rules.
119
- /// For example, i32 and i64 has coerced type Int64.
131
+ /// One or more arguments that can be "compared"
132
+ ///
133
+ /// Each argument will be coerced to a single type based on comparison rules.
134
+ /// For example a function called with `i32` and `i64` has coerced type `Int64` so
135
+ /// each argument will be coerced to `Int64` before the function is invoked.
120
136
///
121
137
/// Note:
122
- /// - If compares with numeric and string, numeric is preferred for numeric string cases. For example, nullif('2', 1) has coerced types Int64.
138
+ /// - If compares with numeric and string, numeric is preferred for numeric string cases. For example, ` nullif('2', 1)` has coerced types ` Int64` .
123
139
/// - If the result is Null, it will be coerced to String (Utf8View).
140
+ /// - See [`comparison_coercion`] for more details.
141
+ /// - For functions that take no arguments (e.g. `random()` see [`TypeSignature::Nullary`]).
124
142
///
125
- /// See `comparison_coercion_numeric` for more details.
143
+ /// [`comparison_coercion`]: crate::type_coercion::binary::comparison_coercion
126
144
Comparable ( usize ) ,
127
- /// Fixed number of arguments of arbitrary types, number should be larger than 0
145
+ /// One or more arguments of arbitrary types.
146
+ ///
147
+ /// For functions that take no arguments (e.g. `random()`) use [`TypeSignature::Nullary`].
128
148
Any ( usize ) ,
129
- /// Matches exactly one of a list of [`TypeSignature`]s. Coercion is attempted to match
130
- /// the signatures in order, and stops after the first success, if any.
149
+ /// Matches exactly one of a list of [`TypeSignature`]s.
150
+ ///
151
+ /// Coercion is attempted to match the signatures in order, and stops after
152
+ /// the first success, if any.
131
153
///
132
154
/// # Examples
133
- /// Function `make_array` takes 0 or more arguments with arbitrary types, its `TypeSignature`
155
+ ///
156
+ /// Since `make_array` takes 0 or more arguments with arbitrary types, its `TypeSignature`
134
157
/// is `OneOf(vec![Any(0), VariadicAny])`.
135
158
OneOf ( Vec < TypeSignature > ) ,
136
- /// Specifies Signatures for array functions
159
+ /// A function that has an [`ArrayFunctionSignature`]
137
160
ArraySignature ( ArrayFunctionSignature ) ,
138
- /// Fixed number of arguments of numeric types.
161
+ /// One or more arguments of numeric types.
162
+ ///
139
163
/// See [`NativeType::is_numeric`] to know which type is considered numeric
140
164
///
141
- /// [`NativeType::is_numeric`]: datafusion_common
165
+ /// For functions that take no arguments (e.g. `random()`) use [`TypeSignature::Nullary`].
166
+ ///
167
+ /// [`NativeType::is_numeric`]: datafusion_common::types::NativeType::is_numeric
142
168
Numeric ( usize ) ,
143
- /// Fixed number of arguments of all the same string types.
169
+ /// One or arguments of all the same string types.
170
+ ///
144
171
/// The precedence of type from high to low is Utf8View, LargeUtf8 and Utf8.
145
172
/// Null is considered as `Utf8` by default
146
173
/// Dictionary with string value type is also handled.
174
+ ///
175
+ /// For example, if a function is called with (utf8, large_utf8), all
176
+ /// arguments will be coerced to `LargeUtf8`
177
+ ///
178
+ /// For functions that take no arguments (e.g. `random()` use [`TypeSignature::Nullary`]).
147
179
String ( usize ) ,
148
- /// Zero argument
149
- NullAry ,
180
+ /// No arguments
181
+ Nullary ,
150
182
}
151
183
152
184
impl TypeSignature {
@@ -243,7 +275,7 @@ impl Display for ArrayFunctionSignature {
243
275
impl TypeSignature {
244
276
pub fn to_string_repr ( & self ) -> Vec < String > {
245
277
match self {
246
- TypeSignature :: NullAry => {
278
+ TypeSignature :: Nullary => {
247
279
vec ! [ "NullAry()" . to_string( ) ]
248
280
}
249
281
TypeSignature :: Variadic ( types) => {
@@ -302,7 +334,7 @@ impl TypeSignature {
302
334
pub fn supports_zero_argument ( & self ) -> bool {
303
335
match & self {
304
336
TypeSignature :: Exact ( vec) => vec. is_empty ( ) ,
305
- TypeSignature :: NullAry => true ,
337
+ TypeSignature :: Nullary => true ,
306
338
TypeSignature :: OneOf ( types) => types
307
339
. iter ( )
308
340
. any ( |type_sig| type_sig. supports_zero_argument ( ) ) ,
@@ -368,7 +400,7 @@ impl TypeSignature {
368
400
// TODO: Implement for other types
369
401
TypeSignature :: Any ( _)
370
402
| TypeSignature :: Comparable ( _)
371
- | TypeSignature :: NullAry
403
+ | TypeSignature :: Nullary
372
404
| TypeSignature :: VariadicAny
373
405
| TypeSignature :: ArraySignature ( _)
374
406
| TypeSignature :: UserDefined => vec ! [ ] ,
@@ -502,7 +534,7 @@ impl Signature {
502
534
503
535
pub fn nullary ( volatility : Volatility ) -> Self {
504
536
Signature {
505
- type_signature : TypeSignature :: NullAry ,
537
+ type_signature : TypeSignature :: Nullary ,
506
538
volatility,
507
539
}
508
540
}
@@ -579,10 +611,10 @@ mod tests {
579
611
TypeSignature :: Exact ( vec![ ] ) ,
580
612
TypeSignature :: OneOf ( vec![
581
613
TypeSignature :: Exact ( vec![ DataType :: Int8 ] ) ,
582
- TypeSignature :: NullAry ,
614
+ TypeSignature :: Nullary ,
583
615
TypeSignature :: Uniform ( 1 , vec![ DataType :: Int8 ] ) ,
584
616
] ) ,
585
- TypeSignature :: NullAry ,
617
+ TypeSignature :: Nullary ,
586
618
] ;
587
619
588
620
for case in positive_cases {
0 commit comments