Skip to content

Commit

Permalink
Updated a few instances of internal_err missed in previous audit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Omega359 committed Feb 21, 2024
1 parent 86d2498 commit c408e43
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 42 deletions.
13 changes: 6 additions & 7 deletions datafusion/functions/src/core/nullif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -58,7 +58,7 @@ impl NullIfFunc {
Self {
signature:
Signature::uniform(2, SUPPORTED_NULLIF_TYPES.to_vec(),
Volatility::Immutable,
Volatility::Immutable,
)
}
}
Expand All @@ -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<ColumnarValue> {
Expand All @@ -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<ColumnarValue> {
if args.len() != 2 {
return internal_err!(
return exec_err!(
"{:?} args were supplied but NULLIF takes exactly two args",
args.len()
);
Expand Down
34 changes: 18 additions & 16 deletions datafusion/functions/src/encoding/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -111,6 +111,7 @@ impl DecodeFunc {
}
}
}

impl ScalarUDFImpl for DecodeFunc {
fn as_any(&self) -> &dyn Any {
self
Expand Down Expand Up @@ -148,14 +149,15 @@ enum Encoding {
Base64,
Hex,
}

fn encode_process(value: &ColumnarValue, encoding: Encoding) -> Result<ColumnarValue> {
match value {
ColumnarValue::Array(a) => match a.data_type() {
DataType::Utf8 => encoding.encode_utf8_array::<i32>(a.as_ref()),
DataType::LargeUtf8 => encoding.encode_utf8_array::<i64>(a.as_ref()),
DataType::Binary => encoding.encode_binary_array::<i32>(a.as_ref()),
DataType::LargeBinary => encoding.encode_binary_array::<i64>(a.as_ref()),
other => internal_err!(
other => exec_err!(
"Unsupported data type {other:?} for function encode({encoding})"
),
},
Expand All @@ -171,7 +173,7 @@ fn encode_process(value: &ColumnarValue, encoding: Encoding) -> Result<ColumnarV
),
ScalarValue::LargeBinary(a) => Ok(encoding
.encode_large_scalar(a.as_ref().map(|v: &Vec<u8>| v.as_slice()))),
other => internal_err!(
other => exec_err!(
"Unsupported data type {other:?} for function encode({encoding})"
),
}
Expand All @@ -186,7 +188,7 @@ fn decode_process(value: &ColumnarValue, encoding: Encoding) -> Result<ColumnarV
DataType::LargeUtf8 => encoding.decode_utf8_array::<i64>(a.as_ref()),
DataType::Binary => encoding.decode_binary_array::<i32>(a.as_ref()),
DataType::LargeBinary => encoding.decode_binary_array::<i64>(a.as_ref()),
other => internal_err!(
other => exec_err!(
"Unsupported data type {other:?} for function decode({encoding})"
),
},
Expand All @@ -202,7 +204,7 @@ fn decode_process(value: &ColumnarValue, encoding: Encoding) -> Result<ColumnarV
}
ScalarValue::LargeBinary(a) => encoding
.decode_large_scalar(a.as_ref().map(|v: &Vec<u8>| v.as_slice())),
other => internal_err!(
other => exec_err!(
"Unsupported data type {other:?} for function decode({encoding})"
),
}
Expand Down Expand Up @@ -270,8 +272,8 @@ impl Encoding {
}

fn encode_binary_array<T>(self, value: &dyn Array) -> Result<ColumnarValue>
where
T: OffsetSizeTrait,
where
T: OffsetSizeTrait,
{
let input_value = as_generic_binary_array::<T>(value)?;
let array: ArrayRef = match self {
Expand All @@ -282,8 +284,8 @@ impl Encoding {
}

fn encode_utf8_array<T>(self, value: &dyn Array) -> Result<ColumnarValue>
where
T: OffsetSizeTrait,
where
T: OffsetSizeTrait,
{
let input_value = as_generic_string_array::<T>(value)?;
let array: ArrayRef = match self {
Expand Down Expand Up @@ -350,8 +352,8 @@ impl Encoding {
}

fn decode_binary_array<T>(self, value: &dyn Array) -> Result<ColumnarValue>
where
T: OffsetSizeTrait,
where
T: OffsetSizeTrait,
{
let input_value = as_generic_binary_array::<T>(value)?;
let array: ArrayRef = match self {
Expand All @@ -362,8 +364,8 @@ impl Encoding {
}

fn decode_utf8_array<T>(self, value: &dyn Array) -> Result<ColumnarValue>
where
T: OffsetSizeTrait,
where
T: OffsetSizeTrait,
{
let input_value = as_generic_string_array::<T>(value)?;
let array: ArrayRef = match self {
Expand Down Expand Up @@ -405,7 +407,7 @@ impl FromStr for Encoding {
/// Standard encodings are base64 and hex.
fn encode(args: &[ColumnarValue]) -> Result<ColumnarValue> {
if args.len() != 2 {
return internal_err!(
return exec_err!(
"{:?} args were supplied but encode takes exactly two arguments",
args.len()
);
Expand All @@ -431,7 +433,7 @@ fn encode(args: &[ColumnarValue]) -> Result<ColumnarValue> {
/// Standard encodings are base64 and hex.
fn decode(args: &[ColumnarValue]) -> Result<ColumnarValue> {
if args.len() != 2 {
return internal_err!(
return exec_err!(
"{:?} args were supplied but decode takes exactly two arguments",
args.len()
);
Expand Down
10 changes: 5 additions & 5 deletions datafusion/functions/src/math/nans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -73,7 +73,7 @@ impl ScalarUDFImpl for IsNanFunc {
BooleanArray,
{ f64::is_nan }
))
},
}
DataType::Float32 => {
Arc::new(make_function_scalar_inputs_return_type!(
&args[0],
Expand All @@ -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))
}
Expand Down
22 changes: 10 additions & 12 deletions datafusion/physical-expr/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,9 +888,7 @@ pub fn create_physical_fun(
DataType::LargeUtf8 => {
make_scalar_function_inner(string_expressions::overlay::<i64>)(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() {
Expand All @@ -900,9 +898,9 @@ pub fn create_physical_fun(
DataType::LargeUtf8 => make_scalar_function_inner(
string_expressions::levenshtein::<i64>,
)(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 => {
Expand All @@ -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() {
Expand All @@ -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")
}
}),
})
}
Expand Down
4 changes: 2 additions & 2 deletions datafusion/physical-expr/src/string_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,10 @@ pub fn overlay<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> {
/// LEVENSHTEIN('kitten', 'sitting') = 3
pub fn levenshtein<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> {
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::<T>(&args[0])?;
let str2_array = as_generic_string_array::<T>(&args[1])?;
Expand Down

0 comments on commit c408e43

Please sign in to comment.