-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor: Remove redundant BuiltinScalarFunction::supports_zero_argument() #8059
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,31 +82,36 @@ pub enum Volatility { | |
/// ``` | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub enum TypeSignature { | ||
/// arbitrary number of arguments of an common type out of a list of valid types. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked the current functions' signatures, So the doc comment is updated for clarification: |
||
/// 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])` | ||
Variadic(Vec<DataType>), | ||
/// arbitrary number of arguments of an arbitrary but equal type. | ||
/// One or more arguments of an arbitrary but equal type. | ||
/// DataFusion attempts to coerce all argument types to match the first argument's type | ||
/// | ||
/// # Examples | ||
/// A function such as `array` is `VariadicEqual` | ||
VariadicEqual, | ||
/// arbitrary number of arguments with arbitrary types | ||
/// One or more arguments with arbitrary types | ||
VariadicAny, | ||
/// 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])` | ||
Uniform(usize, Vec<DataType>), | ||
/// exact number of arguments of an exact type | ||
/// Exact number of arguments of an exact type | ||
Exact(Vec<DataType>), | ||
/// fixed number of arguments of arbitrary types | ||
/// Fixed number of arguments of arbitrary types | ||
/// If a function takes 0 argument, its `TypeSignature` should be `Any(0)` | ||
Any(usize), | ||
/// 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])`. | ||
OneOf(Vec<TypeSignature>), | ||
} | ||
|
||
|
@@ -150,6 +155,18 @@ impl TypeSignature { | |
.collect::<Vec<String>>() | ||
.join(delimiter) | ||
} | ||
|
||
/// Check whether 0 input argument is valid for given `TypeSignature` | ||
pub fn supports_zero_argument(&self) -> bool { | ||
match &self { | ||
TypeSignature::Exact(vec) => vec.is_empty(), | ||
TypeSignature::Uniform(0, _) | TypeSignature::Any(0) => true, | ||
TypeSignature::OneOf(types) => types | ||
.iter() | ||
.any(|type_sig| type_sig.supports_zero_argument()), | ||
_ => false, | ||
} | ||
} | ||
} | ||
|
||
/// Defines the supported argument types ([`TypeSignature`]) and [`Volatility`] for a function. | ||
|
@@ -234,3 +251,51 @@ impl Signature { | |
/// - `Some(true)` indicates that the function is monotonically increasing w.r.t. the argument in question. | ||
/// - Some(false) indicates that the function is monotonically decreasing w.r.t. the argument in question. | ||
pub type FuncMonotonicity = Vec<Option<bool>>; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn supports_zero_argument_tests() { | ||
// Testing `TypeSignature`s which supports 0 arg | ||
let positive_cases = vec![ | ||
TypeSignature::Exact(vec![]), | ||
TypeSignature::Uniform(0, vec![DataType::Float64]), | ||
TypeSignature::Any(0), | ||
TypeSignature::OneOf(vec![ | ||
TypeSignature::Exact(vec![DataType::Int8]), | ||
TypeSignature::Any(0), | ||
TypeSignature::Uniform(1, vec![DataType::Int8]), | ||
]), | ||
]; | ||
|
||
for case in positive_cases { | ||
assert!( | ||
case.supports_zero_argument(), | ||
"Expected {:?} to support zero arguments", | ||
case | ||
); | ||
} | ||
|
||
// Testing `TypeSignature`s which doesn't support 0 arg | ||
let negative_cases = vec![ | ||
TypeSignature::Exact(vec![DataType::Utf8]), | ||
TypeSignature::Uniform(1, vec![DataType::Float64]), | ||
TypeSignature::Any(1), | ||
TypeSignature::VariadicAny, | ||
TypeSignature::OneOf(vec![ | ||
TypeSignature::Exact(vec![DataType::Int8]), | ||
TypeSignature::Uniform(1, vec![DataType::Int8]), | ||
]), | ||
]; | ||
|
||
for case in negative_cases { | ||
assert!( | ||
!case.supports_zero_argument(), | ||
"Expected {:?} not to support zero arguments", | ||
case | ||
); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also please change this method to call into
self.type_signature().supports_zero_argument
so it is clear they are equivalent and so the implementations don't drift out of sync?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense, updated. Thank you.