MCPcopy Create free account
hub / github.com/apache/datafusion / build

Method build

datafusion/physical-expr/src/aggregate.rs:250–322  ·  view source on GitHub ↗

Constructs an `AggregateFunctionExpr` from the builder Note that an [`Self::alias`] must be provided before calling this method. # Example: Create an [`AggregateUDF`] In the following example, [`AggregateFunctionExpr`] will be built using [`AggregateExprBuilder`] which provides a build function. Full example could be accessed from the source file. ``` # use std::any::Any; # use std::sync::Arc;

(self)

Source from the content-addressed store, hash-verified

248 /// This creates a physical expression equivalent to SQL:
249 /// `first_value(a ORDER BY x) IGNORE NULLS AS first_a_by_x`
250 pub fn build(self) -> Result<AggregateFunctionExpr> {
251 let Self {
252 fun,
253 args,
254 alias,
255 output_metadata,
256 human_display,
257 human_display_alias,
258 schema,
259 order_bys,
260 ignore_nulls,
261 is_distinct,
262 is_reversed,
263 } = self;
264 assert_or_internal_err!(!args.is_empty(), "args should not be empty");
265
266 let ordering_types = order_bys
267 .iter()
268 .map(|e| e.expr.data_type(&schema))
269 .collect::<Result<Vec<_>>>()?;
270
271 let ordering_fields = utils::ordering_fields(&order_bys, &ordering_types);
272
273 let input_exprs_fields = args
274 .iter()
275 .map(|arg| arg.return_field(&schema))
276 .collect::<Result<Vec<_>>>()?;
277
278 check_arg_count(
279 fun.name(),
280 &input_exprs_fields,
281 &fun.signature().type_signature,
282 )?;
283
284 let mut return_field = fun.return_field(&input_exprs_fields)?;
285 if let Some(output_metadata) = output_metadata {
286 return_field = output_metadata.add_to_field_ref(return_field);
287 }
288 let is_nullable = fun.is_nullable();
289 let name = match alias {
290 None => {
291 return internal_err!(
292 "AggregateExprBuilder::alias must be provided prior to calling build"
293 );
294 }
295 Some(alias) => alias,
296 };
297
298 let human_display =
299 AggregateHumanDisplay::try_new(human_display, human_display_alias, &name)?;
300
301 let arg_fields = args
302 .iter()
303 .map(|e| e.return_field(schema.as_ref()))
304 .collect::<Result<Vec<_>>>()?;
305
306 Ok(AggregateFunctionExpr {
307 fun: Arc::unwrap_or_clone(fun),

Calls 15

ordering_fieldsFunction · 0.85
check_arg_countFunction · 0.85
lower_aggregate_displayFunction · 0.85
physical_nameFunction · 0.85
create_physical_exprsFunction · 0.85
create_physical_exprFunction · 0.85
newFunction · 0.85
add_to_field_refMethod · 0.80
with_distinctMethod · 0.80
with_ignore_nullsMethod · 0.80
output_metadataMethod · 0.80