lidavidm commented on code in PR #13037:
URL: https://github.com/apache/arrow/pull/13037#discussion_r864765944
##########
cpp/src/arrow/compute/kernels/scalar_compare_test.cc:
##########
@@ -502,6 +502,64 @@ 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",null,"1900-02-28"])";
+
+ struct ArrayCase {
+ Datum side1, side2, expected;
+ };
+ auto CheckArrayCase = [&](std::shared_ptr<DataType> scalar_type,
+ std::shared_ptr<DataType> array_type,
CompareOperator op,
+ const char* expected_json, const char*
flip_expected_json) {
Review Comment:
`const std::string&`?
##########
cpp/src/arrow/compute/kernels/scalar_compare_test.cc:
##########
@@ -502,6 +502,64 @@ 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",null,"1900-02-28"])";
Review Comment:
Can we use std::string?
##########
cpp/src/arrow/compute/kernels/scalar_compare_test.cc:
##########
@@ -502,6 +502,64 @@ 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",null,"1900-02-28"])";
+
+ struct ArrayCase {
+ Datum side1, side2, expected;
+ };
+ auto CheckArrayCase = [&](std::shared_ptr<DataType> scalar_type,
+ std::shared_ptr<DataType> array_type,
CompareOperator op,
+ const char* expected_json, const char*
flip_expected_json) {
+ auto scalar_side = ScalarFromJSON(scalar_type, scalar_json);
+ auto array_side = ArrayFromJSON(array_type, array_json);
+ auto expected = ArrayFromJSON(boolean(), expected_json);
+ auto flip_expected = ArrayFromJSON(boolean(), flip_expected_json);
+ for (auto array_case :
+ std::vector<ArrayCase>{{scalar_side, array_side, expected},
+ {array_side, scalar_side, flip_expected}}) {
+ auto lhs = array_case.side1, rhs = array_case.side2;
Review Comment:
`const auto&`?
##########
cpp/src/arrow/compute/kernels/scalar_compare_test.cc:
##########
@@ -502,6 +502,64 @@ 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",null,"1900-02-28"])";
+
+ struct ArrayCase {
+ Datum side1, side2, expected;
+ };
+ auto CheckArrayCase = [&](std::shared_ptr<DataType> scalar_type,
+ std::shared_ptr<DataType> array_type,
CompareOperator op,
+ const char* expected_json, const char*
flip_expected_json) {
+ auto scalar_side = ScalarFromJSON(scalar_type, scalar_json);
+ auto array_side = ArrayFromJSON(array_type, array_json);
+ auto expected = ArrayFromJSON(boolean(), expected_json);
+ auto flip_expected = ArrayFromJSON(boolean(), flip_expected_json);
+ for (auto array_case :
+ std::vector<ArrayCase>{{scalar_side, array_side, expected},
+ {array_side, scalar_side, flip_expected}}) {
+ auto lhs = array_case.side1, rhs = array_case.side2;
+ if (scalar_type->Equals(array_type)) {
+ ASSERT_OK_AND_ASSIGN(Datum result,
+ CallFunction(CompareOperatorToFunctionName(op),
{lhs, rhs}));
+ AssertArraysEqual(*array_case.expected.make_array(),
*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::values()) {
+ for (auto types :
Review Comment:
`const auto&`?
##########
cpp/src/arrow/compute/kernels/scalar_compare_test.cc:
##########
@@ -502,6 +502,64 @@ 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",null,"1900-02-28"])";
+
+ struct ArrayCase {
+ Datum side1, side2, expected;
+ };
+ auto CheckArrayCase = [&](std::shared_ptr<DataType> scalar_type,
+ std::shared_ptr<DataType> array_type,
CompareOperator op,
+ const char* expected_json, const char*
flip_expected_json) {
+ auto scalar_side = ScalarFromJSON(scalar_type, scalar_json);
+ auto array_side = ArrayFromJSON(array_type, array_json);
+ auto expected = ArrayFromJSON(boolean(), expected_json);
+ auto flip_expected = ArrayFromJSON(boolean(), flip_expected_json);
+ for (auto array_case :
Review Comment:
`const auto&`?
##########
cpp/src/arrow/compute/kernels/scalar_compare_test.cc:
##########
@@ -502,6 +502,64 @@ 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",null,"1900-02-28"])";
+
+ struct ArrayCase {
+ Datum side1, side2, expected;
+ };
+ auto CheckArrayCase = [&](std::shared_ptr<DataType> scalar_type,
+ std::shared_ptr<DataType> array_type,
CompareOperator op,
+ const char* expected_json, const char*
flip_expected_json) {
+ auto scalar_side = ScalarFromJSON(scalar_type, scalar_json);
+ auto array_side = ArrayFromJSON(array_type, array_json);
+ auto expected = ArrayFromJSON(boolean(), expected_json);
+ auto flip_expected = ArrayFromJSON(boolean(), flip_expected_json);
+ for (auto array_case :
+ std::vector<ArrayCase>{{scalar_side, array_side, expected},
+ {array_side, scalar_side, flip_expected}}) {
+ auto lhs = array_case.side1, rhs = array_case.side2;
+ if (scalar_type->Equals(array_type)) {
+ ASSERT_OK_AND_ASSIGN(Datum result,
+ CallFunction(CompareOperatorToFunctionName(op),
{lhs, rhs}));
+ AssertArraysEqual(*array_case.expected.make_array(),
*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::values()) {
+ 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;
Review Comment:
`const auto&`?
--
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]