kou commented on code in PR #13428:
URL: https://github.com/apache/arrow/pull/13428#discussion_r919659653
##########
cpp/src/gandiva/gdv_function_stubs_test.cc:
##########
@@ -993,4 +993,61 @@ TEST(TestGdvFnStubs, TestTranslate) {
EXPECT_EQ(expected, std::string(result, out_len));
}
+TEST(TestGdvFnStubs, TestToUtcTimezone) {
+ gandiva::ExecutionContext context;
+ auto context_ptr = reinterpret_cast<int64_t>(&context);
+ gdv_int32 len_ist = static_cast<gdv_int32>(strlen("Asia/Kolkata"));
+ gdv_int32 len_pst = static_cast<gdv_int32>(strlen("America/Los_Angeles"));
+
+ //2012-02-28 15:30:00 Asia/Kolkata
Review Comment:
Is this correct?
##########
cpp/src/gandiva/gdv_function_stubs.cc:
##########
@@ -611,6 +611,67 @@ int32_t gdv_fn_cast_intervalyear_utf8_int32(int64_t
context_ptr, int64_t holder_
auto* holder = reinterpret_cast<gandiva::IntervalYearsHolder*>(holder_ptr);
return (*holder)(context, data, data_len, in1_validity, out_valid);
}
+
+GANDIVA_EXPORT
+gdv_timestamp to_utc_timezone_timestamp(int64_t context, gdv_timestamp
time_miliseconds,
+ const char* timezone, gdv_int32
length) {
+ using std::chrono::milliseconds;
+ using arrow_vendored::date::sys_time;
+ using arrow_vendored::date::time_zone;
+ using arrow_vendored::date::zoned_time;
+ using arrow_vendored::date::locate_zone;
+
+ sys_time <milliseconds> tp {milliseconds{time_miliseconds}};
+ try {
+ const time_zone* local_tz = locate_zone(std::string(timezone, length));
+ gdv_timestamp offset = local_tz->get_info(tp).offset.count()*1000;
+ return time_miliseconds - static_cast<gdv_timestamp>(offset);
+ } catch(...) {
+ int32_t msg_len = static_cast<int32_t>(strlen(timezone) + 50);
+ char* err_msg =
reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context,
+ msg_len));
+ if (err_msg == nullptr) {
+ gdv_fn_context_set_error_msg(context, "Could not allocate memory");
+ return 0;
+ }
+ std::snprintf(err_msg, msg_len, "'%s' is an invalid time zone name.",
timezone);
+ gdv_fn_context_set_error_msg(context, err_msg);
Review Comment:
@anthonylouisbsb Could you confirm whether this is a preferred error message
generation approach in Gandiva? (I'm not familiar with Gandiva's error message
generation.)
##########
cpp/src/gandiva/gdv_function_stubs_test.cc:
##########
@@ -993,4 +993,61 @@ TEST(TestGdvFnStubs, TestTranslate) {
EXPECT_EQ(expected, std::string(result, out_len));
}
+TEST(TestGdvFnStubs, TestToUtcTimezone) {
+ gandiva::ExecutionContext context;
+ auto context_ptr = reinterpret_cast<int64_t>(&context);
+ gdv_int32 len_ist = static_cast<gdv_int32>(strlen("Asia/Kolkata"));
+ gdv_int32 len_pst = static_cast<gdv_int32>(strlen("America/Los_Angeles"));
+
+ //2012-02-28 15:30:00 Asia/Kolkata
+ gdv_timestamp ts = 55800000;
+ gdv_timestamp ts2 = to_utc_timezone_timestamp(context_ptr, ts,
+ "Asia/Kolkata", len_ist);
+ EXPECT_EQ(36000000, ts2);
+
+ //1970-01-01 5:00:00 Asia/Kolkata
+ ts = 18000000;
Review Comment:
Is this correct?
It seems that `18000000` is "1970-01-01 5:00:00 UTC" and "1970-01-01 5:00:00
Asia/Kolkata" is `-1800000`.
##########
cpp/src/gandiva/gdv_function_stubs.cc:
##########
@@ -611,6 +611,51 @@ int32_t gdv_fn_cast_intervalyear_utf8_int32(int64_t
context_ptr, int64_t holder_
auto* holder = reinterpret_cast<gandiva::IntervalYearsHolder*>(holder_ptr);
return (*holder)(context, data, data_len, in1_validity, out_valid);
}
+
+GANDIVA_EXPORT
+gdv_timestamp to_utc_timezone_timestamp(int64_t context, gdv_timestamp
time_miliseconds,
+ const char* timezone, gdv_int32
length) {
+ using std::chrono::milliseconds;
+ using arrow_vendored::date::sys_time;
+ using arrow_vendored::date::time_zone;
+ using arrow_vendored::date::zoned_time;
+ using arrow_vendored::date::locate_zone;
+
+ sys_time <milliseconds> tp {milliseconds{time_miliseconds}};
+ try {
+ const time_zone* local_tz = locate_zone(std::string(timezone, length));
+ gdv_timestamp offset = local_tz->get_info(tp).offset.count()*1000;
+ return time_miliseconds - static_cast<gdv_timestamp>(offset);
+ } catch(...) {
+ gdv_fn_context_set_error_msg(context, "Invalid time zone");
+ return 0;
+ }
+}
+
+GANDIVA_EXPORT
+gdv_timestamp from_utc_timezone_timestamp(gdv_int64 context,
+ gdv_timestamp time_miliseconds,
+ const char* timezone, gdv_int32
length) {
+ using std::chrono::milliseconds;
+ using arrow_vendored::date::sys_time;
+ using arrow_vendored::date::time_zone;
+ using arrow_vendored::date::zoned_time;
+ using arrow_vendored::date::make_zoned;
+
+ sys_time <milliseconds> tp {milliseconds{time_miliseconds}};
+ const zoned_time<milliseconds, const time_zone*> utc_tz =
Review Comment:
Umm, I couldn't reproduce it with
```diff
diff --git a/cpp/src/gandiva/gdv_function_stubs.cc
b/cpp/src/gandiva/gdv_function_stubs.cc
index ccf3e7ca3b..e6cbeb8aa7 100644
--- a/cpp/src/gandiva/gdv_function_stubs.cc
+++ b/cpp/src/gandiva/gdv_function_stubs.cc
@@ -651,11 +651,9 @@ gdv_timestamp from_utc_timezone_timestamp(gdv_int64
context,
using arrow_vendored::date::make_zoned;
sys_time <milliseconds> tp {milliseconds{time_miliseconds}};
- const zoned_time<milliseconds, const time_zone*> utc_tz =
- make_zoned(std::string("Etc/UTC"), tp);
+ const auto utc_tz = make_zoned(std::string("Etc/UTC"), tp);
try {
- const zoned_time<milliseconds, const time_zone*> local_tz =
- make_zoned(std::string(timezone, length), utc_tz);
+ const auto local_tz = make_zoned(std::string(timezone, length), utc_tz);
gdv_timestamp offset =
local_tz.get_time_zone()->get_info(tp).offset.count()*1000;
return time_miliseconds + static_cast<gdv_timestamp>(offset);
} catch(...) {
```
Could you show an error message on your environment?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]