-
Notifications
You must be signed in to change notification settings - Fork 1.9k
refactor: Use Signature::coercible for isnan/iszero
#19604
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
Changes from 6 commits
6b1b0e4
f4eb9cb
7b482aa
f2b196e
bd86ee5
c6a65fe
8dd92eb
1b1dfa6
28a242b
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,8 +23,9 @@ use crate::utils::make_scalar_function; | |||||
| use arrow::array::{ArrayRef, AsArray, Float32Array, Float64Array}; | ||||||
| use arrow::datatypes::DataType::{Float32, Float64}; | ||||||
| use arrow::datatypes::{DataType, Float32Type, Float64Type}; | ||||||
| use datafusion_common::{DataFusionError, Result, exec_err}; | ||||||
| use datafusion_expr::TypeSignature::Exact; | ||||||
| use datafusion_common::types::NativeType; | ||||||
| use datafusion_common::{DataFusionError, Result, ScalarValue, exec_err}; | ||||||
| use datafusion_expr::{Coercion, TypeSignatureClass}; | ||||||
| use datafusion_expr::{ | ||||||
| ColumnarValue, Documentation, ScalarFunctionArgs, ScalarUDFImpl, Signature, | ||||||
| Volatility, | ||||||
|
|
@@ -66,10 +67,14 @@ impl Default for NanvlFunc { | |||||
|
|
||||||
| impl NanvlFunc { | ||||||
| pub fn new() -> Self { | ||||||
| use DataType::*; | ||||||
| let float = Coercion::new_implicit( | ||||||
| TypeSignatureClass::Float, | ||||||
| vec![TypeSignatureClass::Numeric], | ||||||
| NativeType::Float64, | ||||||
| ); | ||||||
| Self { | ||||||
| signature: Signature::one_of( | ||||||
| vec![Exact(vec![Float32, Float32]), Exact(vec![Float64, Float64])], | ||||||
| signature: Signature::coercible( | ||||||
| vec![float.clone(), float], | ||||||
|
||||||
| Volatility::Immutable, | ||||||
| ), | ||||||
| } | ||||||
|
|
@@ -97,7 +102,25 @@ impl ScalarUDFImpl for NanvlFunc { | |||||
| } | ||||||
|
|
||||||
| fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> { | ||||||
| make_scalar_function(nanvl, vec![])(&args.args) | ||||||
| if args.arg_fields.iter().any(|f| f.data_type().is_null()) { | ||||||
|
||||||
| return ColumnarValue::Scalar(ScalarValue::Null) | ||||||
| .cast_to(args.return_type(), None); | ||||||
| } | ||||||
|
|
||||||
| let target_type = args.return_type(); | ||||||
| if !matches!(target_type, Float32 | Float64) { | ||||||
|
||||||
| if !matches!(target_type, Float32 | Float64) { | |
| if !matches!(target_type, Float16 | Float32 | Float64) { |
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 also includes
Float16butfn iszero()below currently handles only Float32 and Float64.