jorisvandenbossche commented on a change in pull request #10933:
URL: https://github.com/apache/arrow/pull/10933#discussion_r691282261
##########
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:
After ARROW-12980, this now works with timezones? (or can work)
--
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]