lidavidm commented on a change in pull request #12124:
URL: https://github.com/apache/arrow/pull/12124#discussion_r794550124



##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
##########
@@ -2437,14 +2462,35 @@ void RegisterScalarArithmetic(FunctionRegistry* 
registry) {
                                   std::move(exec)));
   }
 
+  // Add subtract(date32, date32) -> duration(TimeUnit::SECOND)
+  InputType in_type_date_32(date32());
+  auto exec_date_32 = ScalarBinaryEqualTypes<Int64Type, Date32Type, 
SubtractDate32>::Exec;
+  DCHECK_OK(subtract->AddKernel({in_type_date_32, in_type_date_32},
+                                duration(TimeUnit::SECOND), 
std::move(exec_date_32)));
+
+  // Add subtract(date64, date64) -> duration(TimeUnit::MILLI)
+  InputType in_type_date_64(date64());
+  auto exec_date_64 = ScalarBinaryEqualTypes<Int64Type, Date64Type, 
Subtract>::Exec;
+  DCHECK_OK(subtract->AddKernel({in_type_date_64, in_type_date_64},
+                                duration(TimeUnit::MILLI), 
std::move(exec_date_64)));
+
   DCHECK_OK(registry->AddFunction(std::move(subtract)));
 
   // ----------------------------------------------------------------------
   auto subtract_checked = MakeArithmeticFunctionNotNull<SubtractChecked>(
       "subtract_checked", &sub_checked_doc);
   AddDecimalBinaryKernels<SubtractChecked>("subtract_checked", 
subtract_checked.get());
 
-  // Add subtract(timestamp, duration) -> timestamp
+  // Add subtract_checked(timestamp, timestamp) -> duration
+  for (auto unit : TimeUnit::values()) {
+    InputType in_type(match::TimestampTypeUnit(unit));

Review comment:
       Don't we need to check that we aren't mixing naive/zoned timestamps?

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal_test.cc
##########
@@ -1030,6 +1030,36 @@ TEST_F(ScalarTemporalTest, 
TestTemporalSubtractDateAndDurationChecked) {
   CheckScalarBinary(op, dates64, durations_us, timestamps_us);
 }
 
+TEST_F(ScalarTemporalTest, TestTemporalSubtractDate) {
+  std::string op = "subtract";
+  auto arr_date32s = ArrayFromJSON(date32(), date32s);
+  auto arr_date32s2 = ArrayFromJSON(date32(), date32s2);
+  auto arr_date64s = ArrayFromJSON(date64(), date64s);
+  auto arr_date64s2 = ArrayFromJSON(date64(), date64s2);
+
+  CheckScalarBinary(op, arr_date32s2, arr_date32s,
+                    ArrayFromJSON(duration(TimeUnit::SECOND), 
seconds_between_date));
+  CheckScalarBinary(op, arr_date64s2, arr_date64s,
+                    ArrayFromJSON(duration(TimeUnit::MILLI), 
milliseconds_between_date));
+  CheckScalarBinary(op, arr_date64s2, arr_date32s,
+                    ArrayFromJSON(duration(TimeUnit::MILLI), 
milliseconds_between_date));
+}
+
+TEST_F(ScalarTemporalTest, TestTemporalSubtractDateChecked) {
+  std::string op = "subtract_checked";
+  auto arr_date32s = ArrayFromJSON(date32(), date32s);
+  auto arr_date32s2 = ArrayFromJSON(date32(), date32s2);
+  auto arr_date64s = ArrayFromJSON(date64(), date64s);
+  auto arr_date64s2 = ArrayFromJSON(date64(), date64s2);
+
+  CheckScalarBinary(op, arr_date32s2, arr_date32s,
+                    ArrayFromJSON(duration(TimeUnit::SECOND), 
seconds_between_date));
+  CheckScalarBinary(op, arr_date64s2, arr_date64s,
+                    ArrayFromJSON(duration(TimeUnit::MILLI), 
milliseconds_between_date));
+  CheckScalarBinary(op, arr_date64s2, arr_date32s,
+                    ArrayFromJSON(duration(TimeUnit::MILLI), 
milliseconds_between_date));
+}
+

Review comment:
       Is there a test for subtracting timestamps?
   
   We should also check that casting works properly.




-- 
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]


Reply via email to