diff --git a/cpp/src/arrow/compute/kernels/filter-test.cc b/cpp/src/arrow/compute/kernels/filter-test.cc index 0607a70885688..6ccca0a381daa 100644 --- a/cpp/src/arrow/compute/kernels/filter-test.cc +++ b/cpp/src/arrow/compute/kernels/filter-test.cc @@ -323,18 +323,46 @@ TEST_F(TestFilterKernelWithFixedSizeList, FilterFixedSizeListInt32) { "[[1, null, 3], [7, 8, null]]"); } +class TestFilterKernelWithMap : public TestFilterKernel {}; + +TEST_F(TestFilterKernelWithMap, FilterMapStringToInt32) { + std::string map_json = R"([ + [["joe", 0], ["mark", null]], + null, + [["cap", 8]], + [] + ])"; + this->AssertFilter(map(utf8(), int32()), map_json, "[0, 0, 0, 0]", "[]"); + this->AssertFilter(map(utf8(), int32()), map_json, "[0, 1, 1, null]", R"([ + null, + [["cap", 8]], + null + ])"); + this->AssertFilter(map(utf8(), int32()), map_json, "[1, 1, 1, 1]", map_json); + this->AssertFilter(map(utf8(), int32()), map_json, "[0, 1, 0, 1]", "[null, []]"); +} + class TestFilterKernelWithStruct : public TestFilterKernel {}; TEST_F(TestFilterKernelWithStruct, FilterStruct) { auto struct_type = struct_({field("a", int32()), field("b", utf8())}); - auto struct_json = - R"([null, {"a": 1, "b": ""}, {"a": 2, "b": "hello"}, {"a": 4, "b": "eh"}])"; + auto struct_json = R"([ + null, + {"a": 1, "b": ""}, + {"a": 2, "b": "hello"}, + {"a": 4, "b": "eh"} + ])"; this->AssertFilter(struct_type, struct_json, "[0, 0, 0, 0]", "[]"); - this->AssertFilter(struct_type, struct_json, "[0, 1, 1, null]", - R"([{"a": 1, "b": ""}, {"a": 2, "b": "hello"}, null])"); + this->AssertFilter(struct_type, struct_json, "[0, 1, 1, null]", R"([ + {"a": 1, "b": ""}, + {"a": 2, "b": "hello"}, + null + ])"); this->AssertFilter(struct_type, struct_json, "[1, 1, 1, 1]", struct_json); - this->AssertFilter(struct_type, struct_json, "[1, 0, 1, 0]", - R"([null, {"a": 2, "b": "hello"}])"); + this->AssertFilter(struct_type, struct_json, "[1, 0, 1, 0]", R"([ + null, + {"a": 2, "b": "hello"} + ])"); } } // namespace compute diff --git a/cpp/src/arrow/compute/kernels/filter.cc b/cpp/src/arrow/compute/kernels/filter.cc index 0b369a3a4bd07..7d5930748aea4 100644 --- a/cpp/src/arrow/compute/kernels/filter.cc +++ b/cpp/src/arrow/compute/kernels/filter.cc @@ -407,6 +407,8 @@ struct UnpackValues { Status Visit(const ListType& t) { return Make(); } + Status Visit(const MapType& t) { return Make(); } + Status Visit(const FixedSizeListType& t) { return Make>(); }