comphead commented on code in PR #18205: URL: https://github.com/apache/datafusion/pull/18205#discussion_r2450031697
########## datafusion/spark/src/function/math/abs.rs: ########## @@ -0,0 +1,1136 @@ +// 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 crate::function::error_utils::{ + invalid_arg_count_exec_err, unsupported_data_type_exec_err, +}; +use arrow::array::*; +use arrow::datatypes::DataType; +use arrow::datatypes::*; +use datafusion_common::DataFusionError::ArrowError; +use datafusion_common::{internal_err, DataFusionError, Result, ScalarValue}; +use datafusion_expr::{ + ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Signature, Volatility, +}; +use std::any::Any; +use std::sync::Arc; + +/// Spark-compatible `abs` expression +/// <https://spark.apache.org/docs/latest/api/sql/index.html#abs> +/// +/// Returns the absolute value of input +/// Returns NULL if input is NULL, returns NaN if input is NaN. +/// +/// Differences with DataFusion abs: +/// - Spark's ANSI-compliant dialect, when off (i.e. `spark.sql.ansi.enabled=false`), taking absolute values on minimal values of signed integers returns the value as is. DataFusion's abs throws "DataFusion error: Arrow error: Compute error" on arithmetic overflow +/// - Spark's abs also supports ANSI interval types: YearMonthIntervalType and DayTimeIntervalType. DataFusion's abs doesn't. +/// +#[derive(Debug, PartialEq, Eq, Hash)] +pub struct SparkAbs { + signature: Signature, +} + +impl Default for SparkAbs { + fn default() -> Self { + Self::new() + } +} + +impl SparkAbs { + pub fn new() -> Self { + Self { + signature: Signature::user_defined(Volatility::Immutable), Review Comment: ```suggestion signature: Signature::numeric(1, Volatility::Immutable), ``` Lets keep it this way for now since the PR doesn't support Intervals -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
