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

Function round_arrays

datafusion/functions/src/math/round.rs:736–756  ·  view source on GitHub ↗
(
        value: ArrayRef,
        decimal_places: Option<ArrayRef>,
    )

Source from the content-addressed store, hash-verified

734 use datafusion_expr::ColumnarValue;
735
736 fn round_arrays(
737 value: ArrayRef,
738 decimal_places: Option<ArrayRef>,
739 ) -> Result<ArrayRef, DataFusionError> {
740 let number_rows = value.len();
741 // NOTE: For decimal inputs, the actual ROUND return type can differ from the
742 // input type (scale reduction for literal `decimal_places`). These unit tests
743 // only exercise Float32/Float64 behavior.
744 let return_type = value.data_type().clone();
745 let value = ColumnarValue::Array(value);
746 let decimal_places = decimal_places
747 .map(ColumnarValue::Array)
748 .unwrap_or_else(|| ColumnarValue::Scalar(ScalarValue::Int32(Some(0))));
749
750 let result =
751 super::round_columnar(&value, &decimal_places, number_rows, &return_type)?;
752 match result {
753 ColumnarValue::Array(array) => Ok(array),
754 ColumnarValue::Scalar(scalar) => scalar.to_array_of_size(1),
755 }
756 }
757
758 #[test]
759 fn test_round_f32() {

Callers 5

test_round_f32Function · 0.85
test_round_f64Function · 0.85
test_round_f32_one_inputFunction · 0.85
test_round_f64_one_inputFunction · 0.85
test_round_f32_cast_failFunction · 0.85

Calls 6

round_columnarFunction · 0.85
lenMethod · 0.45
cloneMethod · 0.45
data_typeMethod · 0.45
mapMethod · 0.45
to_array_of_sizeMethod · 0.45

Tested by 5

test_round_f32Function · 0.68
test_round_f64Function · 0.68
test_round_f32_one_inputFunction · 0.68
test_round_f64_one_inputFunction · 0.68
test_round_f32_cast_failFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…