rok commented on a change in pull request #10457:
URL: https://github.com/apache/arrow/pull/10457#discussion_r657500729
##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -60,86 +63,132 @@ const std::string& GetInputTimezone(const ArrayData&
array) {
return checked_cast<const TimestampType&>(*array.type).timezone();
}
-template <typename T>
-Status TemporalComponentExtractCheckTimezone(const T& input) {
- const auto& timezone = GetInputTimezone(input);
- if (!timezone.empty()) {
- return Status::NotImplemented(
- "Cannot extract components from timestamp with specific timezone: ",
timezone);
+template <typename Op, typename OutType>
+struct TemporalComponentExtract {
+ using OutValue = typename internal::GetOutputType<OutType>::T;
+
+ static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+ return ScalarUnaryNotNull<OutType, TimestampType, Op>::Exec(ctx, batch,
out);
}
- return Status::OK();
}
template <typename Op, typename OutType>
-struct TemporalComponentExtract {
+struct TemporalComponentExtractZoned {
using OutValue = typename internal::GetOutputType<OutType>::T;
static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
- RETURN_NOT_OK(TemporalComponentExtractCheckTimezone(batch.values[0]));
- return ScalarUnaryNotNull<OutType, TimestampType, Op>::Exec(ctx, batch,
out);
+ const auto& timezone = GetInputTimezone(batch.values[0]);
+ if (timezone.empty()) {
+ return ScalarUnaryNotNull<OutType, TimestampType, Op>::Exec(ctx, batch,
out);
+ } else {
+ applicator::ScalarUnaryNotNullStateful<OutType, TimestampType, Op>
kernel{
+ locate_zone(timezone)};
+ return kernel.Exec(ctx, batch, out);
+ }
}
+}
+
+struct TimezoneMixin {
+ TimezoneMixin(const time_zone* tz = nullptr) : tz_(tz) {}
+ const time_zone* tz_;
};
// ----------------------------------------------------------------------
// Extract year from timestamp
template <typename Duration>
-struct Year {
+struct Year : public TimezoneMixin {
+ using TimezoneMixin::TimezoneMixin;
+
template <typename T, typename Arg0>
- static T Call(KernelContext*, Arg0 arg, Status*) {
+ T Call(KernelContext*, Arg0 arg, Status*) const {
+ if (tz_ == nullptr) {
Review comment:
@pitrou what would be a practical way to remove this check by
templateing?
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]