Skip to content

Commit

Permalink
Use the null-skipping applicator for subtract_checked
Browse files Browse the repository at this point in the history
  • Loading branch information
westonpace committed Apr 18, 2023
1 parent d4f7332 commit ec9a5a4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1405,8 +1405,8 @@ void RegisterScalarArithmetic(FunctionRegistry* registry) {
// Add subtract_checked(timestamp, timestamp) -> duration
for (auto unit : TimeUnit::values()) {
InputType in_type(match::TimestampTypeUnit(unit));
auto exec =
ArithmeticExecFromOp<ScalarBinaryEqualTypes, SubtractChecked>(Type::TIMESTAMP);
auto exec = ArithmeticExecFromOp<ScalarBinaryNotNullEqualTypes, SubtractChecked>(
Type::TIMESTAMP);
DCHECK_OK(subtract_checked->AddKernel({in_type, in_type},
OutputType::Resolver(ResolveTemporalOutput),
std::move(exec)));
Expand All @@ -1423,38 +1423,40 @@ void RegisterScalarArithmetic(FunctionRegistry* registry) {
// Add subtract_checked(duration, duration) -> duration
for (auto unit : TimeUnit::values()) {
InputType in_type(match::DurationTypeUnit(unit));
auto exec =
ArithmeticExecFromOp<ScalarBinaryEqualTypes, SubtractChecked>(Type::DURATION);
auto exec = ArithmeticExecFromOp<ScalarBinaryNotNullEqualTypes, SubtractChecked>(
Type::DURATION);
DCHECK_OK(
subtract_checked->AddKernel({in_type, in_type}, duration(unit), std::move(exec)));
}

// Add subtract_checked(date32, date32) -> duration(TimeUnit::SECOND)
auto exec_date_32_checked =
ScalarBinaryEqualTypes<Int64Type, Int32Type, SubtractCheckedDate32>::Exec;
ScalarBinaryNotNullEqualTypes<Int64Type, Int32Type, SubtractCheckedDate32>::Exec;
DCHECK_OK(subtract_checked->AddKernel({in_type_date_32, in_type_date_32},
duration(TimeUnit::SECOND),
std::move(exec_date_32_checked)));

// Add subtract_checked(date64, date64) -> duration(TimeUnit::MILLI)
auto exec_date_64_checked =
ScalarBinaryEqualTypes<Int64Type, Int64Type, SubtractChecked>::Exec;
ScalarBinaryNotNullEqualTypes<Int64Type, Int64Type, SubtractChecked>::Exec;
DCHECK_OK(subtract_checked->AddKernel({in_type_date_64, in_type_date_64},
duration(TimeUnit::MILLI),
std::move(exec_date_64_checked)));

// Add subtract_checked(time32, time32) -> duration
for (auto unit : {TimeUnit::SECOND, TimeUnit::MILLI}) {
InputType in_type(match::Time32TypeUnit(unit));
auto exec = ScalarBinaryEqualTypes<Int64Type, Int32Type, SubtractChecked>::Exec;
auto exec =
ScalarBinaryNotNullEqualTypes<Int64Type, Int32Type, SubtractChecked>::Exec;
DCHECK_OK(
subtract_checked->AddKernel({in_type, in_type}, duration(unit), std::move(exec)));
}

// Add subtract_checked(time64, time64) -> duration
for (auto unit : {TimeUnit::MICRO, TimeUnit::NANO}) {
InputType in_type(match::Time64TypeUnit(unit));
auto exec = ScalarBinaryEqualTypes<Int64Type, Int64Type, SubtractChecked>::Exec;
auto exec =
ScalarBinaryNotNullEqualTypes<Int64Type, Int64Type, SubtractChecked>::Exec;
DCHECK_OK(
subtract_checked->AddKernel({in_type, in_type}, duration(unit), std::move(exec)));
}
Expand Down

0 comments on commit ec9a5a4

Please sign in to comment.