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

Method invoke_with_args

datafusion/functions/src/math/cot.rs:93–135  ·  view source on GitHub ↗
(&self, args: ScalarFunctionArgs)

Source from the content-addressed store, hash-verified

91 }
92
93 fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
94 let return_field = args.return_field;
95 let [arg] = take_function_args(self.name(), args.args)?;
96
97 match arg {
98 ColumnarValue::Scalar(scalar) => {
99 if scalar.is_null() {
100 return ColumnarValue::Scalar(ScalarValue::Null)
101 .cast_to(return_field.data_type(), None);
102 }
103
104 match scalar {
105 ScalarValue::Float64(Some(v)) => Ok(ColumnarValue::Scalar(
106 ScalarValue::Float64(Some(compute_cot64(v))),
107 )),
108 ScalarValue::Float32(Some(v)) => Ok(ColumnarValue::Scalar(
109 ScalarValue::Float32(Some(compute_cot32(v))),
110 )),
111 _ => {
112 internal_err!(
113 "Unexpected scalar type for cot: {:?}",
114 scalar.data_type()
115 )
116 }
117 }
118 }
119 ColumnarValue::Array(array) => match array.data_type() {
120 Float64 => Ok(ColumnarValue::Array(Arc::new(
121 array
122 .as_primitive::<Float64Type>()
123 .unary::<_, Float64Type>(compute_cot64),
124 ))),
125 Float32 => Ok(ColumnarValue::Array(Arc::new(
126 array
127 .as_primitive::<Float32Type>()
128 .unary::<_, Float32Type>(compute_cot32),
129 ))),
130 other => {
131 internal_err!("Unexpected data type {other:?} for function cot")
132 }
133 },
134 }
135 }
136}
137
138fn compute_cot32(x: f32) -> f32 {

Callers 7

test_cot_f32Function · 0.45
test_cot_f64Function · 0.45
test_cot_scalar_f64Function · 0.45
test_cot_scalar_f32Function · 0.45
test_cot_scalar_nullFunction · 0.45
test_cot_scalar_zeroFunction · 0.45
test_cot_scalar_piFunction · 0.45

Calls 8

take_function_argsFunction · 0.85
compute_cot64Function · 0.85
compute_cot32Function · 0.85
newFunction · 0.85
nameMethod · 0.45
is_nullMethod · 0.45
cast_toMethod · 0.45
data_typeMethod · 0.45

Tested by 7

test_cot_f32Function · 0.36
test_cot_f64Function · 0.36
test_cot_scalar_f64Function · 0.36
test_cot_scalar_f32Function · 0.36
test_cot_scalar_nullFunction · 0.36
test_cot_scalar_zeroFunction · 0.36
test_cot_scalar_piFunction · 0.36