Merge temporal types based on options. Returns nullptr for non-temporal types.
| 425 | |
| 426 | // Merge temporal types based on options. Returns nullptr for non-temporal types. |
| 427 | Result<std::shared_ptr<DataType>> MaybeMergeTemporalTypes( |
| 428 | const std::shared_ptr<DataType>& promoted_type, |
| 429 | const std::shared_ptr<DataType>& other_type, const Field::MergeOptions& options) { |
| 430 | if (options.promote_temporal_unit) { |
| 431 | if (promoted_type->id() == Type::DATE32 && other_type->id() == Type::DATE64) { |
| 432 | return date64(); |
| 433 | } |
| 434 | if (promoted_type->id() == Type::DATE64 && other_type->id() == Type::DATE32) { |
| 435 | return date64(); |
| 436 | } |
| 437 | |
| 438 | if (promoted_type->id() == Type::DURATION && other_type->id() == Type::DURATION) { |
| 439 | const auto& left = checked_cast<const DurationType&>(*promoted_type); |
| 440 | const auto& right = checked_cast<const DurationType&>(*other_type); |
| 441 | return duration(std::max(left.unit(), right.unit())); |
| 442 | } |
| 443 | |
| 444 | if (is_time(promoted_type->id()) && is_time(other_type->id())) { |
| 445 | const auto& left = checked_cast<const TimeType&>(*promoted_type); |
| 446 | const auto& right = checked_cast<const TimeType&>(*other_type); |
| 447 | const auto unit = std::max(left.unit(), right.unit()); |
| 448 | if (unit == TimeUnit::MICRO || unit == TimeUnit::NANO) { |
| 449 | return time64(unit); |
| 450 | } |
| 451 | return time32(unit); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | if (promoted_type->id() == Type::TIMESTAMP && other_type->id() == Type::TIMESTAMP) { |
| 456 | const auto& left = checked_cast<const TimestampType&>(*promoted_type); |
| 457 | const auto& right = checked_cast<const TimestampType&>(*other_type); |
| 458 | if (left.timezone().empty() ^ right.timezone().empty()) { |
| 459 | return Status::TypeError( |
| 460 | "Cannot merge timestamp with timezone and timestamp without timezone"); |
| 461 | } |
| 462 | if (left.timezone() != right.timezone()) { |
| 463 | return Status::TypeError("Cannot merge timestamps with differing timezones"); |
| 464 | } |
| 465 | if (options.promote_temporal_unit) { |
| 466 | return timestamp(std::max(left.unit(), right.unit()), left.timezone()); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | return nullptr; |
| 471 | } |
| 472 | |
| 473 | // Merge numeric types based on options. Returns nullptr for non-numeric types. |
| 474 | Result<std::shared_ptr<DataType>> MaybeMergeNumericTypes( |