Skip to content

Commit f98f1c5

Browse files
kumarUjjawal2010YOUY01
authored andcommitted
minor: refactor with assert_or_internal_err!() in datafusion/functions-nested (apache#18724)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes apache#123` indicates that this PR will close issue apache#123. --> - Part of apache#18613 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> --------- Co-authored-by: Yongting You <[email protected]>
1 parent b60ded0 commit f98f1c5

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

‎datafusion/functions-nested/src/position.rs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ use arrow::array::{
3737
use datafusion_common::cast::{
3838
as_generic_list_array, as_int64_array, as_large_list_array, as_list_array,
3939
};
40-
use datafusion_common::{exec_err, internal_err, utils::take_function_args, Result};
40+
use datafusion_common::{
41+
assert_or_internal_err, exec_err, utils::take_function_args, DataFusionError, Result,
42+
};
4143
use itertools::Itertools;
4244

4345
use crate::utils::{compare_element_to_list, make_scalar_function};
@@ -172,13 +174,11 @@ fn general_position_dispatch<O: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<Ar
172174

173175
// if `start_from` index is out of bounds, return error
174176
for (arr, &from) in list_array.iter().zip(arr_from.iter()) {
175-
if let Some(arr) = arr {
176-
if from < 0 || from as usize > arr.len() {
177-
return internal_err!("start_from index out of bounds");
178-
}
179-
} else {
180-
// We will get null if we got null in the array, so we don't need to check
181-
}
177+
// If `arr` is `None`: we will get null if we got null in the array, so we don't need to check
178+
assert_or_internal_err!(
179+
arr.is_none_or(|arr| from >= 0 && (from as usize) <= arr.len()),
180+
"start_from index out of bounds"
181+
);
182182
}
183183

184184
generic_position::<O>(list_array, element_array, arr_from)

‎datafusion/functions-nested/src/set_ops.rs‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ use arrow::datatypes::{DataType, Field, FieldRef};
2929
use arrow::row::{RowConverter, SortField};
3030
use datafusion_common::cast::{as_large_list_array, as_list_array};
3131
use datafusion_common::utils::ListCoercion;
32-
use datafusion_common::{exec_err, internal_err, utils::take_function_args, Result};
32+
use datafusion_common::{
33+
assert_eq_or_internal_err, exec_err, internal_err, utils::take_function_args,
34+
DataFusionError, Result,
35+
};
3336
use datafusion_expr::{
3437
ColumnarValue, Documentation, ScalarUDFImpl, Signature, Volatility,
3538
};
@@ -353,9 +356,11 @@ fn generic_set_lists<OffsetSize: OffsetSizeTrait>(
353356
return general_array_distinct::<OffsetSize>(l, &field);
354357
}
355358

356-
if l.value_type() != r.value_type() {
357-
return internal_err!("{set_op:?} is not implemented for '{l:?}' and '{r:?}'");
358-
}
359+
assert_eq_or_internal_err!(
360+
l.value_type(),
361+
r.value_type(),
362+
"{set_op:?} is not implemented for '{l:?}' and '{r:?}'"
363+
);
359364

360365
let mut offsets = vec![OffsetSize::usize_as(0)];
361366
let mut new_arrays = vec![];

0 commit comments

Comments
 (0)