From 794f3c9b1dd8835ee4686e4d349eff895c11e41d Mon Sep 17 00:00:00 2001 From: JiaKe Date: Thu, 8 Apr 2021 14:25:14 +0800 Subject: [PATCH] add the timestamp unit convert and date64 to date32 convert (#10) --- cpp/src/gandiva/function_registry_datetime.cc | 9 +++++++++ cpp/src/gandiva/precompiled/time.cc | 12 ++++++++++++ cpp/src/gandiva/precompiled/types.h | 3 +++ 3 files changed, 24 insertions(+) diff --git a/cpp/src/gandiva/function_registry_datetime.cc b/cpp/src/gandiva/function_registry_datetime.cc index 1b86aa69c251a..1b5ccfea239e1 100644 --- a/cpp/src/gandiva/function_registry_datetime.cc +++ b/cpp/src/gandiva/function_registry_datetime.cc @@ -131,6 +131,15 @@ std::vector GetDateTimeFunctionRegistry() { DATE_TYPES(LAST_DAY_SAFE_NULL_IF_NULL, last_day, {}), BASE_NUMERIC_TYPES(TO_TIME_SAFE_NULL_IF_NULL, to_time, {}), BASE_NUMERIC_TYPES(TO_TIMESTAMP_SAFE_NULL_IF_NULL, to_timestamp, {})}; + NativeFunction("convertTimestampUnit", {}, DataTypeVector{timestamp()}, arrow::timestamp(arrow::TimeUnit::MICRO), + kResultNullIfNull, "convertTimestampUnit_ms"), + + NativeFunction("convertTimestampUnit", {}, DataTypeVector{arrow::timestamp(arrow::TimeUnit::MICRO)}, timestamp(), + kResultNullIfNull, "convertTimestampUnit_us"), + + NativeFunction("castDATE", {}, DataTypeVector{date64()}, date32(), + kResultNullIfNull, "castDATE_date64"), + DATE_TYPES(LAST_DAY_SAFE_NULL_IF_NULL, last_day, {}); return date_time_fn_registry_; } diff --git a/cpp/src/gandiva/precompiled/time.cc b/cpp/src/gandiva/precompiled/time.cc index 533545c51c0f0..49232fcf9bf78 100644 --- a/cpp/src/gandiva/precompiled/time.cc +++ b/cpp/src/gandiva/precompiled/time.cc @@ -818,6 +818,18 @@ gdv_time32 castTIME_timestamp(gdv_timestamp timestamp_in_millis) { return static_cast(millis_since_midnight); } +gdv_timestamp convertTimestampUnit_ms(gdv_timestamp timestamp_in_millis) { + return timestamp_in_millis * 1000; +} + +gdv_timestamp convertTimestampUnit_us(gdv_timestamp timestamp_in_micro) { + return timestamp_in_micro / 1000; +} + +gdv_date32 castDATE_date64(gdv_date64 date_in_millis) { + return static_cast(date_in_millis / (MILLIS_IN_DAY)); +} + const char* castVARCHAR_timestamp_int64(gdv_int64 context, gdv_timestamp in, gdv_int64 length, gdv_int32* out_len) { gdv_int64 year = extractYear_timestamp(in); diff --git a/cpp/src/gandiva/precompiled/types.h b/cpp/src/gandiva/precompiled/types.h index 01c8cd6e67a7d..4f943bfa449ed 100644 --- a/cpp/src/gandiva/precompiled/types.h +++ b/cpp/src/gandiva/precompiled/types.h @@ -422,6 +422,9 @@ gdv_timestamp castTIMESTAMP_date64(gdv_date64); gdv_timestamp castTIMESTAMP_int64(gdv_int64); gdv_date64 castDATE_timestamp(gdv_timestamp); gdv_time32 castTIME_timestamp(gdv_timestamp timestamp_in_millis); +gdv_timestamp convertTimestampUnit_ms(gdv_timestamp); +gdv_timestamp convertTimestampUnit_us(gdv_timestamp); +gdv_date32 castDATE_date64(gdv_date64 date); const char* castVARCHAR_timestamp_int64(int64_t, gdv_timestamp, gdv_int64, gdv_int32*); gdv_date64 last_day_from_timestamp(gdv_date64 millis);