bkietz commented on a change in pull request #11080: URL: https://github.com/apache/arrow/pull/11080#discussion_r714193210
########## File path: cpp/src/arrow/compute/kernels/codegen_internal.cc ########## @@ -155,24 +161,44 @@ std::shared_ptr<DataType> CommonNumeric(const ValueDescr* begin, size_t count) { std::shared_ptr<DataType> CommonTimestamp(const std::vector<ValueDescr>& descrs) { TimeUnit::type finest_unit = TimeUnit::SECOND; + const std::string* timezone = nullptr; + bool saw_date32 = false; + bool saw_date64 = false; for (const auto& descr : descrs) { auto id = descr.type->id(); // a common timestamp is only possible if all types are timestamp like switch (id) { case Type::DATE32: + // Date32's unit is days, but the coarsest we have is seconds + saw_date32 = true; + continue; case Type::DATE64: + finest_unit = std::max(finest_unit, TimeUnit::MILLI); + saw_date64 = true; continue; - case Type::TIMESTAMP: - finest_unit = - std::max(finest_unit, checked_cast<const TimestampType&>(*descr.type).unit()); + case Type::TIMESTAMP: { + const auto& ty = checked_cast<const TimestampType&>(*descr.type); + // Don't cast to common timezone by default (may not make + // sense for all kernels) + if (timezone && *timezone != ty.timezone()) return nullptr; + timezone = &ty.timezone(); + finest_unit = std::max(finest_unit, ty.unit()); continue; + } default: return nullptr; } } - return timestamp(finest_unit); + if (timezone) { + // At least one timestamp seen + return timestamp(finest_unit, *timezone); + } else if (saw_date32 && saw_date64) { + // Saw mixed date types + return date64(); + } + return nullptr; Review comment: nullptr is returned to indicate that no common temporal type was found; returning date32 here would mean `CommonTemporal(float64(), utf8()) === date32()` -- 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-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org