rok commented on a change in pull request #10647:
URL: https://github.com/apache/arrow/pull/10647#discussion_r678366291



##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -321,6 +323,70 @@ struct Nanosecond {
   }
 };
 
+// ----------------------------------------------------------------------
+// Convert timestamps to a string representation with an arbitrary format
+
+template <typename Duration>
+inline std::string get_timestamp(int64_t arg, const std::locale* locale,
+                                 const time_zone* tz, const std::string* 
format) {
+  auto zt =
+      arrow_vendored::date::zoned_time<Duration>{tz, 
sys_time<Duration>(Duration{arg})};
+  return arrow_vendored::date::format(*locale, *format, zt);
+}
+
+template <typename Duration>
+struct Strftime {
+  static Status Call(KernelContext* ctx, const Scalar& in, Scalar* out) {
+    const auto& timezone = GetInputTimezone(in);
+    if (timezone.empty()) {
+      return Status::Invalid(
+          "Timestamps without a time zone cannot be reliably printed.");
+    }
+    const arrow_vendored::date::time_zone* tz =
+        arrow_vendored::date::locate_zone(timezone);
+    const StrftimeOptions options = StrftimeState::Get(ctx);
+
+    if (in.is_valid) {
+      const auto& in_val = internal::UnboxScalar<const 
TimestampType>::Unbox(in);
+      *checked_cast<StringScalar*>(out) = StringScalar(
+          get_timestamp<Duration>(in_val, &options.loc, tz, &options.format));
+    } else {
+      out->is_valid = false;
+    }
+    return Status::OK();
+  }
+
+  static Status Call(KernelContext* ctx, const ArrayData& in, ArrayData* out) {
+    const auto& timezone = GetInputTimezone(in);
+    if (timezone.empty()) {
+      return Status::Invalid("Timestamp without a time zone cannot be reliably 
printed.");
+    }
+    const arrow_vendored::date::time_zone* tz =
+        arrow_vendored::date::locate_zone(timezone);
+    const StrftimeOptions options = StrftimeState::Get(ctx);
+
+    std::unique_ptr<ArrayBuilder> array_builder;
+    RETURN_NOT_OK(MakeBuilder(ctx->memory_pool(), utf8(), &array_builder));
+    StringBuilder* string_builder = 
checked_cast<StringBuilder*>(array_builder.get());
+    auto expected_string_size = static_cast<int64_t>(
+        ceil(get_timestamp<Duration>(0, &options.loc, tz, 
&options.format).size() * 1.1));
+    RETURN_NOT_OK(string_builder->Reserve(in.length * expected_string_size));

Review comment:
       Got it. Added.

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -656,6 +764,13 @@ void RegisterScalarTemporal(FunctionRegistry* registry) {
 
   auto subsecond = MakeTemporal<Subsecond, DoubleType>("subsecond", 
&subsecond_doc);
   DCHECK_OK(registry->AddFunction(std::move(subsecond)));
+
+#ifndef _WIN32

Review comment:
       Done.




-- 
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]


Reply via email to