MCPcopy Create free account
hub / github.com/apache/arrow / MaybeMergeTemporalTypes

Function MaybeMergeTemporalTypes

cpp/src/arrow/type.cc:427–471  ·  view source on GitHub ↗

Merge temporal types based on options. Returns nullptr for non-temporal types.

Source from the content-addressed store, hash-verified

425
426// Merge temporal types based on options. Returns nullptr for non-temporal types.
427Result<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.
474Result<std::shared_ptr<DataType>> MaybeMergeNumericTypes(

Callers

nothing calls this directly

Calls 10

timezoneMethod · 0.80
durationFunction · 0.70
is_timeFunction · 0.70
time64Function · 0.70
time32Function · 0.70
TypeErrorFunction · 0.70
timestampFunction · 0.70
idMethod · 0.45
unitMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected