lidavidm commented on a change in pull request #12162:
URL: https://github.com/apache/arrow/pull/12162#discussion_r798023340
##########
File path: cpp/src/arrow/compute/kernels/scalar_nested_test.cc
##########
@@ -225,6 +225,471 @@ TEST(TestScalarNested, StructField) {
}
}
+void CheckMapLookupWithDifferentOptions(const std::shared_ptr<Array>& map,
+ const std::shared_ptr<Scalar>&
query_key,
+ const std::shared_ptr<Array>&
expected_all,
+ const std::shared_ptr<Array>&
expected_first,
+ const std::shared_ptr<Array>&
expected_last) {
+ MapLookupOptions all_matches(query_key, MapLookupOptions::ALL);
+ MapLookupOptions first_matches(query_key, MapLookupOptions::FIRST);
+ MapLookupOptions last_matches(query_key, MapLookupOptions::LAST);
+
+ CheckScalar("map_lookup", {map}, expected_all, &all_matches);
+ CheckScalar("map_lookup", {map}, expected_first, &first_matches);
+ CheckScalar("map_lookup", {map}, expected_last, &last_matches);
+}
+
+class TestMapLookupKernel : public ::testing::Test {};
+
+TEST_F(TestMapLookupKernel, Basic) {
+ auto type = map(utf8(), int32());
+ const char* input = R"(
+ [
+ [["foo", 99], ["bar", 1], ["hello", 2], ["foo", 3], ["lets go", 5],
["what now?", 8]],
+ null,
+ [["nothing", null], ["hat", null], ["foo", 101], ["sorry", 1], ["dip",
null],
+ ["foo", 22]],
+ []
+ ])";
+ auto map_array = ArrayFromJSON(type, input);
+
+ CheckMapLookupWithDifferentOptions(
+ map_array, MakeScalar("foo"),
+ ArrayFromJSON(list(int32()), R"([[99, 3], null, [101, 22], null])"),
+ ArrayFromJSON(int32(), R"([99, null, 101, null])"),
+ ArrayFromJSON(int32(), R"([3, null, 22, null])"));
+}
+
+TEST_F(TestMapLookupKernel, NestedItems) {
+ auto type = map(utf8(), map(int16(), int16()));
+ const char* input = R"(
+ [
+ [
+ [
+ "just",
+ [[0, 0], [1, 1]]
+ ],
+ [
+ "random",
+ [[2, 2], [3, 3]]
+ ],
+ [
+ "foo",
+ [[4, 4], [5, 5]]
+ ],
+ [
+ "values",
+ [[6, 6], [7, 7]]
+ ],
+ [
+ "foo",
+ [[8, 8], [9, 9]]
+ ],
+ [
+ "point",
+ [[10, 10], [11, 11]]
+ ],
+ [
+ "foo",
+ [[12, 12], [13, 13]]
+ ]
+ ],
+ null,
+ [
+ [
+ "yet",
+ [[0, 1], [1, 2]]
+ ],
+ [
+ "more",
+ [[2, 3], [3, 4]]
+ ],
+ [
+ "foo",
+ [[4, 5], [5, 6]]
+ ],
+ [
+ "random",
+ [[6, 7], [7, 8]]
+ ],
+ [
+ "foo",
+ [[8, 9], [9, 10]]
+ ],
+ [
+ "values",
+ [[10, 11], [11, 12]]
+ ],
+ [
+ "foo",
+ [[12, 13], [13, 14]]
+ ]
+ ],
+ []
+ ]
+ )";
+ const auto map_array = ArrayFromJSON(type, input);
+
+ const auto expected_all = ArrayFromJSON(list(map(int16(), int16())), R"(
+ [
+ [
+ [[4, 4], [5, 5]], [[8, 8], [9, 9]],
+ [[12, 12], [13, 13]]
+ ],
+ null,
+ [
+ [[4, 5], [5, 6]], [[8, 9], [9, 10]],
+ [[12, 13], [13, 14]]
+ ],
+ null
+ ])");
+ const auto expected_first = ArrayFromJSON(map(int16(), int16()), R"(
+ [
+ [[4, 4], [5, 5]],
+ null,
+ [[4, 5], [5, 6]],
+ null
+ ])");
+ const auto expected_last = ArrayFromJSON(map(int16(), int16()), R"(
+ [
+ [[12, 12], [13, 13]],
+ null,
+ [[12, 13], [13, 14]],
+ null
+ ])");
+
+ CheckMapLookupWithDifferentOptions(map_array, MakeScalar("foo"),
expected_all,
+ expected_first, expected_last);
+}
Review comment:
Yes, I'm not sure these tests add anything compared to the existing ones.
--
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]