You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/09/24 19:28:39 UTC
[GitHub] [arrow] lidavidm commented on a change in pull request #11229: ARROW-14111: [C++] Add extraction function support for time32/time64
lidavidm commented on a change in pull request #11229:
URL: https://github.com/apache/arrow/pull/11229#discussion_r715854990
##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -528,13 +576,18 @@ struct Strftime {
static Result<Strftime> Make(KernelContext* ctx, const DataType& type) {
const StrftimeOptions& options = StrftimeState::Get(ctx);
- auto timezone = GetInputTimezone(type);
// This check is due to surprising %c behavior.
// See https://github.com/HowardHinnant/date/issues/704
if ((options.format.find("%c") != std::string::npos) && (options.locale != "C")) {
return Status::Invalid("%c flag is not supported in non-C locales.");
}
- if (timezone.empty()) {
+ std::string timezone;
+ bool is_timestamp = type.id() == Type::TIMESTAMP;
+ if (is_timestamp) {
Review comment:
You could make this a compile-time check:
https://github.com/apache/arrow/blob/78ac1322de9d31fdf89b8db7d1bd786928fe3a32/cpp/src/arrow/type_traits.h#L703
Then presumably any timestamp-related code would get optimized out for the non-timestamp specializations.
##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal_test.cc
##########
@@ -566,6 +594,25 @@ TEST_F(ScalarTemporalTest, Strftime) {
utf8(), string_microseconds, &options);
CheckScalarUnary("strftime", timestamp(TimeUnit::NANO, "US/Hawaii"), nanoseconds,
utf8(), string_nanoseconds, &options);
+
+ auto options_hms = StrftimeOptions("%H:%M:%S");
+ const char* times_s = R"([59, null])";
+ const char* times_ms = R"([59123, null])";
+ const char* times_us = R"([59123456, null])";
+ const char* times_ns = R"([59123456789, null])";
+ const char* strftime_ns = R"(["00:00:59.123456789", null])";
+ const char* strftime_us = R"(["00:00:59.123456", null])";
+ const char* strftime_ms = R"(["00:00:59.123", null])";
+ const char* strftime_s = R"(["00:00:59", null])";
+
+ CheckScalarUnary("strftime", time64(TimeUnit::NANO), times_ns, utf8(), strftime_ns,
+ &options_hms);
+ CheckScalarUnary("strftime", time64(TimeUnit::MICRO), times_us, utf8(), strftime_us,
+ &options_hms);
+ CheckScalarUnary("strftime", time32(TimeUnit::MILLI), times_ms, utf8(), strftime_ms,
+ &options_hms);
+ CheckScalarUnary("strftime", time32(TimeUnit::SECOND), times_s, utf8(), strftime_s,
Review comment:
Should we 1) check what happens for fields like year, and 2) check that `%z` isn't allowed for times below in StrftimeNoTimezone?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org