Skip to content

Commit

Permalink
Switched internal_err! -> exec_err! - apache#9164
Browse files Browse the repository at this point in the history
  • Loading branch information
Omega359 committed Feb 12, 2024
1 parent fbb1ed2 commit e9ea5d7
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 138 deletions.
25 changes: 13 additions & 12 deletions datafusion/physical-expr/src/aggregate/build_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@

use std::sync::Arc;

use arrow::datatypes::Schema;

use datafusion_common::{exec_err, not_impl_err, DataFusionError, Result};
use datafusion_expr::AggregateFunction;

use crate::aggregate::regr::RegrType;
use crate::expressions::{self, Literal};
use crate::{AggregateExpr, PhysicalExpr, PhysicalSortExpr};

use arrow::datatypes::Schema;
use datafusion_common::{internal_err, not_impl_err, DataFusionError, Result};
use datafusion_expr::AggregateFunction;

/// Create a physical aggregation expression.
/// This function errors when `input_phy_exprs`' can't be coerced to a valid argument type of the aggregation function.
pub fn create_aggregate_expr(
Expand Down Expand Up @@ -379,9 +380,7 @@ pub fn create_aggregate_expr(
.downcast_ref::<Literal>()
.map(|literal| literal.value())
else {
return internal_err!(
"Second argument of NTH_VALUE needs to be a literal"
);
return exec_err!("Second argument of NTH_VALUE needs to be a literal");
};
let nullable = expr.nullable(input_schema)?;
Arc::new(expressions::NthValueAgg::new(
Expand Down Expand Up @@ -415,17 +414,19 @@ pub fn create_aggregate_expr(

#[cfg(test)]
mod tests {
use super::*;
use arrow::datatypes::{DataType, Field};

use datafusion_common::{plan_err, ScalarValue};
use datafusion_expr::type_coercion::aggregates::NUMERICS;
use datafusion_expr::{type_coercion, Signature};

use crate::expressions::{
try_cast, ApproxDistinct, ApproxMedian, ApproxPercentileCont, ArrayAgg, Avg,
BitAnd, BitOr, BitXor, BoolAnd, BoolOr, Correlation, Count, Covariance,
DistinctArrayAgg, DistinctCount, Max, Min, Stddev, Sum, Variance,
};

use arrow::datatypes::{DataType, Field};
use datafusion_common::{plan_err, ScalarValue};
use datafusion_expr::type_coercion::aggregates::NUMERICS;
use datafusion_expr::{type_coercion, Signature};
use super::*;

#[test]
fn test_count_arragg_approx_expr() -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions datafusion/physical-expr/src/conditional_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
// specific language governing permissions and limitations
// under the License.

use arrow::array::{new_null_array, Array, BooleanArray};
use arrow::compute::kernels::zip::zip;
use arrow::array::{Array, BooleanArray, new_null_array};
use arrow::compute::{and, is_not_null, is_null};
use arrow::compute::kernels::zip::zip;

use datafusion_common::{internal_err, DataFusionError, Result};
use datafusion_common::{DataFusionError, exec_err, Result};
use datafusion_expr::ColumnarValue;

/// coalesce evaluates to the first value which is not NULL
pub fn coalesce(args: &[ColumnarValue]) -> Result<ColumnarValue> {
// do not accept 0 arguments.
if args.is_empty() {
return internal_err!(
return exec_err!(
"coalesce was called with {} arguments. It requires at least 1.",
args.len()
);
Expand Down
16 changes: 8 additions & 8 deletions datafusion/physical-expr/src/crypto_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ use arrow::{
};
use blake2::{Blake2b512, Blake2s256, Digest};
use blake3::Hasher as Blake3;
use datafusion_common::ScalarValue;
use datafusion_common::{
cast::{as_binary_array, as_generic_binary_array, as_generic_string_array},
plan_err,
};
use datafusion_common::{exec_err, ScalarValue};
use datafusion_common::{internal_err, DataFusionError, Result};
use datafusion_expr::ColumnarValue;
use md5::Md5;
Expand Down Expand Up @@ -66,7 +66,7 @@ fn digest_process(
DataType::LargeBinary => {
digest_algorithm.digest_binary_array::<i64>(a.as_ref())
}
other => internal_err!(
other => exec_err!(
"Unsupported data type {other:?} for function {digest_algorithm}"
),
},
Expand All @@ -77,7 +77,7 @@ fn digest_process(
}
ScalarValue::Binary(a) | ScalarValue::LargeBinary(a) => Ok(digest_algorithm
.digest_scalar(a.as_ref().map(|v: &Vec<u8>| v.as_slice()))),
other => internal_err!(
other => exec_err!(
"Unsupported data type {other:?} for function {digest_algorithm}"
),
},
Expand Down Expand Up @@ -238,7 +238,7 @@ macro_rules! define_digest_function {
#[doc = $DOC]
pub fn $NAME(args: &[ColumnarValue]) -> Result<ColumnarValue> {
if args.len() != 1 {
return internal_err!(
return exec_err!(
"{:?} args were supplied but {} takes exactly one argument",
args.len(),
DigestAlgorithm::$METHOD.to_string()
Expand All @@ -264,7 +264,7 @@ fn hex_encode<T: AsRef<[u8]>>(data: T) -> String {
/// computes md5 hash digest of the given input
pub fn md5(args: &[ColumnarValue]) -> Result<ColumnarValue> {
if args.len() != 1 {
return internal_err!(
return exec_err!(
"{:?} args were supplied but {} takes exactly one argument",
args.len(),
DigestAlgorithm::Md5
Expand All @@ -284,7 +284,7 @@ pub fn md5(args: &[ColumnarValue]) -> Result<ColumnarValue> {
ColumnarValue::Scalar(ScalarValue::Binary(opt)) => {
ColumnarValue::Scalar(ScalarValue::Utf8(opt.map(hex_encode::<_>)))
}
_ => return internal_err!("Impossibly got invalid results from digest"),
_ => return exec_err!("Impossibly got invalid results from digest"),
})
}

Expand Down Expand Up @@ -329,7 +329,7 @@ define_digest_function!(
/// Standard algorithms are md5, sha1, sha224, sha256, sha384 and sha512.
pub fn digest(args: &[ColumnarValue]) -> Result<ColumnarValue> {
if args.len() != 2 {
return internal_err!(
return exec_err!(
"{:?} args were supplied but digest takes exactly two arguments",
args.len()
);
Expand All @@ -339,7 +339,7 @@ pub fn digest(args: &[ColumnarValue]) -> Result<ColumnarValue> {
ScalarValue::Utf8(Some(method)) | ScalarValue::LargeUtf8(Some(method)) => {
method.parse::<DigestAlgorithm>()
}
other => internal_err!("Unsupported data type {other:?} for function digest"),
other => exec_err!("Unsupported data type {other:?} for function digest"),
},
ColumnarValue::Array(_) => {
internal_err!("Digest using dynamically decided method is not yet supported")
Expand Down
Loading

0 comments on commit e9ea5d7

Please sign in to comment.