From 96220d1797e608e29472d73a081306c61b299a5f Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Wed, 2 Oct 2019 11:48:30 -0700 Subject: [PATCH 1/3] Test and fix for bug in filter kernel with a slice --- cpp/src/arrow/compute/kernels/filter.cc | 4 +--- cpp/src/arrow/compute/kernels/filter_test.cc | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cpp/src/arrow/compute/kernels/filter.cc b/cpp/src/arrow/compute/kernels/filter.cc index f985886973b..86545aa1c61 100644 --- a/cpp/src/arrow/compute/kernels/filter.cc +++ b/cpp/src/arrow/compute/kernels/filter.cc @@ -65,10 +65,8 @@ class FilterIndexSequence { // TODO(bkietz) this can be optimized static int64_t OutputSize(const BooleanArray& filter) { - auto offset = filter.offset(); - auto length = filter.length(); int64_t size = 0; - for (auto i = offset; i < offset + length; ++i) { + for (auto i = 0; i < filter.length(); ++i) { if (filter.IsNull(i) || filter.Value(i)) { ++size; } diff --git a/cpp/src/arrow/compute/kernels/filter_test.cc b/cpp/src/arrow/compute/kernels/filter_test.cc index 37f609e92d5..cc75edd028a 100644 --- a/cpp/src/arrow/compute/kernels/filter_test.cc +++ b/cpp/src/arrow/compute/kernels/filter_test.cc @@ -151,6 +151,12 @@ TYPED_TEST(TestFilterKernelWithNumeric, FilterNumeric) { this->AssertFilter("[7, 8, 9]", "[null, 1, 0]", "[null, 8]"); this->AssertFilter("[7, 8, 9]", "[1, null, 1]", "[7, null, 9]"); + this->AssertFilterArrays( + ArrayFromJSON(this->type_singleton(), "[7, 8, 9]"), + ArrayFromJSON(boolean(), "[0, 1, 1, 1, 0, 1]")->Slice(3, 3), + ArrayFromJSON(this->type_singleton(), "[7, 9]") + ); + std::shared_ptr arr; ASSERT_RAISES(Invalid, this->Filter(this->type_singleton(), "[7, 8, 9]", "[]", &arr)); } From f7e9475b730d585c4338bf8a698aa7474d8533d0 Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Wed, 2 Oct 2019 13:32:29 -0700 Subject: [PATCH 2/3] lint --- cpp/src/arrow/compute/kernels/filter_test.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cpp/src/arrow/compute/kernels/filter_test.cc b/cpp/src/arrow/compute/kernels/filter_test.cc index cc75edd028a..0032a3f5488 100644 --- a/cpp/src/arrow/compute/kernels/filter_test.cc +++ b/cpp/src/arrow/compute/kernels/filter_test.cc @@ -154,8 +154,7 @@ TYPED_TEST(TestFilterKernelWithNumeric, FilterNumeric) { this->AssertFilterArrays( ArrayFromJSON(this->type_singleton(), "[7, 8, 9]"), ArrayFromJSON(boolean(), "[0, 1, 1, 1, 0, 1]")->Slice(3, 3), - ArrayFromJSON(this->type_singleton(), "[7, 9]") - ); + ArrayFromJSON(this->type_singleton(), "[7, 9]")); std::shared_ptr arr; ASSERT_RAISES(Invalid, this->Filter(this->type_singleton(), "[7, 8, 9]", "[]", &arr)); From 3a772fcc56da774a691b5be2ee146f6a53588503 Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Wed, 2 Oct 2019 13:38:18 -0700 Subject: [PATCH 3/3] Lint again --- cpp/src/arrow/compute/kernels/filter_test.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/compute/kernels/filter_test.cc b/cpp/src/arrow/compute/kernels/filter_test.cc index 0032a3f5488..bb685f474dc 100644 --- a/cpp/src/arrow/compute/kernels/filter_test.cc +++ b/cpp/src/arrow/compute/kernels/filter_test.cc @@ -151,10 +151,9 @@ TYPED_TEST(TestFilterKernelWithNumeric, FilterNumeric) { this->AssertFilter("[7, 8, 9]", "[null, 1, 0]", "[null, 8]"); this->AssertFilter("[7, 8, 9]", "[1, null, 1]", "[7, null, 9]"); - this->AssertFilterArrays( - ArrayFromJSON(this->type_singleton(), "[7, 8, 9]"), - ArrayFromJSON(boolean(), "[0, 1, 1, 1, 0, 1]")->Slice(3, 3), - ArrayFromJSON(this->type_singleton(), "[7, 9]")); + this->AssertFilterArrays(ArrayFromJSON(this->type_singleton(), "[7, 8, 9]"), + ArrayFromJSON(boolean(), "[0, 1, 1, 1, 0, 1]")->Slice(3, 3), + ArrayFromJSON(this->type_singleton(), "[7, 9]")); std::shared_ptr arr; ASSERT_RAISES(Invalid, this->Filter(this->type_singleton(), "[7, 8, 9]", "[]", &arr));