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



##########
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:
       You mean like `TimezoneMixin`? That wouldn't remove the check.
   Also the linter doesn't like it (["explicit" should be used on 
single-parameter constructors and conversion 
operators](https://rules.sonarsource.com/cpp/RSPEC-1709)).
   
   I'm looking to template the extractor or rather `Call` based on if 
`timezone` is present or not.  




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


Reply via email to