parthchandra commented on code in PR #500: URL: https://github.com/apache/datafusion-comet/pull/500#discussion_r1628118524
########## core/src/execution/datafusion/expressions/abs.rs: ########## @@ -0,0 +1,87 @@ +// 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. + +use arrow::datatypes::DataType; +use arrow_schema::ArrowError; +use datafusion::logical_expr::{ColumnarValue, ScalarUDFImpl, Signature}; +use datafusion_common::DataFusionError; +use datafusion_functions::math; +use std::{any::Any, sync::Arc}; + +use crate::errors::CometError; + +use super::EvalMode; + +fn arithmetic_overflow_error(from_type: &str) -> CometError { + CometError::ArithmeticOverflow { + from_type: from_type.to_string(), + } +} + +#[derive(Debug)] +pub struct CometAbsFunc { + inner_abs_func: Arc<dyn ScalarUDFImpl>, + eval_mode: EvalMode, + data_type_name: String, +} + +impl CometAbsFunc { + pub fn new(eval_mode: EvalMode, data_type_name: String) -> Self { + Self { + inner_abs_func: math::abs().inner(), + eval_mode, + data_type_name, + } + } +} + +impl ScalarUDFImpl for CometAbsFunc { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { + "abs" + } + + fn signature(&self) -> &Signature { + self.inner_abs_func.signature() + } + + fn return_type(&self, arg_types: &[DataType]) -> Result<DataType, DataFusionError> { + self.inner_abs_func.return_type(arg_types) + } + + fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue, DataFusionError> { + match self.inner_abs_func.invoke(args) { + Ok(result) => Ok(result), + Err(DataFusionError::ArrowError(ArrowError::ComputeError(msg), trace)) + if msg.contains("overflow") => Review Comment: We can continue with this and do a follow up once the arrow-rs change is available. Or you can wait; the arrow-rs community is very responsive. -- 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...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org