dhruv9vats commented on a change in pull request #12162: URL: https://github.com/apache/arrow/pull/12162#discussion_r788751815
########## File path: cpp/src/arrow/compute/kernels/scalar_nested_test.cc ########## @@ -225,6 +225,167 @@ TEST(TestScalarNested, StructField) { } } +TEST(TestScalarNested, MapArrayLookup) { + MapArrayLookupOptions foo_all(MakeScalar("foo"), MapArrayLookupOptions::ALL); + MapArrayLookupOptions foo_first(MakeScalar("foo"), MapArrayLookupOptions::FIRST); + MapArrayLookupOptions foo_last(MakeScalar("foo"), MapArrayLookupOptions::LAST); + + auto type = map(utf8(), int32()); + const char* input = R"( + [ + [["foo", 99], ["bar", 1], ["hello", 2], ["foo", 3], ["lesgo", 5], ["whatnow", 8]], + null, + [["nothing", null], ["hat", null], ["foo", 101], ["sorry", 1], ["dip", null], + ["foo", 22]], + [] + ] + )"; + auto map_array = ArrayFromJSON(type, input); + + CheckScalar("map_array_lookup", {map_array}, + ArrayFromJSON(list(int32()), "[[99, 3], null, [101, 22], null]"), &foo_all); + CheckScalar("map_array_lookup", {map_array}, + ArrayFromJSON(int32(), "[99, null, 101, null]"), &foo_first); + CheckScalar("map_array_lookup", {map_array}, + ArrayFromJSON(int32(), "[3, null, 22, null]"), &foo_last); +} + +TEST(TestScalarNested, MapArrayLookupNested) { + 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]] + ] + ], + [] + ] + )"; + auto map_array = ArrayFromJSON(type, input); + + MapArrayLookupOptions foo_all(MakeScalar("foo"), MapArrayLookupOptions::ALL); + MapArrayLookupOptions foo_first(MakeScalar("foo"), MapArrayLookupOptions::FIRST); + MapArrayLookupOptions foo_last(MakeScalar("foo"), MapArrayLookupOptions::LAST); + + auto foo_all_output = ArrayFromJSON( + list(map(int16(), int16())), + "[ [[[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 ]"); + + CheckScalar("map_array_lookup", {map_array}, foo_all_output, &foo_all); + CheckScalar("map_array_lookup", {map_array}, + ArrayFromJSON(map(int16(), int16()), + "[ [[4, 4], [5, 5]], null, [[4, 5], [5, 6]], null ]"), + &foo_first); + CheckScalar("map_array_lookup", {map_array}, + ArrayFromJSON(map(int16(), int16()), + "[ [[12, 12], [13, 13]], null, [[12, 13], [13, 14]], null ]"), + &foo_last); +} + +template <typename Type> +class TestMapArrayLookupIntegralKeys : public ::testing ::Test {}; + +TYPED_TEST_SUITE(TestMapArrayLookupIntegralKeys, IntegralArrowTypes); + +TYPED_TEST(TestMapArrayLookupIntegralKeys, StringItems) { Review comment: This basic structure has to be repeated for `StringArrowTypes` and `DecimalArrowTypes`, right? Also should templated tests be written for `BinaryArrowTypes` and `StringArrowTypes`? -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org