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 Apr 8, 2021
1 parent 554ad19 commit 03e0d7a
Show file tree
Hide file tree
Showing 3 changed files with 25 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 @@ -86,6 +86,15 @@ 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"),
};

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 @@ -749,6 +749,18 @@ gdv_date64 castDATE_timestamp(gdv_timestamp timestamp_in_millis) {
return tp.ClearTimeOfDay().MillisSinceEpoch();
}

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
4 changes: 4 additions & 0 deletions cpp/src/gandiva/precompiled/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ gdv_timestamp castTIMESTAMP_utf8(int64_t execution_context, const char* input,
gdv_timestamp castTIMESTAMP_date64(gdv_date64);
gdv_timestamp castTIMESTAMP_int64(gdv_int64);
gdv_date64 castDATE_timestamp(gdv_timestamp);
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*);

const char* castVARCHAR_date32_int64(int64_t, gdv_date32, gdv_int64, gdv_int32*);
Expand Down

0 comments on commit 03e0d7a

Please sign in to comment.