kou commented on code in PR #46031:
URL: https://github.com/apache/arrow/pull/46031#discussion_r2055488982


##########
cpp/src/arrow/record_batch_test.cc:
##########
@@ -1423,35 +1452,132 @@ TEST_F(TestRecordBatch, 
MakeStatisticsArrayMaxApproximate) {
   AssertArraysEqual(*expected_statistics_array, *statistics_array, true);
 }
 
-TEST_F(TestRecordBatch, MakeStatisticsArrayString) {
-  auto schema =
-      ::arrow::schema({field("no-statistics", boolean()), field("string", 
utf8())});
-  auto no_statistics_array = ArrayFromJSON(boolean(), "[true, false, true]");
-  auto string_array_data = ArrayFromJSON(utf8(), "[\"a\", null, 
\"c\"]")->data()->Copy();
-  string_array_data->statistics = std::make_shared<ArrayStatistics>();
-  string_array_data->statistics->is_max_exact = true;
-  string_array_data->statistics->max = "c";
-  auto string_array = MakeArray(std::move(string_array_data));
-  auto batch = RecordBatch::Make(schema, string_array->length(),
-                                 {no_statistics_array, string_array});
+template <typename DataType>
+class TestRecordBatchMakeStatisticsArrayStringBase {
+ public:
+  std::shared_ptr<::arrow::DataType> type(int32_t byte_width = 1) {
+    if constexpr (std::is_same_v<DataType, FixedSizeBinaryType>) {
+      return fixed_size_binary(byte_width);
+    } else {
+      return TypeTraits<DataType>::type_singleton();
+    }
+  }
+  std::shared_ptr<Array> GenerateString(
+      const std::shared_ptr<::arrow::DataType>& data_type) {
+    if (data_type->id() == Type::FIXED_SIZE_BINARY) {
+      auto byte_width = data_type->byte_width();
+      auto a = std::string(byte_width, 'a');
+      auto b = std::string(byte_width, 'b');
+      auto c = std::string(byte_width, 'c');
+      std::stringstream ss;
+      ss << R"([")" << a << R"(",")" << b << R"(",")" << c << R"("])";
+      return ArrayFromJSON(data_type, ss.str());
+    }
+    return ArrayFromJSON(data_type, R"(["a","b","c"])");
+  }

Review Comment:
   How about defining them as functions in anonymous namespace instead of 
defining this template class and using it as parent class of 
`TestRecordBatchMakeStatisticsArrayEachStringType` and 
`TestRecordBatchMakeStatisticsArrayStringBase`?
   I think that it simplifies these tests.



-- 
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

Reply via email to