lidavidm commented on code in PR #13037:
URL: https://github.com/apache/arrow/pull/13037#discussion_r862789676


##########
cpp/src/arrow/compute/kernels/scalar_compare_test.cc:
##########
@@ -502,6 +502,53 @@ TEST(TestCompareTimestamps, DifferentParameters) {
   }
 }
 
+TEST(TestCompareTimestamps, ScalarArray) {
+  const char* scalar_json = R"("1970-01-02")";
+  const char* array_json = R"(["1970-01-02","2000-02-01","1900-02-28"])";

Review Comment:
   Can we add a `null` element here too?



##########
cpp/src/arrow/compute/kernels/scalar_compare_test.cc:
##########
@@ -502,6 +502,53 @@ TEST(TestCompareTimestamps, DifferentParameters) {
   }
 }
 
+TEST(TestCompareTimestamps, ScalarArray) {
+  const char* scalar_json = R"("1970-01-02")";
+  const char* array_json = R"(["1970-01-02","2000-02-01","1900-02-28"])";
+
+  auto CheckArrayCase = [&](std::shared_ptr<DataType> scalar_type,
+                            std::shared_ptr<DataType> array_type, 
CompareOperator op,
+                            const char* expected_json) {
+    auto lhs = ScalarFromJSON(scalar_type, scalar_json);
+    auto rhs = ArrayFromJSON(array_type, array_json);
+    auto expected = ArrayFromJSON(boolean(), expected_json);
+    if (scalar_type->Equals(array_type)) {
+      ASSERT_OK_AND_ASSIGN(Datum result,
+                           CallFunction(CompareOperatorToFunctionName(op), 
{lhs, rhs}));
+      AssertArraysEqual(*expected, *result.make_array(), /*verbose=*/true);
+    } else {
+      EXPECT_RAISES_WITH_MESSAGE_THAT(
+          Invalid,
+          ::testing::HasSubstr(
+              "Cannot compare timestamp with timezone to timestamp without 
timezone"),
+          CallFunction(CompareOperatorToFunctionName(op), {lhs, rhs}));
+    }
+  };
+
+  for (auto unit : {
+           TimeUnit::SECOND,
+           TimeUnit::MILLI,
+           TimeUnit::MICRO,
+           TimeUnit::NANO,
+       }) {
+    for (auto types :
+         std::vector<std::pair<std::shared_ptr<DataType>, 
std::shared_ptr<DataType>>>{
+             {timestamp(unit), timestamp(unit)},
+             {timestamp(unit), timestamp(unit, "utc")},
+             {timestamp(unit, "utc"), timestamp(unit)},
+             {timestamp(unit, "utc"), timestamp(unit, "utc")},
+         }) {
+      auto t0 = types.first, t1 = types.second;
+      CheckArrayCase(t0, t1, CompareOperator::EQUAL, "[true, false, false]");

Review Comment:
   At the very least we should test that the comparison works when the scalar 
is second. And then it would likely be easier to write it out instead of trying 
to factor out a helper function.



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