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

Method invoke_with_args

datafusion/functions/src/math/log.rs:232–305  ·  view source on GitHub ↗

Support overloaded log(base, x) and log(x) which defaults to log(10, x)

(&self, args: ScalarFunctionArgs)

Source from the content-addressed store, hash-verified

230
231 // Support overloaded log(base, x) and log(x) which defaults to log(10, x)
232 fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
233 if args.arg_fields.iter().any(|a| a.data_type().is_null()) {
234 return ColumnarValue::Scalar(ScalarValue::Null)
235 .cast_to(args.return_type(), None);
236 }
237
238 let (base, value) = if args.args.len() == 2 {
239 (args.args[0].clone(), &args.args[1])
240 } else {
241 // no base specified, default to 10
242 (
243 ColumnarValue::Scalar(ScalarValue::new_ten(args.return_type())?),
244 &args.args[0],
245 )
246 };
247 let value = value.to_array(args.number_rows)?;
248
249 let output: ArrayRef = match value.data_type() {
250 DataType::Float16 => {
251 calculate_binary_math::<Float16Type, Float16Type, Float16Type, _>(
252 &value,
253 &base,
254 |value, base| Ok(value.log(base)),
255 )?
256 }
257 DataType::Float32 => {
258 calculate_binary_math::<Float32Type, Float32Type, Float32Type, _>(
259 &value,
260 &base,
261 |value, base| Ok(value.log(base)),
262 )?
263 }
264 DataType::Float64 => {
265 calculate_binary_math::<Float64Type, Float64Type, Float64Type, _>(
266 &value,
267 &base,
268 |value, base| Ok(value.log(base)),
269 )?
270 }
271 DataType::Decimal32(_, scale) => {
272 calculate_binary_math::<Decimal32Type, Float64Type, Float64Type, _>(
273 &value,
274 &base,
275 |value, base| log_decimal32(value, *scale, base),
276 )?
277 }
278 DataType::Decimal64(_, scale) => {
279 calculate_binary_math::<Decimal64Type, Float64Type, Float64Type, _>(
280 &value,
281 &base,
282 |value, base| log_decimal64(value, *scale, base),
283 )?
284 }
285 DataType::Decimal128(_, scale) => {
286 calculate_binary_math::<Decimal128Type, Float64Type, Float64Type, _>(
287 &value,
288 &base,
289 |value, base| log_decimal128(value, *scale, base),

Callers 15

test_log_invalid_valueFunction · 0.45
test_log_scalar_f32Function · 0.45
test_log_scalar_f64Function · 0.45
test_log_f64_unaryFunction · 0.45
test_log_f32_unaryFunction · 0.45
test_log_f64Function · 0.45
test_log_f32Function · 0.45

Calls 14

log_decimal32Function · 0.85
log_decimal64Function · 0.85
log_decimal128Function · 0.85
log_decimal256Function · 0.85
logMethod · 0.80
anyMethod · 0.45
iterMethod · 0.45
is_nullMethod · 0.45
data_typeMethod · 0.45
cast_toMethod · 0.45
return_typeMethod · 0.45
lenMethod · 0.45

Tested by 15

test_log_invalid_valueFunction · 0.36
test_log_scalar_f32Function · 0.36
test_log_scalar_f64Function · 0.36
test_log_f64_unaryFunction · 0.36
test_log_f32_unaryFunction · 0.36
test_log_f64Function · 0.36
test_log_f32Function · 0.36