lidavidm commented on a change in pull request #11853:
URL: https://github.com/apache/arrow/pull/11853#discussion_r778106647
##########
File path: cpp/src/arrow/compute/kernels/vector_replace_test.cc
##########
@@ -793,5 +851,772 @@ TYPED_TEST(TestReplaceBinary, ReplaceWithMaskRandom) {
}
}
+template <typename T>
+class TestFillNullNumeric : public TestReplaceKernel<T> {
+ protected:
+ std::shared_ptr<DataType> type() override { return
default_type_instance<T>(); }
+};
+template <typename T>
+class TestFillNullDecimal : public TestReplaceKernel<T> {
+ protected:
+ std::shared_ptr<DataType> type() override { return
default_type_instance<T>(); }
+};
+template <typename T>
+class TestFillNullBinary : public TestReplaceKernel<T> {
+ protected:
+ std::shared_ptr<DataType> type() override { return
default_type_instance<T>(); }
+};
+
+template <typename T>
+class TestFillNullNullType : public TestReplaceKernel<T> {
+ protected:
+ std::shared_ptr<DataType> type() override { return
default_type_instance<T>(); }
+};
+
+TYPED_TEST_SUITE(TestFillNullNumeric, NumericBasedTypes);
+TYPED_TEST_SUITE(TestFillNullDecimal, DecimalArrowTypes);
+TYPED_TEST_SUITE(TestFillNullBinary, BaseBinaryArrowTypes);
+TYPED_TEST_SUITE(TestFillNullNullType, ::testing::Types<NullType>);
+
+TYPED_TEST(TestFillNullNumeric, FillNullValuesForward) {
+ this->AssertFillNullArray(FillNullForward, this->array("[]"),
this->array("[]"));
+
+ this->AssertFillNullArray(FillNullForward, this->array("[null, null, null,
null]"),
+ this->array("[null, null, null, null]"));
+ this->AssertFillNullArray(FillNullForward, this->array("[null, null, null,
4]"),
+ this->array("[null, null, null, 4]"));
+ this->AssertFillNullArray(FillNullForward, this->array("[null, 4, null]"),
+ this->array("[null, 4, 4]"));
+ this->AssertFillNullArray(FillNullForward, this->array("[null, null, 4,
null]"),
+ this->array("[null, null, 4, 4]"));
+ this->AssertFillNullArray(FillNullForward, this->array("[null, null, null,
4, null]"),
+ this->array("[null, null, null, 4, 4]"));
+ this->AssertFillNullArray(FillNullForward, this->array("[null, null, 4,null,
5, null]"),
+ this->array("[null, null, 4, 4, 5, 5]"));
+
+ this->AssertFillNullArray(FillNullForward, this->array("[1,4,null]"),
+ this->array("[1,4,4]"));
+ this->AssertFillNullArray(FillNullForward,
+ this->array("[1, 4, null, null, null, null]"),
+ this->array("[1, 4 ,4, 4, 4, 4]"));
+ this->AssertFillNullArray(FillNullForward, this->array("[1, 4, null, 5,
null, null]"),
+ this->array("[1, 4 ,4, 5, 5, 5]"));
+ this->AssertFillNullArray(FillNullForward,
+ this->array("[1, 4, null, 5, null, null, 6]"),
+ this->array("[1, 4 ,4, 5, 5, 5, 6]"));
+ this->AssertFillNullArray(FillNullForward,
+ this->array("[1, 4, null, 5, null, null, 5]"),
+ this->array("[1, 4 ,4, 5, 5, 5, 5]"));
+ this->AssertFillNullArray(FillNullForward,
+ this->array("[1, 4, null, 5, null, 6, null]"),
+ this->array("[1, 4 ,4, 5, 5, 6, 6]"));
+ this->AssertFillNullArray(FillNullForward, this->array("[1, 4, null, 5,
null, 6, 7]"),
+ this->array("[1, 4 ,4, 5, 5, 6, 7]"));
+ this->AssertFillNullArray(FillNullForward, this->array("[1, 4 ,4, 5, 5, 6,
7]"),
+ this->array("[1, 4 ,4, 5, 5, 6, 7]"));
+}
+
+TYPED_TEST(TestFillNullDecimal, FillNullValuesForward) {
+ this->AssertFillNullArray(FillNullForward, this->array(R"([])"),
this->array(R"([])"));
+
+ this->AssertFillNullArray(FillNullForward, this->array(R"([null, null, null,
null])"),
+ this->array(R"([null, null, null, null])"));
+ this->AssertFillNullArray(FillNullForward,
+ this->array(R"([null, null, null, "30.00"])"),
+ this->array(R"([null, null, null, "30.00"])"));
+ this->AssertFillNullArray(FillNullForward, this->array(R"([null, "30.00",
null])"),
+ this->array(R"([null, "30.00", "30.00"])"));
+ this->AssertFillNullArray(FillNullForward,
+ this->array(R"([null, null, "30.00", null])"),
+ this->array(R"([null, null, "30.00", "30.00"])"));
+ this->AssertFillNullArray(FillNullForward,
+ this->array(R"([null, null, null, "30.00",
null])"),
+ this->array(R"([null, null, null, "30.00",
"30.00"])"));
+ this->AssertFillNullArray(
+ FillNullForward, this->array(R"([null, null, "30.00",null, "5.00",
null])"),
+ this->array(R"([null, null, "30.00", "30.00", "5.00", "5.00"])"));
+
+ this->AssertFillNullArray(FillNullForward,
this->array(R"(["10.00","30.00",null])"),
+ this->array(R"(["10.00","30.00","30.00"])"));
+ this->AssertFillNullArray(
+ FillNullForward, this->array(R"(["10.00", "30.00", null, null, null,
null])"),
+ this->array(R"(["10.00", "30.00" ,"30.00", "30.00", "30.00",
"30.00"])"));
+ this->AssertFillNullArray(
+ FillNullForward, this->array(R"(["10.00", "30.00", null, "5.00", null,
null])"),
+ this->array(R"(["10.00", "30.00" ,"30.00", "5.00", "5.00", "5.00"])"));
+ this->AssertFillNullArray(
+ FillNullForward,
+ this->array(R"(["10.00", "30.00", null, "5.00", null, null, "6.00"])"),
+ this->array(R"(["10.00", "30.00" ,"30.00", "5.00", "5.00", "5.00",
"6.00"])"));
+ this->AssertFillNullArray(
+ FillNullForward,
+ this->array(R"(["10.00", "30.00", null, "5.00", null, null, "5.00"])"),
+ this->array(R"(["10.00", "30.00" ,"30.00", "5.00", "5.00", "5.00",
"5.00"])"));
+ this->AssertFillNullArray(
+ FillNullForward,
+ this->array(R"(["10.00", "30.00", null, "5.00", null, "6.00", null])"),
+ this->array(R"(["10.00", "30.00" ,"30.00", "5.00", "5.00", "6.00",
"6.00"])"));
+ this->AssertFillNullArray(
+ FillNullForward,
+ this->array(R"(["10.00", "30.00", null, "5.00", null, "6.00", "7.00"])"),
+ this->array(R"(["10.00", "30.00" ,"30.00", "5.00", "5.00", "6.00",
"7.00"])"));
+ this->AssertFillNullArray(
+ FillNullForward,
+ this->array(R"(["10.00", "30.00" ,"30.00", "5.00", "5.00", "6.00",
"7.00"])"),
+ this->array(R"(["10.00", "30.00" ,"30.00", "5.00", "5.00", "6.00",
"7.00"])"));
+}
+
+TYPED_TEST(TestFillNullBinary, FillNullValuesForward) {
+ this->AssertFillNullArray(FillNullForward, this->array(R"([])"),
this->array(R"([])"));
+
+ this->AssertFillNullArray(FillNullForward, this->array(R"([null, null, null,
null])"),
+ this->array(R"([null, null, null, null])"));
+ this->AssertFillNullArray(FillNullForward, this->array(R"([null, null, null,
"ccc"])"),
+ this->array(R"([null, null, null, "ccc"])"));
+ this->AssertFillNullArray(FillNullForward, this->array(R"([null, "ccc",
null])"),
+ this->array(R"([null, "ccc", "ccc"])"));
+ this->AssertFillNullArray(FillNullForward, this->array(R"([null, null,
"ccc", null])"),
+ this->array(R"([null, null, "ccc", "ccc"])"));
+ this->AssertFillNullArray(FillNullForward,
+ this->array(R"([null, null, null, "ccc", null])"),
+ this->array(R"([null, null, null, "ccc",
"ccc"])"));
+ this->AssertFillNullArray(FillNullForward,
+ this->array(R"([null, null, "ccc",null, "xyz",
null])"),
+ this->array(R"([null, null, "ccc", "ccc", "xyz",
"xyz"])"));
+
+ this->AssertFillNullArray(FillNullForward,
this->array(R"(["aaa","ccc",null])"),
+ this->array(R"(["aaa","ccc","ccc"])"));
+ this->AssertFillNullArray(FillNullForward,
+ this->array(R"(["aaa", "ccc", null, null, null,
null])"),
+ this->array(R"(["aaa", "ccc" ,"ccc", "ccc", "ccc",
"ccc"])"));
+ this->AssertFillNullArray(FillNullForward,
+ this->array(R"(["aaa", "ccc", null, "xyz", null,
null])"),
+ this->array(R"(["aaa", "ccc" ,"ccc", "xyz", "xyz",
"xyz"])"));
+ this->AssertFillNullArray(
+ FillNullForward, this->array(R"(["aaa", "ccc", null, "xyz", null, null,
"qwert"])"),
+ this->array(R"(["aaa", "ccc" ,"ccc", "xyz", "xyz", "xyz", "qwert"])"));
+ this->AssertFillNullArray(
+ FillNullForward, this->array(R"(["aaa", "ccc", null, "xyz", null, null,
"xyz"])"),
+ this->array(R"(["aaa", "ccc" ,"ccc", "xyz", "xyz", "xyz", "xyz"])"));
+ this->AssertFillNullArray(
+ FillNullForward, this->array(R"(["aaa", "ccc", null, "xyz", null,
"qwert", null])"),
+ this->array(R"(["aaa", "ccc" ,"ccc", "xyz", "xyz", "qwert", "qwert"])"));
+ this->AssertFillNullArray(
+ FillNullForward, this->array(R"(["aaa", "ccc", null, "xyz", null,
"qwert", "uy"])"),
+ this->array(R"(["aaa", "ccc" ,"ccc", "xyz", "xyz", "qwert", "uy"])"));
+ this->AssertFillNullArray(
+ FillNullForward,
+ this->array(R"(["aaa", "ccc" ,"ccc", "xyz", "xyz", "qwert", "uy"])"),
+ this->array(R"(["aaa", "ccc" ,"ccc", "xyz", "xyz", "qwert", "uy"])"));
+}
+
+TYPED_TEST(TestFillNullNumeric, FillNullValuesBackward) {
+ this->AssertFillNullArray(FillNullBackward, this->array("[]"),
this->array("[]"));
+ this->AssertFillNullArray(FillNullBackward, this->array("[null, null, null,
null]"),
+ this->array("[null, null, null, null]"));
+ this->AssertFillNullArray(FillNullBackward, this->array("[null, 4, null,
null, null]"),
+ this->array("[4, 4,null, null, null]"));
+ this->AssertFillNullArray(FillNullBackward, this->array("[null, null, null,
4]"),
+ this->array("[4, 4, 4, 4]"));
+ this->AssertFillNullArray(FillNullBackward, this->array("[null, 4, null]"),
+ this->array("[4, 4, null]"));
+ this->AssertFillNullArray(FillNullBackward, this->array("[null, null, 4,
null]"),
+ this->array("[4, 4, 4, null]"));
+ this->AssertFillNullArray(FillNullBackward, this->array("[null, null, null,
4, null]"),
+ this->array("[4, 4, 4, 4, null]"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array("[null, null, 4,null, 5, null]"),
+ this->array("[4, 4, 4, 5, 5, null]"));
+
+ this->AssertFillNullArray(FillNullBackward, this->array("[1, 4, null]"),
+ this->array("[1, 4, null]"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array("[1, 4, null, null, null, null]"),
+ this->array("[1, 4 ,null, null, null, null]"));
+ this->AssertFillNullArray(FillNullBackward, this->array("[1, 4, null, 5,
null, null]"),
+ this->array("[1, 4 , 5, 5, null, null]"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array("[1, 4, null, 5, null, null, 6]"),
+ this->array("[1, 4 ,5, 5, 6, 6, 6]"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array("[1, 4, null, 5, null, null, 5]"),
+ this->array("[1, 4 ,5 , 5, 5, 5, 5]"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array("[1, 4, null, 5, null, 6, null]"),
+ this->array("[1, 4 ,5 , 5, 6, 6, null]"));
+ this->AssertFillNullArray(FillNullBackward, this->array("[1, 4, null, 5,
null, 6, 7]"),
+ this->array("[1, 4 ,5, 5, 6, 6, 7]"));
+ this->AssertFillNullArray(FillNullBackward, this->array("[1, 4 ,5, 5, 6, 6,
7]"),
+ this->array("[1, 4 ,5, 5, 6, 6, 7]"));
+}
+
+TYPED_TEST(TestFillNullDecimal, FillNullValuesBackward) {
+ this->AssertFillNullArray(FillNullBackward, this->array(R"([])"),
this->array(R"([])"));
+
+ this->AssertFillNullArray(FillNullBackward, this->array(R"([null, null,
null, null])"),
+ this->array(R"([null, null, null, null])"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array(R"([null, "40.00", null, null,
null])"),
+ this->array(R"(["40.00", "40.00",null, null,
null])"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array(R"([null, null, null, "40.00"])"),
+ this->array(R"(["40.00", "40.00", "40.00",
"40.00"])"));
+ this->AssertFillNullArray(FillNullBackward, this->array(R"([null, "40.00",
null])"),
+ this->array(R"(["40.00", "40.00", null])"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array(R"([null, null, "40.00", null])"),
+ this->array(R"(["40.00", "40.00", "40.00",
null])"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array(R"([null, null, null, "40.00",
null])"),
+ this->array(R"(["40.00", "40.00", "40.00",
"40.00", null])"));
+ this->AssertFillNullArray(
+ FillNullBackward, this->array(R"([null, null, "40.00",null, "50.00",
null])"),
+ this->array(R"(["40.00", "40.00", "40.00", "50.00", "50.00", null])"));
+
+ this->AssertFillNullArray(FillNullBackward, this->array(R"(["10.00",
"40.00", null])"),
+ this->array(R"(["10.00", "40.00", null])"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array(R"(["10.00", "40.00", null, null,
null, null])"),
+ this->array(R"(["10.00", "40.00" ,null, null,
null, null])"));
+ this->AssertFillNullArray(
+ FillNullBackward, this->array(R"(["10.00", "40.00", null, "50.00", null,
null])"),
+ this->array(R"(["10.00", "40.00" , "50.00", "50.00", null, null])"));
+ this->AssertFillNullArray(
+ FillNullBackward,
+ this->array(R"(["10.00", "40.00", null, "50.00", null, null, "6.00"])"),
+ this->array(R"(["10.00", "40.00" ,"50.00", "50.00", "6.00", "6.00",
"6.00"])"));
+ this->AssertFillNullArray(
+ FillNullBackward,
+ this->array(R"(["10.00", "40.00", null, "50.00", null, null, "50.00"])"),
+ this->array(R"(["10.00", "40.00" ,"50.00" , "50.00", "50.00", "50.00",
"50.00"])"));
+ this->AssertFillNullArray(
+ FillNullBackward,
+ this->array(R"(["10.00", "40.00", null, "50.00", null, "6.00", null])"),
+ this->array(R"(["10.00", "40.00" ,"50.00" , "50.00", "6.00", "6.00",
null])"));
+ this->AssertFillNullArray(
+ FillNullBackward,
+ this->array(R"(["10.00", "40.00", null, "50.00", null, "6.00",
"7.00"])"),
+ this->array(R"(["10.00", "40.00" ,"50.00", "50.00", "6.00", "6.00",
"7.00"])"));
+ this->AssertFillNullArray(
+ FillNullBackward,
+ this->array(R"(["10.00", "40.00" ,"50.00", "50.00", "6.00", "6.00",
"7.00"])"),
+ this->array(R"(["10.00", "40.00" ,"50.00", "50.00", "6.00", "6.00",
"7.00"])"));
+}
+
+TYPED_TEST(TestFillNullBinary, FillNullValuesBackward) {
+ this->AssertFillNullArray(FillNullBackward, this->array(R"([])"),
this->array(R"([])"));
+
+ this->AssertFillNullArray(FillNullBackward, this->array(R"([null, null,
null, null])"),
+ this->array(R"([null, null, null, null])"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array(R"([null, "afd", null, null, null])"),
+ this->array(R"(["afd", "afd",null, null, null])"));
+ this->AssertFillNullArray(FillNullBackward, this->array(R"([null, null,
null, "afd"])"),
+ this->array(R"(["afd", "afd", "afd", "afd"])"));
+ this->AssertFillNullArray(FillNullBackward, this->array(R"([null, "afd",
null])"),
+ this->array(R"(["afd", "afd", null])"));
+ this->AssertFillNullArray(FillNullBackward, this->array(R"([null, null,
"afd", null])"),
+ this->array(R"(["afd", "afd", "afd", null])"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array(R"([null, null, null, "afd", null])"),
+ this->array(R"(["afd", "afd", "afd", "afd",
null])"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array(R"([null, null, "afd",null, "qwe",
null])"),
+ this->array(R"(["afd", "afd", "afd", "qwe", "qwe",
null])"));
+
+ this->AssertFillNullArray(FillNullBackward, this->array(R"(["tyu", "afd",
null])"),
+ this->array(R"(["tyu", "afd", null])"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array(R"(["tyu", "afd", null, null, null,
null])"),
+ this->array(R"(["tyu", "afd" ,null, null, null,
null])"));
+ this->AssertFillNullArray(FillNullBackward,
+ this->array(R"(["tyu", "afd", null, "qwe", null,
null])"),
+ this->array(R"(["tyu", "afd" , "qwe", "qwe", null,
null])"));
+ this->AssertFillNullArray(
+ FillNullBackward,
+ this->array(R"(["tyu", "afd", null, "qwe", null, null, "oiutyu"])"),
+ this->array(R"(["tyu", "afd" ,"qwe", "qwe", "oiutyu", "oiutyu",
"oiutyu"])"));
+ this->AssertFillNullArray(
+ FillNullBackward, this->array(R"(["tyu", "afd", null, "qwe", null, null,
"qwe"])"),
+ this->array(R"(["tyu", "afd" ,"qwe" , "qwe", "qwe", "qwe", "qwe"])"));
+ this->AssertFillNullArray(
+ FillNullBackward,
+ this->array(R"(["tyu", "afd", null, "qwe", null, "oiutyu", null])"),
+ this->array(R"(["tyu", "afd" ,"qwe" , "qwe", "oiutyu", "oiutyu",
null])"));
+ this->AssertFillNullArray(
+ FillNullBackward,
+ this->array(R"(["tyu", "afd", null, "qwe", null, "oiutyu",
"aaaagggbbb"])"),
+ this->array(R"(["tyu", "afd" ,"qwe", "qwe", "oiutyu", "oiutyu",
"aaaagggbbb"])"));
+ this->AssertFillNullArray(
+ FillNullBackward,
+ this->array(R"(["tyu", "afd" ,"qwe", "qwe", "oiutyu", "oiutyu",
"aaaagggbbb"])"),
+ this->array(R"(["tyu", "afd" ,"qwe", "qwe", "oiutyu", "oiutyu",
"aaaagggbbb"])"));
+}
+
+// For Test Blocks
+TYPED_TEST(TestFillNullNumeric, FillNullForwardLargeInput) {
+ using CType = typename TypeTraits<TypeParam>::CType;
+ random::RandomArrayGenerator rand(/*seed=*/1000);
+ int64_t len_null = 500;
+ int64_t len_random = 1000;
+ std::shared_ptr<Array> array_random =
+ rand.Numeric<TypeParam>(len_random, /*min=*/0, /*max=*/200, /*nulls=*/0);
+
+ if (array_random) {
+ auto x_ptr = array_random->data()->template GetValues<CType>(1);
+ ASSERT_OK_AND_ASSIGN(auto array_null,
+ MakeArrayOfNull(array_random->type(), len_null));
+ auto array_null_filled =
+ ConstantArrayGenerator::Numeric<TypeParam>(len_null, x_ptr[len_random
- 1]);
+ {
+ ASSERT_OK_AND_ASSIGN(auto value_array,
+ Concatenate({array_random, array_null,
array_random}));
+ ASSERT_OK_AND_ASSIGN(auto result_array,
+ Concatenate({array_random, array_null_filled,
array_random}));
+ this->AssertFillNullArray(FillNullForward, value_array, result_array);
+ }
+ }
+}
+
+TYPED_TEST(TestFillNullNumeric, FillNullBackwardLargeInput) {
+ using CType = typename TypeTraits<TypeParam>::CType;
+ random::RandomArrayGenerator rand(/*seed=*/1000);
+ int64_t len_null = 500;
+ int64_t len_random = 1000;
+ std::shared_ptr<Array> array_random =
+ rand.Numeric<TypeParam>(len_random, /*min=*/0, /*max=*/200,
/*null_count=*/0);
+
+ if (array_random) {
Review comment:
Then please document why the check is needed.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]