Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions datafusion/physical-expr/src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ use crate::expressions::Column;

use arrow::compute::SortOptions;
use arrow::datatypes::{DataType, FieldRef, Schema, SchemaRef};
use datafusion_common::{internal_err, not_impl_err, Result, ScalarValue};
use datafusion_common::{
assert_or_internal_err, internal_err, not_impl_err, DataFusionError, Result,
ScalarValue,
};
use datafusion_expr::{AggregateUDF, ReversedUDAF, SetMonotonicity};
use datafusion_expr_common::accumulator::Accumulator;
use datafusion_expr_common::groups_accumulator::GroupsAccumulator;
Expand Down Expand Up @@ -198,9 +201,7 @@ impl AggregateExprBuilder {
is_distinct,
is_reversed,
} = self;
if args.is_empty() {
return internal_err!("args should not be empty");
}
assert_or_internal_err!(!args.is_empty(), "args should not be empty");

let ordering_types = order_bys
.iter()
Expand Down
33 changes: 16 additions & 17 deletions datafusion/physical-expr/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ use crate::PhysicalExpr;
use arrow::datatypes::Schema;
use datafusion_common::stats::Precision;
use datafusion_common::{
internal_datafusion_err, internal_err, ColumnStatistics, Result, ScalarValue,
assert_or_internal_err, internal_datafusion_err, internal_err, ColumnStatistics,
DataFusionError, Result, ScalarValue,
};
use datafusion_expr::interval_arithmetic::{cardinality_ratio, Interval};

