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 Feb 28, 2022
1 parent ee3102a commit 1d348c1
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 @@ -131,6 +131,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 @@ -818,6 +818,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));
}

const char* castVARCHAR_timestamp_int64(gdv_int64 context, gdv_timestamp in,
gdv_int64 length, gdv_int32* out_len) {
gdv_int64 year = extractYear_timestamp(in);
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 @@ -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);

Expand Down

0 comments on commit 1d348c1

Please sign in to comment.