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



##########
File path: cpp/src/arrow/compute/kernels/codegen_internal.cc
##########
@@ -109,6 +109,58 @@ void ReplaceNullWithOtherType(ValueDescr* first, size_t 
count) {
   }
 }
 
+void ReplaceTemporalTypes(const std::shared_ptr<DataType>& type,
+                          std::vector<ValueDescr>* descrs) {
+  auto* end = descrs->data() + descrs->size();
+  TimeUnit::type finest_unit = TimeUnit::SECOND;
+
+  switch (type->id()) {
+    case Type::TIMESTAMP: {
+      const auto& ty = checked_cast<const TimestampType&>(*type);
+      finest_unit = ty.unit();
+      break;
+    }
+    case Type::DURATION: {
+      const auto& ty = checked_cast<const DurationType&>(*type);
+      finest_unit = ty.unit();
+      break;
+    }
+    case Type::DATE32: {
+      // Date32's unit is days, but the coarsest we have is seconds
+      break;
+    }
+    case Type::DATE64: {
+      finest_unit = std::max(finest_unit, TimeUnit::MILLI);
+      break;
+    }
+    default:
+      break;
+  }
+
+  for (auto* it = descrs->data(); it != end; it++) {
+    switch (it->type->id()) {
+      case Type::TIMESTAMP: {
+        it->type = type;
+        continue;
+      }
+      case Type::DURATION: {
+        it->type = duration(finest_unit);
+        continue;
+      }
+      case Type::DATE32: {
+        it->type = timestamp(finest_unit);

Review comment:
       This would matter in case of e.g. `subtract(date, timestamp)` but I'm 
only covering `subtract(date, duration)` here. Same as above.




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


Reply via email to