edponce commented on a change in pull request #11541:
URL: https://github.com/apache/arrow/pull/11541#discussion_r736003276



##########
File path: cpp/src/arrow/compute/kernels/scalar_compare_test.cc
##########
@@ -454,6 +454,57 @@ TEST(TestCompareTimestamps, Basics) {
   CheckArrayCase(seconds_utc, CompareOperator::EQUAL, "[false, false, true]");
 }
 
+TEST(TestCompareTimestamps, DifferentParameters) {
+  const std::vector<std::pair<std::string, std::string>> cases = {
+      std::make_pair("equal", "[0, 0, 1]"),
+      std::make_pair("not_equal", "[1, 1, 0]"),
+      std::make_pair("less", "[1, 0, 0]"),
+      std::make_pair("less_equal", "[1, 0, 1]"),
+      std::make_pair("greater", "[0, 1, 0]"),
+      std::make_pair("greater_equal", "[0, 1, 1]"),

Review comment:
       Food for thought: `std::pair<T,T>` can be initialized with initializer 
list:
   ```c++
   std::make_pair("equal", "[0, 0, 1]")  -->  {"equal", "[0, 0, 1]"}
   ```

##########
File path: cpp/src/arrow/compute/kernels/scalar_compare.cc
##########
@@ -140,6 +140,26 @@ struct Maximum {
 
 // Implement Less, LessEqual by flipping arguments to Greater, GreaterEqual
 
+template <typename OutType, typename ArgType, typename Op>
+struct CompareTimestamps
+    : public applicator::ScalarBinaryEqualTypes<OutType, ArgType, Op> {
+  using Base = applicator::ScalarBinaryEqualTypes<OutType, ArgType, Op>;
+
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    if (is_timestamp_type<ArgType>::value) {
+      const auto& lhs = checked_cast<const TimestampType&>(*batch[0].type());
+      const auto& rhs = checked_cast<const TimestampType&>(*batch[1].type());
+      if ((lhs.timezone().empty() && !rhs.timezone().empty()) ||
+          (!lhs.timezone().empty() && rhs.timezone().empty())) {
+        return Status::Invalid(

Review comment:
       Nit: Can simplify condition uisng XOR op.
   ```c++
   if (lhs.timezone().empty() ^ rhs.timezone().empty()) { ... }
   ```

##########
File path: cpp/src/arrow/compute/kernels/scalar_compare.cc
##########
@@ -140,6 +140,26 @@ struct Maximum {
 
 // Implement Less, LessEqual by flipping arguments to Greater, GreaterEqual
 
+template <typename OutType, typename ArgType, typename Op>
+struct CompareTimestamps
+    : public applicator::ScalarBinaryEqualTypes<OutType, ArgType, Op> {
+  using Base = applicator::ScalarBinaryEqualTypes<OutType, ArgType, Op>;
+
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    if (is_timestamp_type<ArgType>::value) {

Review comment:
       Is this check necessary? The [kernel registration only provides 
`TimstampType`](https://github.com/apache/arrow/pull/11541/files#diff-368ab7e748bd4432c92d9fdc26b51e131742b968e3eb32a6fcea4b9f02fa36aaR249)
 and this class/struct should only be used for timestamps (based on its name).




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