You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "lidavidm (via GitHub)" <gi...@apache.org> on 2023/04/12 11:10:49 UTC

[GitHub] [arrow] lidavidm commented on a diff in pull request #34961: GH-34960: [C++] test util Fixing arrow Random Generator for lost nullable info

lidavidm commented on code in PR #34961:
URL: https://github.com/apache/arrow/pull/34961#discussion_r1163975967


##########
cpp/src/arrow/testing/random_test.cc:
##########
@@ -499,6 +499,45 @@ TEST(RandomList, Basics) {
   }
 }
 
+TEST(RandomNestedBatchOf, Basics) {
+  random::RandomArrayGenerator rng(42);
+  {
+    auto item = std::make_shared<arrow::Field>("item", arrow::int8(), true);
+    auto nestListField = std::make_shared<arrow::Field>("list", arrow::list(item), false);

Review Comment:
   nit: use `arrow::field` helper, remember to use `snake_case` variable names



##########
cpp/src/arrow/testing/random.cc:
##########
@@ -916,14 +916,14 @@ std::shared_ptr<Array> RandomArrayGenerator::ArrayOf(const Field& field, int64_t
 
     case Type::type::STRUCT: {
       ArrayVector child_arrays(field.type()->num_fields());
-      std::vector<std::string> field_names;
+      FieldVector child_fields;
       for (int i = 0; i < field.type()->num_fields(); i++) {
         const auto& child_field = field.type()->field(i);
         child_arrays[i] = ArrayOf(*child_field, length, alignment, memory_pool);
-        field_names.push_back(child_field->name());
+        child_fields.push_back(child_field);
       }
       return *StructArray::Make(
-          child_arrays, field_names,
+          child_arrays, child_fields,

Review Comment:
   Sorry, what are you saying fails? I agree the proposed code is more correct.



##########
cpp/src/arrow/testing/random_test.cc:
##########
@@ -499,6 +499,45 @@ TEST(RandomList, Basics) {
   }
 }
 
+TEST(RandomNestedBatchOf, Basics) {

Review Comment:
   And for all three tests, can you call out specifically that we want to test child field nullability is preserved?



##########
cpp/src/arrow/testing/random_test.cc:
##########
@@ -499,6 +499,45 @@ TEST(RandomList, Basics) {
   }
 }
 
+TEST(RandomNestedBatchOf, Basics) {
+  random::RandomArrayGenerator rng(42);
+  {
+    auto item = std::make_shared<arrow::Field>("item", arrow::int8(), true);
+    auto nestListField = std::make_shared<arrow::Field>("list", arrow::list(item), false);
+    auto listField =
+        std::make_shared<arrow::Field>("list", arrow::list(nestListField), true);
+    auto array = rng.ArrayOf(*listField, 428);
+    ARROW_EXPECT_OK(array->ValidateFull());
+
+    auto batch = rng.BatchOf({listField}, 428);
+    ARROW_EXPECT_OK(batch->ValidateFull());
+  }
+  {
+    auto item = std::make_shared<arrow::Field>("item", arrow::int8(), true);
+    auto nestStructField =
+        std::make_shared<arrow::Field>("struct", arrow::struct_({item}), false);
+    auto structField =
+        std::make_shared<arrow::Field>("struct", arrow::struct_({nestStructField}), true);
+    auto array = rng.ArrayOf(*structField, 428);
+    ARROW_EXPECT_OK(array->ValidateFull());
+
+    auto batch = rng.BatchOf({structField}, 428);
+    ARROW_EXPECT_OK(batch->ValidateFull());
+  }
+  {

Review Comment:
   And `RandomMap` here.



##########
cpp/src/arrow/testing/random_test.cc:
##########
@@ -499,6 +499,45 @@ TEST(RandomList, Basics) {
   }
 }
 
+TEST(RandomNestedBatchOf, Basics) {
+  random::RandomArrayGenerator rng(42);
+  {
+    auto item = std::make_shared<arrow::Field>("item", arrow::int8(), true);
+    auto nestListField = std::make_shared<arrow::Field>("list", arrow::list(item), false);
+    auto listField =
+        std::make_shared<arrow::Field>("list", arrow::list(nestListField), true);
+    auto array = rng.ArrayOf(*listField, 428);
+    ARROW_EXPECT_OK(array->ValidateFull());
+
+    auto batch = rng.BatchOf({listField}, 428);
+    ARROW_EXPECT_OK(batch->ValidateFull());
+  }
+  {

Review Comment:
   Can this be made into a `RandomStruct` suite?



##########
cpp/src/arrow/testing/random_test.cc:
##########
@@ -499,6 +499,45 @@ TEST(RandomList, Basics) {
   }
 }
 
+TEST(RandomNestedBatchOf, Basics) {

Review Comment:
   Can this just be part of the `RandomList` suite as a new case?



##########
cpp/src/arrow/testing/random.cc:
##########
@@ -793,7 +793,7 @@ std::shared_ptr<Array> RandomArrayGenerator::ArrayOf(const Field& field, int64_t
                 values_length, alignment, memory_pool);                              \
     const auto offsets = OffsetsFromLengthsArray(lengths.get(), force_empty_nulls,   \
                                                  alignment, memory_pool);            \
-    return *ARRAY_TYPE::FromArrays(*offsets, *values);                               \
+    return *ARRAY_TYPE::FromArrays(field.type(), *offsets, *values);                 \

Review Comment:
   Specifically, if you look at the case for MapType, it already passes the type. So this is just bringing ListType into alignment.



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org