Skip to content

Commit

Permalink
ARROW-5975: [C++][Gandiva] support castTIMESTAMP(date)
Browse files Browse the repository at this point in the history
Closes apache#4902 from pprudhvi/casttimestamp-date and squashes the following commits:

49de552 <Prudhvi Porandla> add castTIMESTAMP_date64 method and its unittest

Authored-by: Prudhvi Porandla <[email protected]>
Signed-off-by: Pindikura Ravindra <[email protected]>
  • Loading branch information
pprudhvi authored and Pindikura Ravindra committed Jul 31, 2019
1 parent ca2758e commit 8bdade4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cpp/src/gandiva/function_registry_datetime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ std::vector<NativeFunction> GetDateTimeFunctionRegistry() {
kResultNullInternal, "gdv_fn_to_date_utf8_utf8_int32",
NativeFunction::kNeedsContext |
NativeFunction::kNeedsFunctionHolder |
NativeFunction::kCanReturnErrors)};
NativeFunction::kCanReturnErrors),
NativeFunction("castTIMESTAMP", {}, DataTypeVector{date64()}, timestamp(),
kResultNullIfNull, "castTIMESTAMP_date64")};

return date_time_fn_registry_;
}
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/gandiva/precompiled/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -686,4 +686,7 @@ timestamp castTIMESTAMP_utf8(int64_t context, const char* input, int32 length) {
}
return std::chrono::time_point_cast<milliseconds>(date_time).time_since_epoch().count();
}

timestamp castTIMESTAMP_date64(date64 date_in_millis) { return date_in_millis; }

} // extern "C"
3 changes: 3 additions & 0 deletions cpp/src/gandiva/precompiled/time_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ TEST(TestTime, TestCastTimestamp) {
-1187308799080);
EXPECT_EQ(castTIMESTAMP_utf8(context_ptr, "1857-02-11 20:31:40.920 -05:30", 30),
-3562264699080);
EXPECT_EQ(castTIMESTAMP_date64(
castDATE_utf8(context_ptr, "2000-09-23 9:45:30.920 +08:00", 29)),
castTIMESTAMP_utf8(context_ptr, "2000-09-23 0:00:00.000 +00:00", 29));
}

#ifndef _WIN32
Expand Down
1 change: 1 addition & 0 deletions cpp/src/gandiva/precompiled/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ int32 utf8_length(int64 context, const char* data, int32 data_len);
date64 castDATE_utf8(int64_t execution_context, const char* input, int32 length);

timestamp castTIMESTAMP_utf8(int64_t execution_context, const char* input, int32 length);
timestamp castTIMESTAMP_date64(date64);

} // extern "C"

Expand Down

0 comments on commit 8bdade4

Please sign in to comment.