From d887dea80a5a8aa648fa5fd2de5bae44596285c4 Mon Sep 17 00:00:00 2001 From: Yuan Zhou Date: Fri, 15 May 2020 10:35:53 +0800 Subject: [PATCH 1/2] [C++][Gandiva] Adding abs function Signed-off-by: Yuan Zhou --- .../gandiva/precompiled/extended_math_ops.cc | 18 ++++++++++++++++++ cpp/src/gandiva/precompiled/types.h | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/cpp/src/gandiva/precompiled/extended_math_ops.cc b/cpp/src/gandiva/precompiled/extended_math_ops.cc index e6b6a6e3af111..7f482f95b26b6 100644 --- a/cpp/src/gandiva/precompiled/extended_math_ops.cc +++ b/cpp/src/gandiva/precompiled/extended_math_ops.cc @@ -72,6 +72,24 @@ ENUMERIC_TYPES_UNARY(LOG, float64) ENUMERIC_TYPES_UNARY(LOG10, float64) +// abs +#define ABS_TYPES_UNARY(IN_TYPE, OUT_TYPE) \ + FORCE_INLINE \ + gdv_##OUT_TYPE abs_##IN_TYPE(gdv_##IN_TYPE in) { \ + return static_cast(abs((in))); \ + } + +#define ABS_FTYPES_UNARY(IN_TYPE, OUT_TYPE) \ + FORCE_INLINE \ + gdv_##OUT_TYPE abs_##IN_TYPE(gdv_##IN_TYPE in) { \ + return static_cast(fabs((in))); \ + } + +ABS_TYPES_UNARY(int32, uint32) +ABS_TYPES_UNARY(int64, uint64) +ABS_FTYPES_UNARY(float32, float32) +ABS_FTYPES_UNARY(float64, float64) + FORCE_INLINE void set_error_for_logbase(int64_t execution_context, double base) { char const* prefix = "divide by zero error with log of base"; diff --git a/cpp/src/gandiva/precompiled/types.h b/cpp/src/gandiva/precompiled/types.h index 11529bf014b02..8b2823621aa9c 100644 --- a/cpp/src/gandiva/precompiled/types.h +++ b/cpp/src/gandiva/precompiled/types.h @@ -152,6 +152,11 @@ gdv_float64 log10_int64(gdv_int64); gdv_float64 log10_float32(gdv_float32); gdv_float64 log10_float64(gdv_float64); +gdv_uint32 abs_int32(gdv_int32); +gdv_uint64 abs_int64(gdv_int64); +gdv_float32 abs_float32(gdv_float32); +gdv_float64 abs_float64(gdv_float64); + gdv_float64 power_float64_float64(gdv_float64, gdv_float64); gdv_float64 log_int32_int32(gdv_int64 context, gdv_int32 base, gdv_int32 value); From 43e48bdd1d67f751e28ae6f582584c2e9f2f731f Mon Sep 17 00:00:00 2001 From: Yuan Zhou Date: Fri, 15 May 2020 14:52:20 +0800 Subject: [PATCH 2/2] [C++][Gandiva] update function registry for abs Signed-off-by: Yuan Zhou --- cpp/src/gandiva/function_registry_math_ops.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cpp/src/gandiva/function_registry_math_ops.cc b/cpp/src/gandiva/function_registry_math_ops.cc index 771e363e3048f..722b908f2eb7a 100644 --- a/cpp/src/gandiva/function_registry_math_ops.cc +++ b/cpp/src/gandiva/function_registry_math_ops.cc @@ -59,6 +59,11 @@ std::vector GetMathOpsFunctionRegistry() { BINARY_SAFE_NULL_NEVER_BOOL_FN(is_distinct_from, {}), BINARY_SAFE_NULL_NEVER_BOOL_FN(is_not_distinct_from, {}), + UNARY_SAFE_NULL_IF_NULL(abs, {}, int32, uint32), + UNARY_SAFE_NULL_IF_NULL(abs, {}, int64, uint64), + UNARY_SAFE_NULL_IF_NULL(abs, {}, float32, float32), + UNARY_SAFE_NULL_IF_NULL(abs, {}, float64, float64), + // decimal functions UNARY_SAFE_NULL_IF_NULL(abs, {}, decimal128, decimal128), UNARY_SAFE_NULL_IF_NULL(ceil, {}, decimal128, decimal128),