Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions cpp/src/arrow/compute/kernels/filter-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -414,5 +414,34 @@ TEST_F(TestFilterKernelWithStruct, FilterStruct) {
])");
}

class TestFilterKernelWithUnion : public TestFilterKernel<UnionType> {};

TEST_F(TestFilterKernelWithUnion, FilterUnion) {
for (auto mode : {UnionMode::SPARSE, UnionMode::DENSE}) {
auto union_type = union_({field("a", int32()), field("b", utf8())}, {2, 5}, mode);
auto union_json = R"([
null,
[2, 222],
[5, "hello"],
[5, "eh"],
null,
[2, 111]
])";
this->AssertFilter(union_type, union_json, "[0, 0, 0, 0, 0, 0]", "[]");
this->AssertFilter(union_type, union_json, "[0, 1, 1, null, 0, 1]", R"([
[2, 222],
[5, "hello"],
null,
[2, 111]
])");
this->AssertFilter(union_type, union_json, "[1, 0, 1, 0, 1, 0]", R"([
null,
[5, "hello"],
null
])");
this->AssertFilter(union_type, union_json, "[1, 1, 1, 1, 1, 1]", union_json);
}
}

} // namespace compute
} // namespace arrow
3 changes: 1 addition & 2 deletions cpp/src/arrow/compute/kernels/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <utility>

#include "arrow/builder.h"
#include "arrow/compute/context.h"
#include "arrow/compute/kernels/take-internal.h"
#include "arrow/util/checked_cast.h"
#include "arrow/util/logging.h"
Expand Down Expand Up @@ -88,7 +87,7 @@ class FilterKernelImpl : public FilterKernel {
if (values.length() != filter.length()) {
return Status::Invalid("filter and value array must have identical lengths");
}
RETURN_NOT_OK(taker_->Init(ctx->memory_pool()));
RETURN_NOT_OK(taker_->SetContext(ctx));
RETURN_NOT_OK(taker_->Take(values, FilterIndexSequence(filter, length)));
return taker_->Finish(out);
}
Expand Down
Loading