dmitry-chirkov-dremio commented on code in PR #54684:
URL: https://github.com/apache/arrow/pull/54684#discussion_r4434791028
##########
cpp/src/arrow/compute/kernels/scalar_cast_string.cc:
##########
@@ -200,13 +200,51 @@ struct TemporalToStringCastFunctor<O, TimestampType> {
DCHECK(!timezone.empty());
ARROW_ASSIGN_OR_RAISE(auto tz, LocateZone(timezone));
ARROW_ASSIGN_OR_RAISE(auto locale, GetLocale("C"));
- TimestampFormatter<Duration> formatter{
- timezone == "UTC" ? kUtcFormatString : kFormatString, tz, locale};
+ if (timezone == "UTC") {
+ TimestampFormatter<Duration> formatter{kUtcFormatString, tz, locale};
+ return VisitArraySpanInline<TimestampType>(
+ input,
+ [&](value_type v) {
+ ARROW_ASSIGN_OR_RAISE(auto formatted, formatter(v));
+ return builder->Append(std::move(formatted));
+ },
+ [&]() {
+ builder->UnsafeAppendNull();
+ return Status::OK();
+ });
+ }
+
+ ARROW_ASSIGN_OR_RAISE(auto utc_tz, LocateZone("UTC"));
+ TimestampFormatter<Duration> utc_formatter{kUtcFormatString, utc_tz,
locale};
+ std::ostringstream bufstream;
+ bufstream.imbue(locale);
+ bufstream.exceptions(std::ios::failbit | std::ios::badbit);
+
return VisitArraySpanInline<TimestampType>(
input,
[&](value_type v) {
- ARROW_ASSIGN_OR_RAISE(auto formatted, formatter(v));
- return builder->Append(std::move(formatted));
+ bufstream.str("");
+ const auto timepoint = sys_time<Duration>(Duration{v});
+ bool subminute_offset = false;
+ auto format_zoned_time = [&](auto&& zt) {
+ if (ARROW_PREDICT_FALSE(zt.get_info().offset.count() % 60 != 0)) {
Review Comment:
zt.get_info() formats an abbreviation for fixed-offset zones, and
to_stream() calls it again. Can we skip the extra call for OffsetZone, which
stores whole minutes?
In local tests, a 1M-row, six-column in-memory CSV export took 0.812 s on
parent fb767a7c and 0.954 s on this head (092de95d). Skipping only this call
for fixed-offset zones brought it back to 0.820 s, with identical CSV output.
--
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]