rok commented on a change in pull request #10960: URL: https://github.com/apache/arrow/pull/10960#discussion_r717999853
########## File path: docs/source/cpp/compute.rst ########## @@ -1385,6 +1385,48 @@ For timestamps inputs with non-empty timezone, localized timestamp components wi .. _ISO 8601 week date definition: https://en.wikipedia.org/wiki/ISO_week_date#First_week +Temporal difference +~~~~~~~~~~~~~~~~~~~ + +These functions compute the difference between two timestamps in the +specified unit. The difference is determined by the number of +boundaries crossed, not the span of time. For example, the difference +in days between 23:59:59 on one day and 00:00:01 on the next day is +one day (since midnight was crossed), not zero days (even though less +than 24 hours elapsed). Additionally, if the timestamp has a defined +timezone, the difference is calculated in the local timezone. For +instance, the difference in years between "2019-12-31 18:00:00-0500" +and "2019-12-31 23:00:00-0500" is zero years, because the local year +is the same, even though the UTC years would be different. + ++---------------------------------+------------+-------------------+-----------------------+----------------------------+ +| Function name | Arity | Input types | Output type | Options class | ++=================================+============+===================+=======================+============================+ +| day_time_interval_between | Binary | Temporal | DayTime interval | | ++---------------------------------+------------+-------------------+-----------------------+----------------------------+ +| days_between | Binary | Timestamp, Date | Int64 | | ++---------------------------------+------------+-------------------+-----------------------+----------------------------+ +| hours_between | Binary | Temporal | Int64 | | ++---------------------------------+------------+-------------------+-----------------------+----------------------------+ +| microseconds_between | Binary | Temporal | Int64 | | ++---------------------------------+------------+-------------------+-----------------------+----------------------------+ +| milliseconds_between | Binary | Temporal | Int64 | | ++---------------------------------+------------+-------------------+-----------------------+----------------------------+ +| minutes_between | Binary | Temporal | Int64 | | ++---------------------------------+------------+-------------------+-----------------------+----------------------------+ +| month_day_nano_interval_between | Binary | Temporal | MonthDayNano interval | | ++---------------------------------+------------+-------------------+-----------------------+----------------------------+ +| month_interval_between | Binary | Timestamp, Date | Month interval | | ++---------------------------------+------------+-------------------+-----------------------+----------------------------+ +| nanoseconds_between | Binary | Temporal | Int64 | | ++---------------------------------+------------+-------------------+-----------------------+----------------------------+ Review comment: ```suggestion +---------------------------------+------------+-------------------+-----------------------+----------------------------+ | quarters_between | Binary | Timestamp, Date | Int64 | | +---------------------------------+------------+-------------------+-----------------------+----------------------------+ ``` ########## File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc ########## @@ -1209,6 +1660,75 @@ void RegisterScalarTemporal(FunctionRegistry* registry) { OutputType::Resolver(ResolveAssumeTimezoneOutput), &assume_timezone_doc, nullptr, AssumeTimezoneState::Init); DCHECK_OK(registry->AddFunction(std::move(assume_timezone))); + + auto years_between = MakeTemporalBinary<YearsBetween, TemporalBinary, Int64Type>( + "years_between", {WithDates, WithTimestamps}, int64(), &years_between_doc); + DCHECK_OK(registry->AddFunction(std::move(years_between))); + + auto quarters_between = MakeTemporalBinary<QuartersBetween, TemporalBinary, Int64Type>( + "quarters_between", {WithDates, WithTimestamps}, int64(), &quarters_between_doc); + DCHECK_OK(registry->AddFunction(std::move(quarters_between))); + + auto month_interval_between = + MakeTemporalBinary<MonthsBetween, TemporalBinary, MonthIntervalType>( + "month_interval_between", {WithDates, WithTimestamps}, month_interval(), + &months_between_doc); + DCHECK_OK(registry->AddFunction(std::move(month_interval_between))); + + auto month_day_nano_between = + MakeTemporalBinary<MonthDayNanoBetween, TemporalBinary, MonthDayNanoIntervalType>( + "month_day_nano_interval_between", {WithDates, WithTimes, WithTimestamps}, + month_day_nano_interval(), &month_day_nano_interval_between_doc); + DCHECK_OK(registry->AddFunction(std::move(month_day_nano_between))); + + auto weeks_between = + MakeTemporalBinary<WeeksBetween, TemporalDayOfWeekBinary, Int64Type>( + "weeks_between", {WithDates, WithTimestamps}, int64(), &weeks_between_doc, + &default_day_of_week_options, DayOfWeekState::Init); + DCHECK_OK(registry->AddFunction(std::move(weeks_between))); + + auto day_time_between = Review comment: Nit: `day_time_interval_between` would be more consistent. Same for `month_day_nano_interval_between`. I don't feel strongly about it, just noticing :). -- 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]
