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 May 13, 2021
1 parent 2f5fdb4 commit 0cb1d18
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cpp/src/gandiva/function_registry_datetime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ std::vector<NativeFunction> GetDateTimeFunctionRegistry() {
NativeFunction("extractDay", {}, DataTypeVector{day_time_interval()}, int64(),
kResultNullIfNull, "extractDay_daytimeinterval"),

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 @@ -805,6 +805,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 @@ -276,6 +276,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 0cb1d18

Please sign in to comment.