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/08/18 14:54:34 UTC

[GitHub] [arrow] lidavidm commented on a change in pull request #10933: ARROW-13549: [C++] Add date/time extraction functions

lidavidm commented on a change in pull request #10933:
URL: https://github.com/apache/arrow/pull/10933#discussion_r691318263



##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -616,6 +671,59 @@ std::shared_ptr<ScalarFunction> MakeSimpleUnaryTemporal(
   return func;
 }
 
+template <template <typename...> class Op, template <template <typename...> class OpExec,
+                                                     typename Duration, typename OutType>
+                                           class ExecTemplate>
+std::shared_ptr<ScalarFunction> MakeTimeTemporal(
+    std::string name, const FunctionDoc* doc,
+    const FunctionOptions* default_options = NULLPTR, KernelInit init = NULLPTR) {
+  auto func =
+      std::make_shared<ScalarFunction>(name, Arity::Unary(), doc, default_options);
+
+  for (auto unit : internal::AllTimeUnits()) {
+    InputType in_type{match::TimestampTypeUnit(unit)};
+    switch (unit) {
+      case TimeUnit::SECOND: {
+        auto exec = ExecTemplate<Op, std::chrono::seconds, Time32Type>::Exec;
+        DCHECK_OK(func->AddKernel({in_type}, time32(unit), std::move(exec), init));
+        break;
+      }
+      case TimeUnit::MILLI: {
+        auto exec = ExecTemplate<Op, std::chrono::milliseconds, Time32Type>::Exec;
+        DCHECK_OK(func->AddKernel({in_type}, time32(unit), std::move(exec), init));
+        break;
+      }
+      case TimeUnit::MICRO: {
+        auto exec = ExecTemplate<Op, std::chrono::microseconds, Time64Type>::Exec;
+        DCHECK_OK(func->AddKernel({in_type}, time64(unit), std::move(exec), init));
+        break;
+      }
+      case TimeUnit::NANO: {
+        auto exec = ExecTemplate<Op, std::chrono::nanoseconds, Time64Type>::Exec;
+        DCHECK_OK(func->AddKernel({in_type}, time64(unit), std::move(exec), init));
+        break;
+      }
+    }
+  }
+  return func;
+}
+
+const FunctionDoc date32_doc{
+    "Extract date32 from timestamp",
+    "Returns an error if timestamp has a defined timezone. Null values return null.",

Review comment:
       Doh, I forgot to update the docstring. Yes, they all work with timezones and there are tests. I've updated all the docstrings.




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