diff --git a/datafusion/functions/src/core/nullif.rs b/datafusion/functions/src/core/nullif.rs index f83bd987c937..73bfba9b38b1 100644 --- a/datafusion/functions/src/core/nullif.rs +++ b/datafusion/functions/src/core/nullif.rs @@ -18,15 +18,15 @@ //! Encoding expressions use arrow::datatypes::DataType; -use datafusion_common::{internal_err, Result, DataFusionError}; +use datafusion_common::{exec_err, DataFusionError, Result}; use datafusion_expr::ColumnarValue; -use datafusion_expr::{ScalarUDFImpl, Signature, Volatility}; -use std::any::Any; use arrow::array::Array; use arrow::compute::kernels::cmp::eq; use arrow::compute::kernels::nullif::nullif; use datafusion_common::ScalarValue; +use datafusion_expr::{ScalarUDFImpl, Signature, Volatility}; +use std::any::Any; #[derive(Debug)] pub(super) struct NullIfFunc { @@ -58,7 +58,7 @@ impl NullIfFunc { Self { signature: Signature::uniform(2, SUPPORTED_NULLIF_TYPES.to_vec(), - Volatility::Immutable, + Volatility::Immutable, ) } } @@ -81,7 +81,7 @@ impl ScalarUDFImpl for NullIfFunc { let coerced_types = datafusion_expr::type_coercion::functions::data_types(arg_types, &self.signature); coerced_types.map(|typs| typs[0].clone()) .map_err(|e| e.context("Failed to coerce arguments for NULLIF") - ) + ) } fn invoke(&self, args: &[ColumnarValue]) -> Result { @@ -90,14 +90,13 @@ impl ScalarUDFImpl for NullIfFunc { } - /// Implements NULLIF(expr1, expr2) /// Args: 0 - left expr is any array /// 1 - if the left is equal to this expr2, then the result is NULL, otherwise left value is passed. /// fn nullif_func(args: &[ColumnarValue]) -> Result { if args.len() != 2 { - return internal_err!( + return exec_err!( "{:?} args were supplied but NULLIF takes exactly two args", args.len() ); diff --git a/datafusion/functions/src/encoding/inner.rs b/datafusion/functions/src/encoding/inner.rs index 886a031a5269..4cbeab3092c7 100644 --- a/datafusion/functions/src/encoding/inner.rs +++ b/datafusion/functions/src/encoding/inner.rs @@ -22,11 +22,11 @@ use arrow::{ datatypes::DataType, }; use base64::{engine::general_purpose, Engine as _}; -use datafusion_common::ScalarValue; use datafusion_common::{ cast::{as_generic_binary_array, as_generic_string_array}, - internal_err, not_impl_err, plan_err, + not_impl_err, plan_err, }; +use datafusion_common::{exec_err, ScalarValue}; use datafusion_common::{DataFusionError, Result}; use datafusion_expr::ColumnarValue; use std::sync::Arc; @@ -111,6 +111,7 @@ impl DecodeFunc { } } } + impl ScalarUDFImpl for DecodeFunc { fn as_any(&self) -> &dyn Any { self @@ -148,6 +149,7 @@ enum Encoding { Base64, Hex, } + fn encode_process(value: &ColumnarValue, encoding: Encoding) -> Result { match value { ColumnarValue::Array(a) => match a.data_type() { @@ -155,7 +157,7 @@ fn encode_process(value: &ColumnarValue, encoding: Encoding) -> Result encoding.encode_utf8_array::(a.as_ref()), DataType::Binary => encoding.encode_binary_array::(a.as_ref()), DataType::LargeBinary => encoding.encode_binary_array::(a.as_ref()), - other => internal_err!( + other => exec_err!( "Unsupported data type {other:?} for function encode({encoding})" ), }, @@ -171,7 +173,7 @@ fn encode_process(value: &ColumnarValue, encoding: Encoding) -> Result Ok(encoding .encode_large_scalar(a.as_ref().map(|v: &Vec| v.as_slice()))), - other => internal_err!( + other => exec_err!( "Unsupported data type {other:?} for function encode({encoding})" ), } @@ -186,7 +188,7 @@ fn decode_process(value: &ColumnarValue, encoding: Encoding) -> Result encoding.decode_utf8_array::(a.as_ref()), DataType::Binary => encoding.decode_binary_array::(a.as_ref()), DataType::LargeBinary => encoding.decode_binary_array::(a.as_ref()), - other => internal_err!( + other => exec_err!( "Unsupported data type {other:?} for function decode({encoding})" ), }, @@ -202,7 +204,7 @@ fn decode_process(value: &ColumnarValue, encoding: Encoding) -> Result encoding .decode_large_scalar(a.as_ref().map(|v: &Vec| v.as_slice())), - other => internal_err!( + other => exec_err!( "Unsupported data type {other:?} for function decode({encoding})" ), } @@ -270,8 +272,8 @@ impl Encoding { } fn encode_binary_array(self, value: &dyn Array) -> Result - where - T: OffsetSizeTrait, + where + T: OffsetSizeTrait, { let input_value = as_generic_binary_array::(value)?; let array: ArrayRef = match self { @@ -282,8 +284,8 @@ impl Encoding { } fn encode_utf8_array(self, value: &dyn Array) -> Result - where - T: OffsetSizeTrait, + where + T: OffsetSizeTrait, { let input_value = as_generic_string_array::(value)?; let array: ArrayRef = match self { @@ -350,8 +352,8 @@ impl Encoding { } fn decode_binary_array(self, value: &dyn Array) -> Result - where - T: OffsetSizeTrait, + where + T: OffsetSizeTrait, { let input_value = as_generic_binary_array::(value)?; let array: ArrayRef = match self { @@ -362,8 +364,8 @@ impl Encoding { } fn decode_utf8_array(self, value: &dyn Array) -> Result - where - T: OffsetSizeTrait, + where + T: OffsetSizeTrait, { let input_value = as_generic_string_array::(value)?; let array: ArrayRef = match self { @@ -405,7 +407,7 @@ impl FromStr for Encoding { /// Standard encodings are base64 and hex. fn encode(args: &[ColumnarValue]) -> Result { if args.len() != 2 { - return internal_err!( + return exec_err!( "{:?} args were supplied but encode takes exactly two arguments", args.len() ); @@ -431,7 +433,7 @@ fn encode(args: &[ColumnarValue]) -> Result { /// Standard encodings are base64 and hex. fn decode(args: &[ColumnarValue]) -> Result { if args.len() != 2 { - return internal_err!( + return exec_err!( "{:?} args were supplied but decode takes exactly two arguments", args.len() ); diff --git a/datafusion/functions/src/math/nans.rs b/datafusion/functions/src/math/nans.rs index 20754c18aa8e..c7868e6d5eca 100644 --- a/datafusion/functions/src/math/nans.rs +++ b/datafusion/functions/src/math/nans.rs @@ -18,14 +18,14 @@ //! Encoding expressions use arrow::datatypes::DataType; -use datafusion_common::{internal_err, Result, DataFusionError}; +use datafusion_common::{exec_err, DataFusionError, Result}; use datafusion_expr::ColumnarValue; +use arrow::array::{ArrayRef, BooleanArray, Float32Array, Float64Array}; use datafusion_expr::TypeSignature::*; use datafusion_expr::{ScalarUDFImpl, Signature, Volatility}; use std::any::Any; use std::sync::Arc; -use arrow::array::{ArrayRef, BooleanArray, Float32Array, Float64Array}; #[derive(Debug)] pub(super) struct IsNanFunc { @@ -73,7 +73,7 @@ impl ScalarUDFImpl for IsNanFunc { BooleanArray, { f64::is_nan } )) - }, + } DataType::Float32 => { Arc::new(make_function_scalar_inputs_return_type!( &args[0], @@ -82,8 +82,8 @@ impl ScalarUDFImpl for IsNanFunc { BooleanArray, { f32::is_nan } )) - }, - other => return internal_err!("Unsupported data type {other:?} for function isnan"), + } + other => return exec_err!("Unsupported data type {other:?} for function isnan"), }; Ok(ColumnarValue::Array(arr)) } diff --git a/datafusion/physical-expr/src/functions.rs b/datafusion/physical-expr/src/functions.rs index 8c7a5c3eab0a..92a300b072f7 100644 --- a/datafusion/physical-expr/src/functions.rs +++ b/datafusion/physical-expr/src/functions.rs @@ -888,9 +888,7 @@ pub fn create_physical_fun( DataType::LargeUtf8 => { make_scalar_function_inner(string_expressions::overlay::)(args) } - other => Err(DataFusionError::Internal(format!( - "Unsupported data type {other:?} for function overlay", - ))), + other => exec_err!("Unsupported data type {other:?} for function overlay"), }), BuiltinScalarFunction::Levenshtein => { Arc::new(|args| match args[0].data_type() { @@ -900,9 +898,9 @@ pub fn create_physical_fun( DataType::LargeUtf8 => make_scalar_function_inner( string_expressions::levenshtein::, )(args), - other => Err(DataFusionError::Internal(format!( - "Unsupported data type {other:?} for function levenshtein", - ))), + other => { + exec_err!("Unsupported data type {other:?} for function levenshtein") + } }) } BuiltinScalarFunction::SubstrIndex => { @@ -923,9 +921,9 @@ pub fn create_physical_fun( ); make_scalar_function_inner(func)(args) } - other => Err(DataFusionError::Internal(format!( - "Unsupported data type {other:?} for function substr_index", - ))), + other => { + exec_err!("Unsupported data type {other:?} for function substr_index") + } }) } BuiltinScalarFunction::FindInSet => Arc::new(|args| match args[0].data_type() { @@ -945,9 +943,9 @@ pub fn create_physical_fun( ); make_scalar_function_inner(func)(args) } - other => Err(DataFusionError::Internal(format!( - "Unsupported data type {other:?} for function find_in_set", - ))), + other => { + exec_err!("Unsupported data type {other:?} for function find_in_set") + } }), }) } diff --git a/datafusion/physical-expr/src/string_expressions.rs b/datafusion/physical-expr/src/string_expressions.rs index 5a127c93a845..6a4a29763e4b 100644 --- a/datafusion/physical-expr/src/string_expressions.rs +++ b/datafusion/physical-expr/src/string_expressions.rs @@ -665,10 +665,10 @@ pub fn overlay(args: &[ArrayRef]) -> Result { /// LEVENSHTEIN('kitten', 'sitting') = 3 pub fn levenshtein(args: &[ArrayRef]) -> Result { if args.len() != 2 { - return Err(DataFusionError::Internal(format!( + return exec_err!( "levenshtein function requires two arguments, got {}", args.len() - ))); + ); } let str1_array = as_generic_string_array::(&args[0])?; let str2_array = as_generic_string_array::(&args[1])?;