lidavidm commented on a change in pull request #12136:
URL: https://github.com/apache/arrow/pull/12136#discussion_r788767993
##########
File path: docs/source/cpp/compute.rst
##########
@@ -420,39 +420,39 @@ precisions/scales will be promoted appropriately. Mixed
decimal and
floating-point arguments will cast all arguments to floating-point, while mixed
decimal and integer arguments will cast all arguments to decimals.
Review comment:
Should we add a note about temporal casting here?
##########
File path: cpp/src/arrow/compute/kernels/codegen_internal_test.cc
##########
@@ -156,6 +156,24 @@ TEST(TestDispatchBest, CommonTemporal) {
args = {timestamp(TimeUnit::SECOND, "America/Phoenix"),
timestamp(TimeUnit::SECOND, "UTC")};
ASSERT_EQ(nullptr, CommonTemporal(args.data(), args.size()));
+ args = {date32(), duration(TimeUnit::MILLI)};
+ AssertTypeEqual(duration(TimeUnit::MILLI), CommonTemporal(args.data(),
args.size()));
+ args = {date64(), duration(TimeUnit::MICRO)};
+ AssertTypeEqual(duration(TimeUnit::MICRO), CommonTemporal(args.data(),
args.size()));
Review comment:
Check that timestamp + duration = timestamp?
##########
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:
Shouldn't this preserve the timezone of the input timestamp, if there is
one?
--
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]