|
15 | 15 | // specific language governing permissions and limitations
|
16 | 16 | // under the License.
|
17 | 17 |
|
18 |
| -use arrow_schema::{Field, Schema}; |
19 |
| -use datafusion::{arrow::datatypes::DataType, logical_expr::Volatility}; |
20 |
| -use datafusion_expr::function::{AggregateFunctionSimplification, StateFieldsArgs}; |
21 |
| -use datafusion_expr::simplify::SimplifyInfo; |
22 |
| - |
23 | 18 | use std::{any::Any, sync::Arc};
|
24 | 19 |
|
| 20 | +use arrow_schema::{Field, Schema}; |
| 21 | + |
25 | 22 | use datafusion::arrow::{array::Float32Array, record_batch::RecordBatch};
|
26 | 23 | use datafusion::error::Result;
|
| 24 | +use datafusion::functions_aggregate::average::avg_udaf; |
| 25 | +use datafusion::{arrow::datatypes::DataType, logical_expr::Volatility}; |
27 | 26 | use datafusion::{assert_batches_eq, prelude::*};
|
28 | 27 | use datafusion_common::cast::as_float64_array;
|
| 28 | +use datafusion_expr::function::{AggregateFunctionSimplification, StateFieldsArgs}; |
| 29 | +use datafusion_expr::simplify::SimplifyInfo; |
29 | 30 | use datafusion_expr::{
|
30 |
| - expr::{AggregateFunction, AggregateFunctionDefinition}, |
31 |
| - function::AccumulatorArgs, |
32 |
| - Accumulator, AggregateUDF, AggregateUDFImpl, GroupsAccumulator, Signature, |
| 31 | + expr::AggregateFunction, function::AccumulatorArgs, Accumulator, AggregateUDF, |
| 32 | + AggregateUDFImpl, GroupsAccumulator, Signature, |
33 | 33 | };
|
34 | 34 |
|
35 | 35 | /// This example shows how to use the AggregateUDFImpl::simplify API to simplify/replace user
|
@@ -92,18 +92,16 @@ impl AggregateUDFImpl for BetterAvgUdaf {
|
92 | 92 | // with build-in aggregate function to illustrate the use
|
93 | 93 | let simplify = |aggregate_function: datafusion_expr::expr::AggregateFunction,
|
94 | 94 | _: &dyn SimplifyInfo| {
|
95 |
| - Ok(Expr::AggregateFunction(AggregateFunction { |
96 |
| - func_def: AggregateFunctionDefinition::BuiltIn( |
97 |
| - // yes it is the same Avg, `BetterAvgUdaf` was just a |
98 |
| - // marketing pitch :) |
99 |
| - datafusion_expr::aggregate_function::AggregateFunction::Avg, |
100 |
| - ), |
101 |
| - args: aggregate_function.args, |
102 |
| - distinct: aggregate_function.distinct, |
103 |
| - filter: aggregate_function.filter, |
104 |
| - order_by: aggregate_function.order_by, |
105 |
| - null_treatment: aggregate_function.null_treatment, |
106 |
| - })) |
| 95 | + Ok(Expr::AggregateFunction(AggregateFunction::new_udf( |
| 96 | + avg_udaf(), |
| 97 | + // yes it is the same Avg, `BetterAvgUdaf` was just a |
| 98 | + // marketing pitch :) |
| 99 | + aggregate_function.args, |
| 100 | + aggregate_function.distinct, |
| 101 | + aggregate_function.filter, |
| 102 | + aggregate_function.order_by, |
| 103 | + aggregate_function.null_treatment, |
| 104 | + ))) |
107 | 105 | };
|
108 | 106 |
|
109 | 107 | Some(Box::new(simplify))
|
|
0 commit comments