bkietz commented on a change in pull request #10802: URL: https://github.com/apache/arrow/pull/10802#discussion_r685444859
########## File path: cpp/src/arrow/compute/kernels/vector_selection_test.cc ########## @@ -1734,5 +1734,372 @@ 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> +class TestDropNullKernelTyped : public TestDropNullKernel {}; + +template <typename ArrowType> +class TestDropNullKernelWithNumeric : public TestDropNullKernelTyped<ArrowType> { + protected: + void AssertDropNull(const std::string& values, const std::string& expected) { + CheckDropNull(type_singleton(), values, expected); + } + + std::shared_ptr<DataType> type_singleton() { + return TypeTraits<ArrowType>::type_singleton(); + } +}; + +TYPED_TEST_SUITE(TestDropNullKernelWithNumeric, NumericArrowTypes); +TYPED_TEST(TestDropNullKernelWithNumeric, DropNullNumeric) { + this->AssertDropNull("[7, 8, 9]", "[7, 8, 9]"); + this->AssertDropNull("[null, 8, 9]", "[8, 9]"); + this->AssertDropNull("[null, null, null]", "[]"); +} + +template <typename TypeClass> +class TestDropNullKernelWithString : public TestDropNullKernelTyped<TypeClass> { + public: + std::shared_ptr<DataType> value_type() { + return TypeTraits<TypeClass>::type_singleton(); + } + + void AssertDropNull(const std::string& values, const std::string& expected) { + CheckDropNull(value_type(), values, expected); + } + + void AssertDropNullDictionary(const std::string& dictionary_values, + const std::string& dictionary_indices, + const std::string& expected_indices) { + auto dict = ArrayFromJSON(value_type(), dictionary_values); + auto type = dictionary(int8(), value_type()); + ASSERT_OK_AND_ASSIGN(auto values, + DictionaryArray::FromArrays( + type, ArrayFromJSON(int8(), dictionary_indices), dict)); + ASSERT_OK_AND_ASSIGN( + auto expected, + DictionaryArray::FromArrays(type, ArrayFromJSON(int8(), expected_indices), dict)); + AssertDropNullArrays(values, expected); + } +}; + +TYPED_TEST_SUITE(TestDropNullKernelWithString, BinaryTypes); Review comment: https://ci.appveyor.com/project/ApacheSoftwareFoundation/arrow/builds/40309444/job/ccnm03ackeryl0m8#L1119 ```suggestion TYPED_TEST_SUITE(TestDropNullKernelWithString, BinaryArrowTypes); ``` These were renamed in #10862 -- 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