Skip to content

Commit

Permalink
add the timestamp unit convert and date64 to date32 convert (apache#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
JkSelf authored and zhztheplayer committed Mar 15, 2022
1 parent a3f3a5e commit b811991
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cpp/src/gandiva/function_registry_datetime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ std::vector<NativeFunction> 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_;
}
Expand Down
12 changes: 12 additions & 0 deletions cpp/src/gandiva/precompiled/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,18 @@ gdv_time32 castTIME_timestamp(gdv_timestamp timestamp_in_millis) {
return static_cast<int32_t>(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<gdv_date32>(date_in_millis / (MILLIS_IN_DAY));
}

// Gets an arbitrary number and return the number of milliseconds since midnight
gdv_time32 castTIME_int32(int32_t int_val) {
if (int_val < 0) {
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/gandiva/precompiled/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ gdv_timestamp castTIMESTAMP_int64(gdv_int64);
gdv_date64 castDATE_timestamp(gdv_timestamp);
gdv_time32 castTIME_utf8(int64_t context, const char* input, int32_t length);
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);
gdv_time32 castTIME_int32(int32_t int_val);
const char* castVARCHAR_timestamp_int64(int64_t, gdv_timestamp, gdv_int64, gdv_int32*);
gdv_date64 last_day_from_timestamp(gdv_date64 millis);
Expand Down

0 comments on commit b811991

Please sign in to comment.