lidavidm commented on a change in pull request #12162:
URL: https://github.com/apache/arrow/pull/12162#discussion_r794491952
##########
File path: cpp/src/arrow/compute/kernels/scalar_nested_test.cc
##########
@@ -225,6 +225,423 @@ TEST(TestScalarNested, StructField) {
}
}
+void CheckMapArrayLookupWithDifferentOptions(
+ 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) {
+ MapArrayLookupOptions all_matches(query_key, MapArrayLookupOptions::ALL);
+ MapArrayLookupOptions first_matches(query_key, MapArrayLookupOptions::FIRST);
+ MapArrayLookupOptions last_matches(query_key, MapArrayLookupOptions::LAST);
+
+ CheckScalar("map_array_lookup", {map}, expected_all, &all_matches);
+ CheckScalar("map_array_lookup", {map}, expected_first, &first_matches);
+ CheckScalar("map_array_lookup", {map}, expected_last, &last_matches);
+}
+
+class TestMapArrayLookupKernel : public ::testing::Test {};
+
+TEST_F(TestMapArrayLookupKernel, 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);
+
+ CheckMapArrayLookupWithDifferentOptions(
+ 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(TestMapArrayLookupKernel, 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
+ ])");
+
+ CheckMapArrayLookupWithDifferentOptions(map_array, MakeScalar("foo"),
expected_all,
+ expected_first, expected_last);
+}
+
+TEST_F(TestMapArrayLookupKernel, BooleanKey) {
+ auto true_scalar = ScalarFromJSON(boolean(), R"(true)");
+ auto map_type = map(boolean(), int32());
+ const char* input = R"(
+ [
+ [
+ [true, 99], [false, 1], [false, 2], [true, null], [false, 5],
+ [true, 8]
+ ],
+ null,
+ [
+ [false, null], [true, 67], [false, 101], [false, 1], [false, null],
+ [false, 9], [true, 80]
+ ],
+ [],
+ [
+ [false, 1], [false, 2], [false, 3], [false, 4]
+ ],
+ [
+ [true, 9], [true, 2], [true, 5], [true, 8]
Review comment:
Ah, I didn't realize that was disallowed. Ok then, we should be good.
And that means we don't have to decide what to do with null query keys. That
also means we should check if the query key is null and return an error in that
case.
--
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]