From 9a4876e0addd14be7d5b45b28b7a7907d43631b9 Mon Sep 17 00:00:00 2001 From: Rui Mo Date: Thu, 15 Jul 2021 13:32:47 +0800 Subject: [PATCH] Add int32 support and change format of castVarchar (#26) * add support to int32 type * fix fortmat of cast varchar --- cpp/src/gandiva/function_registry_datetime.cc | 9 +++++++++ cpp/src/gandiva/precompiled/arithmetic_ops.cc | 12 ++++++++---- cpp/src/gandiva/precompiled/time.cc | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/cpp/src/gandiva/function_registry_datetime.cc b/cpp/src/gandiva/function_registry_datetime.cc index a5bc662530a19..b43b58b03eb52 100644 --- a/cpp/src/gandiva/function_registry_datetime.cc +++ b/cpp/src/gandiva/function_registry_datetime.cc @@ -164,12 +164,21 @@ std::vector GetDateTimeFunctionRegistry() { NativeFunction("seconds_to_timestamp", {}, DataTypeVector{int64()}, timestampusutc(), kResultNullIfNull, "seconds_to_timestamp_int64"), + NativeFunction("seconds_to_timestamp", {}, DataTypeVector{int32()}, timestampusutc(), + kResultNullIfNull, "seconds_to_timestamp_int32"), + NativeFunction("millis_to_timestamp", {}, DataTypeVector{int64()}, timestampusutc(), kResultNullIfNull, "millis_to_timestamp_int64"), + + NativeFunction("millis_to_timestamp", {}, DataTypeVector{int32()}, timestampusutc(), + kResultNullIfNull, "millis_to_timestamp_int32"), NativeFunction("micros_to_timestamp", {}, DataTypeVector{int64()}, timestampusutc(), kResultNullIfNull, "micros_to_timestamp_int64"), + NativeFunction("micros_to_timestamp", {}, DataTypeVector{int32()}, timestampusutc(), + kResultNullIfNull, "micros_to_timestamp_int32"), + NativeFunction("date_diff", {}, DataTypeVector{date32(), date32()}, int32(), kResultNullIfNull, "micros_to_timestamp_date32_date32"), diff --git a/cpp/src/gandiva/precompiled/arithmetic_ops.cc b/cpp/src/gandiva/precompiled/arithmetic_ops.cc index 6fa04da419f35..676a52795e309 100644 --- a/cpp/src/gandiva/precompiled/arithmetic_ops.cc +++ b/cpp/src/gandiva/precompiled/arithmetic_ops.cc @@ -300,10 +300,14 @@ CAST_UNARY_UTF8(castVARCHAR, int8, utf8, "%d", NOFMT, nothing) CAST_UNARY_UTF8(castVARCHAR, int16, utf8, "%d", NOFMT, nothing) CAST_UNARY_UTF8(castVARCHAR, int32, utf8, "%d", NOFMT, nothing) CAST_UNARY_UTF8(castVARCHAR, int64, utf8, "%ld", NOFMT, nothing) -// CAST_UNARY_UTF8(castVARCHAR, float32, utf8, "%.*f", FMT, FLT_DIG) -// CAST_UNARY_UTF8(castVARCHAR, float64, utf8, "%.*f", FMT, DBL_DIG) -CAST_UNARY_UTF8(castVARCHAR, float32, utf8, "%g", NOFMT, nothing) -CAST_UNARY_UTF8(castVARCHAR, float64, utf8, "%g", NOFMT, nothing) +// We set to display the full precision of Float/Double, but this may still behave +// differently with vanilla spark. +CAST_UNARY_UTF8(castVARCHAR, float32, utf8, "%.*f", FMT, FLT_DIG) +CAST_UNARY_UTF8(castVARCHAR, float64, utf8, "%.*f", FMT, DBL_DIG) +// %g means converting floating-point number depending on the value and the precision. +// It bahaves similar to the shortest representation. +// CAST_UNARY_UTF8(castVARCHAR, float32, utf8, "%g", NOFMT, nothing) +// CAST_UNARY_UTF8(castVARCHAR, float64, utf8, "%g", NOFMT, nothing) #undef CAST_UNARY_UTF8 diff --git a/cpp/src/gandiva/precompiled/time.cc b/cpp/src/gandiva/precompiled/time.cc index 8ce7d40f903c8..d71ed93979fd6 100644 --- a/cpp/src/gandiva/precompiled/time.cc +++ b/cpp/src/gandiva/precompiled/time.cc @@ -990,16 +990,31 @@ gdv_timestamp seconds_to_timestamp_int64(gdv_int64 in) { return in * 1000000; } +FORCE_INLINE +gdv_timestamp seconds_to_timestamp_int32(gdv_int32 in) { + return (int64_t)in * 1000000; +} + FORCE_INLINE gdv_timestamp millis_to_timestamp_int64(gdv_int64 in) { return in * 1000; } +FORCE_INLINE +gdv_timestamp millis_to_timestamp_int32(gdv_int32 in) { + return (int64_t)in * 1000; +} + FORCE_INLINE gdv_timestamp micros_to_timestamp_int64(gdv_int64 in) { return in; } +FORCE_INLINE +gdv_timestamp micros_to_timestamp_int32(gdv_int32 in) { + return (int64_t)in; +} + FORCE_INLINE gdv_int32 micros_to_timestamp_date32_date32(gdv_date32 left, gdv_date32 right) { return left - right;