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

Method invoke_with_args

datafusion/functions/src/math/power.rs:424–562  ·  view source on GitHub ↗
(&self, args: ScalarFunctionArgs)

Source from the content-addressed store, hash-verified

422 }
423
424 fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
425 let [base, exponent] = take_function_args(self.name(), &args.args)?;
426
427 // For decimal types, only use native decimal
428 // operations when we have a scalar exponent. When the exponent is an array,
429 // fall back to float computation for better performance.
430 let use_float_fallback = matches!(
431 base.data_type(),
432 DataType::Decimal32(_, _)
433 | DataType::Decimal64(_, _)
434 | DataType::Decimal128(_, _)
435 | DataType::Decimal256(_, _)
436 ) && matches!(exponent, ColumnarValue::Array(_));
437
438 let base = base.to_array(args.number_rows)?;
439
440 // If decimal with array exponent, cast to float and compute
441 if use_float_fallback {
442 return pow_decimal_with_float_fallback(&base, exponent, args.number_rows);
443 }
444
445 let arr: ArrayRef = match (base.data_type(), exponent.data_type()) {
446 (DataType::Float64, DataType::Float64) => {
447 calculate_binary_math::<Float64Type, Float64Type, Float64Type, _>(
448 &base,
449 exponent,
450 float64_power_checked,
451 )?
452 }
453 (DataType::Decimal32(precision, scale), DataType::Int64) => {
454 calculate_binary_decimal_math::<Decimal32Type, Int64Type, Decimal32Type, _>(
455 &base,
456 exponent,
457 |b, e| pow_decimal_int(b, *scale, e),
458 *precision,
459 *scale,
460 )?
461 }
462 (DataType::Decimal32(precision, scale), DataType::Float64) => {
463 calculate_binary_decimal_math::<
464 Decimal32Type,
465 Float64Type,
466 Decimal32Type,
467 _,
468 >(
469 &base,
470 exponent,
471 |b, e| pow_decimal_float(b, *scale, e),
472 *precision,
473 *scale,
474 )?
475 }
476 (DataType::Decimal64(precision, scale), DataType::Int64) => {
477 calculate_binary_decimal_math::<Decimal64Type, Int64Type, Decimal64Type, _>(
478 &base,
479 exponent,
480 |b, e| pow_decimal_int(b, *scale, e),
481 *precision,

Callers

nothing calls this directly

Calls 9

take_function_argsFunction · 0.85
pow_decimal_intFunction · 0.85
pow_decimal_floatFunction · 0.85
pow_decimal256_intFunction · 0.85
pow_decimal256_floatFunction · 0.85
nameMethod · 0.45
to_arrayMethod · 0.45
data_typeMethod · 0.45

Tested by

no test coverage detected