| 267 | } |
| 268 | |
| 269 | TypeHolder CommonTemporal(const TypeHolder* begin, size_t count) { |
| 270 | TimeUnit::type finest_unit = TimeUnit::SECOND; |
| 271 | const std::string* timezone = nullptr; |
| 272 | bool saw_date32 = false; |
| 273 | bool saw_date64 = false; |
| 274 | bool saw_duration = false; |
| 275 | bool saw_time_since_midnight = false; |
| 276 | const TypeHolder* end = begin + count; |
| 277 | for (auto it = begin; it != end; it++) { |
| 278 | auto id = it->type->id(); |
| 279 | // a common timestamp is only possible if all types are timestamp like |
| 280 | switch (id) { |
| 281 | case Type::DATE32: |
| 282 | // Date32's unit is days, but the coarsest we have is seconds |
| 283 | saw_date32 = true; |
| 284 | continue; |
| 285 | case Type::DATE64: |
| 286 | finest_unit = std::max(finest_unit, TimeUnit::MILLI); |
| 287 | saw_date64 = true; |
| 288 | continue; |
| 289 | case Type::TIMESTAMP: { |
| 290 | const auto& ty = checked_cast<const TimestampType&>(*it->type); |
| 291 | if (timezone && *timezone != ty.timezone()) return TypeHolder(nullptr); |
| 292 | timezone = &ty.timezone(); |
| 293 | finest_unit = std::max(finest_unit, ty.unit()); |
| 294 | continue; |
| 295 | } |
| 296 | case Type::TIME32: { |
| 297 | const auto& type = checked_cast<const Time32Type&>(*it->type); |
| 298 | finest_unit = std::max(finest_unit, type.unit()); |
| 299 | saw_time_since_midnight = true; |
| 300 | continue; |
| 301 | } |
| 302 | case Type::TIME64: { |
| 303 | const auto& type = checked_cast<const Time64Type&>(*it->type); |
| 304 | finest_unit = std::max(finest_unit, type.unit()); |
| 305 | saw_time_since_midnight = true; |
| 306 | continue; |
| 307 | } |
| 308 | case Type::DURATION: { |
| 309 | const auto& ty = checked_cast<const DurationType&>(*it->type); |
| 310 | finest_unit = std::max(finest_unit, ty.unit()); |
| 311 | saw_duration = true; |
| 312 | continue; |
| 313 | } |
| 314 | default: |
| 315 | return TypeHolder(nullptr); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | bool saw_timestamp_or_date = timezone || saw_date64 || saw_date32 || saw_duration; |
| 320 | |
| 321 | if (saw_time_since_midnight && saw_timestamp_or_date) { |
| 322 | // Cannot find common type |
| 323 | return TypeHolder(nullptr); |
| 324 | } |
| 325 | if (saw_timestamp_or_date) { |
| 326 | if (timezone) { |