Skip to content

Commit d59ebac

Browse files
feat(spark): implement Spark try_sum function (#18569)
## Which issue does this PR close? part of #15914 ## Rationale for this change Migrate spark functions from https://github.com/lakehq/sail/ to datafusion engine to unify codebase ## What changes are included in this PR? implement spark udaf try_sum https://spark.apache.org/docs/latest/api/sql/index.html#try_sum ## Are these changes tested? unit-tests and sqllogictests added ## Are there any user-facing changes? now can be called in queries
1 parent ead8209 commit d59ebac

File tree

3 files changed

+811
-1
lines changed

3 files changed

+811
-1
lines changed

datafusion/spark/src/function/aggregate/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,27 @@ use datafusion_expr::AggregateUDF;
1919
use std::sync::Arc;
2020

2121
pub mod avg;
22+
pub mod try_sum;
23+
2224
pub mod expr_fn {
2325
use datafusion_functions::export_functions;
2426

2527
export_functions!((avg, "Returns the average value of a given column", arg1));
28+
export_functions!((
29+
try_sum,
30+
"Returns the sum of values for a column, or NULL if overflow occurs",
31+
arg1
32+
));
2633
}
2734

2835
// TODO: try use something like datafusion_functions_aggregate::create_func!()
2936
pub fn avg() -> Arc<AggregateUDF> {
3037
Arc::new(AggregateUDF::new_from_impl(avg::SparkAvg::new()))
3138
}
39+
pub fn try_sum() -> Arc<AggregateUDF> {
40+
Arc::new(AggregateUDF::new_from_impl(try_sum::SparkTrySum::new()))
41+
}
3242

3343
pub fn functions() -> Vec<Arc<AggregateUDF>> {
34-
vec![avg()]
44+
vec![avg(), try_sum()]
3545
}

0 commit comments

Comments
 (0)