SteveLauC commented on code in PR #9297: URL: https://github.com/apache/arrow-datafusion/pull/9297#discussion_r1497196067
########## datafusion/functions/src/math/acos.rs: ########## @@ -0,0 +1,86 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Math function: `acos()`. + +use arrow::datatypes::DataType; +use datafusion_common::{internal_err, Result, DataFusionError}; +use datafusion_expr::ColumnarValue; + +use datafusion_expr::{ScalarUDFImpl, Signature, Volatility}; +use std::any::Any; +use std::sync::Arc; +use arrow::array::{ArrayRef, Float32Array, Float64Array}; + +#[derive(Debug)] +pub struct AcosFunc { + signature: Signature, +} + +impl AcosFunc { + pub fn new() -> Self { + use DataType::*; + Self { + signature: + Signature::uniform(1, vec![Float64, Float32], Volatility::Immutable) + } + } +} + +impl ScalarUDFImpl for AcosFunc { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "acos" + } + + fn signature(&self) -> &Signature { + &self.signature + } + + fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> { + Ok(arg_types[0].clone()) + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> { + let args = ColumnarValue::values_to_arrays(args)?; + + let arr: ArrayRef = match args[0].data_type() { + DataType::Float64 => { + Arc::new(make_function_scalar_inputs_return_type!( + &args[0], + self.name(), + Float64Array, + Float64Array, + { f64::acos } + )) + }, + DataType::Float32 => { + Arc::new(make_function_scalar_inputs_return_type!( + &args[0], + "x", Review Comment: ```suggestion self.name(), ``` I forgot to change this one, BTW, should this be done? I saw that `isnan()` [is using `"x"`](https://github.com/apache/arrow-datafusion/blob/6fad5ed7a37c50b9c200f214c3e13b0e1f0cecbc/datafusion/functions/src/math/nans.rs#L71) ########## datafusion/functions/src/math/mod.rs: ########## @@ -15,15 +15,18 @@ // specific language governing permissions and limitations // under the License. -//! "core" DataFusion functions +//! "math" DataFusion functions Review Comment: Seems to be a copy-paste error, so I changed it ########## datafusion/proto/tests/cases/roundtrip_physical_plan.rs: ########## @@ -589,34 +586,6 @@ async fn roundtrip_parquet_exec_with_table_partition_cols() -> Result<()> { roundtrip_test(Arc::new(ParquetExec::new(scan_config, None, None))) } -#[test] -fn roundtrip_builtin_scalar_function() -> Result<()> { Review Comment: I removed this test because we are going to elimiate buit-in functions ########## datafusion/proto/Cargo.toml: ########## @@ -47,6 +47,7 @@ chrono = { workspace = true } datafusion = { path = "../core", version = "36.0.0" } datafusion-common = { workspace = true } datafusion-expr = { workspace = true } +datafusion-functions = { workspace = true } Review Comment: I should remove this as it is unused ########## datafusion/functions/src/math/nans.rs: ########## @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -//! Encoding expressions Review Comment: Also, seems to be a copy-paste error -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org