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

Function pow_decimal_with_float_fallback

datafusion/functions/src/math/power.rs:375–401  ·  view source on GitHub ↗

Fallback implementation for decimal power when exponent is an array. Casts decimal to float64, computes power, and casts back to original decimal type. This is used for performance when exponent varies per-row.

(
    base: &ArrayRef,
    exponent: &ColumnarValue,
    num_rows: usize,
)

Source from the content-addressed store, hash-verified

373/// Casts decimal to float64, computes power, and casts back to original decimal type.
374/// This is used for performance when exponent varies per-row.
375fn pow_decimal_with_float_fallback(
376 base: &ArrayRef,
377 exponent: &ColumnarValue,
378 num_rows: usize,
379) -> Result<ColumnarValue> {
380 use arrow::compute::cast;
381
382 let original_type = base.data_type().clone();
383 let base_f64 = cast(base.as_ref(), &DataType::Float64)?;
384
385 let exp_f64 = match exponent {
386 ColumnarValue::Array(arr) => cast(arr.as_ref(), &DataType::Float64)?,
387 ColumnarValue::Scalar(scalar) => {
388 let scalar_f64 = scalar.cast_to(&DataType::Float64)?;
389 scalar_f64.to_array_of_size(num_rows)?
390 }
391 };
392
393 let result_f64 = calculate_binary_math::<Float64Type, Float64Type, Float64Type, _>(
394 &base_f64,
395 &ColumnarValue::Array(exp_f64),
396 float64_power_checked,
397 )?;
398
399 let result = cast(result_f64.as_ref(), &original_type)?;
400 Ok(ColumnarValue::Array(result))
401}
402
403impl ScalarUDFImpl for PowerFunc {
404 fn name(&self) -> &str {

Callers 1

invoke_with_argsMethod · 0.85

Calls 6

castFunction · 0.50
cloneMethod · 0.45
data_typeMethod · 0.45
as_refMethod · 0.45
cast_toMethod · 0.45
to_array_of_sizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…