Skip to content

Commit

Permalink
chore: return internal error instead of panacing
Browse files Browse the repository at this point in the history
  • Loading branch information
appletreeisyellow committed May 20, 2024
1 parent 0f069b4 commit 55e3d16
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions datafusion/optimizer/src/single_distinct_to_groupby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,26 +216,24 @@ impl OptimizerRule for SingleDistinctToGroupBy {
..
}) => {
if distinct {
debug_assert_eq!(
args.len(),
1,
"DISTINCT aggregate should have exactly one argument"
);
if args.len() != 1 {
return internal_err!("DISTINCT aggregate should have exactly one argument");
}
let arg = args.swap_remove(0);

let expr_id = distinct_aggr_exprs.hasher().hash_one(&arg);
if distinct_aggr_exprs.insert(expr_id) {
inner_group_exprs
.push(arg.alias(SINGLE_DISTINCT_ALIAS));
}
Expr::AggregateFunction(AggregateFunction::new(
Ok(Expr::AggregateFunction(AggregateFunction::new(
fun,
vec![col(SINGLE_DISTINCT_ALIAS)],
false, // intentional to remove distinct here
None,
None,
None,
))
)))
// if the aggregate function is not distinct, we need to rewrite it like two phase aggregation
} else {
index += 1;
Expand All @@ -251,19 +249,19 @@ impl OptimizerRule for SingleDistinctToGroupBy {
))
.alias(&alias_str),
);
Expr::AggregateFunction(AggregateFunction::new(
Ok(Expr::AggregateFunction(AggregateFunction::new(
fun,
vec![col(&alias_str)],
false,
None,
None,
None,
))
)))
}
}
_ => aggr_expr,
_ => Ok(aggr_expr),
})
.collect::<Vec<_>>();
.collect::<Result<Vec<_>>>()?;

// construct the inner AggrPlan
let inner_agg = LogicalPlan::Aggregate(Aggregate::try_new(
Expand Down

0 comments on commit 55e3d16

Please sign in to comment.