Expand Down Expand Up @@ -170,19 +171,16 @@ pub fn analyze(
.iter()
.all(|bound| bound.interval.is_none())
{
if initial_boundaries
.iter()
.any(|bound| bound.distinct_count != Precision::Exact(0))
{
return internal_err!(
"ExprBoundaries has a non-zero distinct count although it represents an empty table"
);
}
if context.selectivity != Some(0.0) {
return internal_err!(
"AnalysisContext has a non-zero selectivity although it represents an empty table"
);
}
assert_or_internal_err!(
!initial_boundaries
.iter()
.any(|bound| bound.distinct_count != Precision::Exact(0)),
"ExprBoundaries has a non-zero distinct count although it represents an empty table"
);
assert_or_internal_err!(
context.selectivity == Some(0.0),
"AnalysisContext has a non-zero selectivity although it represents an empty table"
);
Ok(context)
} else if initial_boundaries
.iter()
Expand Down Expand Up @@ -257,9 +255,10 @@ fn shrink_boundaries(

let selectivity = calculate_selectivity(&target_boundaries, &initial_boundaries)?;

if !(0.0..=1.0).contains(&selectivity) {
return internal_err!("Selectivity is out of limit: {}", selectivity);
}
assert_or_internal_err!(
(0.0..=1.0).contains(&selectivity),
"Selectivity is out of limit: {selectivity}",
);

Ok(AnalysisContext::new(target_boundaries).with_selectivity(selectivity))
}
Expand Down
26 changes: 15 additions & 11 deletions datafusion/physical-expr/src/expressions/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use arrow::error::ArrowError;
use datafusion_common::cast::as_boolean_array;
use datafusion_common::tree_node::{Transformed, TreeNode, TreeNodeRecursion};
use datafusion_common::{
exec_err, internal_datafusion_err, internal_err, DataFusionError, HashMap, HashSet,
Result, ScalarValue,
assert_or_internal_err, exec_err, internal_datafusion_err, internal_err,
DataFusionError, HashMap, HashSet, Result, ScalarValue,
};
use datafusion_expr::ColumnarValue;
use datafusion_physical_expr_common::datum::compare_with_eq;
Expand Down Expand Up @@ -517,9 +517,10 @@ impl PartialResultIndex {
return internal_err!("Partial result index exceeds limit");
};

if index == NONE_VALUE {
return internal_err!("Partial result index exceeds limit");
}
assert_or_internal_err!(
index != NONE_VALUE,
"Partial result index exceeds limit"
);

Ok(Self { index })
}
Expand Down Expand Up @@ -663,9 +664,10 @@ impl ResultBuilder {
row_indices: &ArrayRef,
row_values: ArrayData,
) -> Result<()> {
if row_indices.null_count() != 0 {
return internal_err!("Row indices must not contain nulls");
}
assert_or_internal_err!(
row_indices.null_count() == 0,
"Row indices must not contain nulls"
);

match &mut self.state {
Empty => {
Expand All @@ -692,9 +694,11 @@ impl ResultBuilder {
// `case_when_with_expr` and `case_when_no_expr`, already ensure that
// they only calculate a value for each row at most once.
#[cfg(debug_assertions)]
if !indices[*row_ix as usize].is_none() {
return internal_err!("Duplicate value for row {}", *row_ix);
}
assert_or_internal_err!(
indices[*row_ix as usize].is_none(),
"Duplicate value for row {}",
*row_ix
);

indices[*row_ix as usize] = array_index;
}
Expand Down
12 changes: 6 additions & 6 deletions datafusion/physical-expr/src/expressions/in_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ use datafusion_common::cast::{
};
use datafusion_common::hash_utils::HashValue;
use datafusion_common::{
exec_err, internal_err, not_impl_err, DFSchema, Result, ScalarValue,
assert_or_internal_err, exec_err, not_impl_err, DFSchema, DataFusionError, Result,
ScalarValue,
};
use datafusion_expr::ColumnarValue;
use datafusion_physical_expr_common::datum::compare_with_eq;
Expand Down Expand Up @@ -459,11 +460,10 @@ pub fn in_list(
let expr_data_type = expr.data_type(schema)?;
for list_expr in list.iter() {
let list_expr_data_type = list_expr.data_type(schema)?;
if !DFSchema::datatype_is_logically_equal(&expr_data_type, &list_expr_data_type) {
return internal_err!(
"The data type inlist should be same, the value type is {expr_data_type}, one of list expr type is {list_expr_data_type}"
);
}
assert_or_internal_err!(
DFSchema::datatype_is_logically_equal(&expr_data_type, &list_expr_data_type),
"The data type inlist should be same, the value type is {expr_data_type}, one of list expr type is {list_expr_data_type}"
);
}
let static_filter = try_cast_static_filter_to_set(&list, schema).ok();
Ok(Arc::new(InListExpr::new(
Expand Down
11 changes: 5 additions & 6 deletions datafusion/physical-expr/src/expressions/like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use crate::PhysicalExpr;
use arrow::datatypes::{DataType, Schema};
use arrow::record_batch::RecordBatch;
use datafusion_common::{internal_err, Result};
use datafusion_common::{assert_or_internal_err, DataFusionError, Result};
use datafusion_expr::{ColumnarValue, Operator};
use datafusion_physical_expr_common::datum::apply_cmp;
use std::hash::Hash;
Expand Down Expand Up @@ -169,11 +169,10 @@ pub fn like(
) -> Result<Arc<dyn PhysicalExpr>> {
let expr_type = &expr.data_type(input_schema)?;
let pattern_type = &pattern.data_type(input_schema)?;
if !expr_type.eq(pattern_type) && !can_like_type(expr_type) {
return internal_err!(
"The type of {expr_type} AND {pattern_type} of like physical should be same"
);
}
assert_or_internal_err!(
expr_type.eq(pattern_type) || can_like_type(expr_type),
"The type of {expr_type} AND {pattern_type} of like physical should be same"
);
Ok(Arc::new(LikeExpr::new(
negated,
case_insensitive,
Expand Down
16 changes: 8 additions & 8 deletions datafusion/physical-expr/src/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ use crate::PhysicalExpr;
use arrow::datatypes::{Field, Schema, SchemaRef};
use datafusion_common::stats::{ColumnStatistics, Precision};
use datafusion_common::tree_node::{Transformed, TransformedResult, TreeNode};
use datafusion_common::{internal_datafusion_err, internal_err, plan_err, Result};
use datafusion_common::{
assert_or_internal_err, internal_datafusion_err, plan_err, DataFusionError, Result,
};

use datafusion_physical_expr_common::sort_expr::{LexOrdering, PhysicalSortExpr};
use indexmap::IndexMap;
Expand Down Expand Up @@ -625,13 +627,11 @@ impl ProjectionMapping {
let idx = col.index();
let matching_field = input_schema.field(idx);
let matching_name = matching_field.name();
if col.name() != matching_name {
return internal_err!(
"Input field name {} does not match with the projection expression {}",
matching_name,
col.name()
);
}
assert_or_internal_err!(
col.name() == matching_name,
"Input field name {matching_name} does not match with the projection expression {}",
col.name()
);
let matching_column = Column::new(matching_name, idx);
Ok(Transformed::yes(Arc::new(matching_column)))
}
Expand Down