pitrou commented on a change in pull request #10802: URL: https://github.com/apache/arrow/pull/10802#discussion_r689504478
########## File path: cpp/src/arrow/compute/kernels/vector_selection_test.cc ########## @@ -1734,5 +1735,551 @@ TEST(TestTake, RandomFixedSizeBinary) { TakeRandomTest<FixedSizeBinaryType>::Test(fixed_size_binary(16)); } +// ---------------------------------------------------------------------- +// DropNull tests + +void AssertDropNullArrays(const std::shared_ptr<Array>& values, + const std::shared_ptr<Array>& expected) { + ASSERT_OK_AND_ASSIGN(std::shared_ptr<Array> actual, DropNull(*values)); + ValidateOutput(actual); + AssertArraysEqual(*expected, *actual, /*verbose=*/true); +} + +Status DropNullJSON(const std::shared_ptr<DataType>& type, const std::string& values, + std::shared_ptr<Array>* out) { + return DropNull(*ArrayFromJSON(type, values)).Value(out); +} + +void CheckDropNull(const std::shared_ptr<DataType>& type, const std::string& values, + const std::string& expected) { + std::shared_ptr<Array> actual; + + ASSERT_OK(DropNullJSON(type, values, &actual)); + ValidateOutput(actual); + AssertArraysEqual(*ArrayFromJSON(type, expected), *actual, /*verbose=*/true); +} + +struct TestDropNullKernel : public ::testing::Test { + void TestNoValidityBitmapButUnknownNullCount(const std::shared_ptr<Array>& values) { + ASSERT_EQ(values->null_count(), 0); + auto expected = (*DropNull(values)).make_array(); + + auto new_values = MakeArray(values->data()->Copy()); + new_values->data()->buffers[0].reset(); + new_values->data()->null_count = kUnknownNullCount; + auto result = (*DropNull(new_values)).make_array(); + AssertArraysEqual(*expected, *result); + } + + void TestNoValidityBitmapButUnknownNullCount(const std::shared_ptr<DataType>& type, + const std::string& values) { + TestNoValidityBitmapButUnknownNullCount(ArrayFromJSON(type, values)); + } +}; + +TEST_F(TestDropNullKernel, DropNull) { + CheckDropNull(null(), "[null, null, null]", "[]"); + CheckDropNull(null(), "[null]", "[]"); +} + +TEST_F(TestDropNullKernel, DropNullBoolean) { + CheckDropNull(boolean(), "[true, false, true]", "[true, false, true]"); + CheckDropNull(boolean(), "[null, false, true]", "[false, true]"); + + TestNoValidityBitmapButUnknownNullCount(boolean(), "[true, false, true]"); +} + +template <typename ArrowType> +struct TestDropNullKernelTyped : public TestDropNullKernel { + TestDropNullKernelTyped() : rng_(seed_) {} + + template <typename OffsetType> + std::vector<OffsetType> Offsets(int32_t length, int32_t slice_count) { + std::vector<OffsetType> offsets(static_cast<std::size_t>(slice_count + 1)); + std::default_random_engine gen(seed_); + std::uniform_int_distribution<OffsetType> dist(0, length); + std::generate(offsets.begin(), offsets.end(), [&] { return dist(gen); }); + std::sort(offsets.begin(), offsets.end()); + return offsets; + } Review comment: Hmm, I'm not sure I understand what you mean here. You should just pass a zero null_probability for offsets (the default). -- 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