MCPcopy Create free account
hub / github.com/apache/arrow / MakeStrTestBatch

Function MakeStrTestBatch

cpp/src/arrow/csv/writer_benchmark.cc:58–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58std::shared_ptr<RecordBatch> MakeStrTestBatch(int rows, int cols, bool quote,
59 int64_t null_percent) {
60 random::RandomArrayGenerator rg(kSeed + 1);
61
62 // append quote to array elements (return a new array)
63 auto append_quote = [](const Array& array) -> std::shared_ptr<Array> {
64 typename TypeTraits<StringType>::BuilderType builder;
65 const auto& string_array = dynamic_cast<const StringArray&>(array);
66 for (int64_t i = 0; i < string_array.length(); ++i) {
67 if (string_array.IsValid(i)) {
68 ABORT_NOT_OK(builder.Append(string_array.GetString(i) + '"'));
69 } else {
70 ABORT_NOT_OK(builder.AppendNull());
71 }
72 }
73 std::shared_ptr<Array> result;
74 ABORT_NOT_OK(builder.Finish(&result));
75 return result;
76 };
77
78 // string length varies from kStrLenMin to kStrLenMax for different columns
79 auto lengths =
80 std::dynamic_pointer_cast<Int32Array>(rg.Int32(cols, kStrLenMin, kStrLenMax));
81 FieldVector fields(cols);
82 ArrayVector arrays(cols);
83 for (int i = 0; i < cols; ++i) {
84 fields[i] = field('s' + std::to_string(i), utf8());
85 // string length varies by 20% for different rows in same column
86 arrays[i] = rg.String(rows, lengths->Value(i), lengths->Value(i) * 6 / 5,
87 null_percent / 100.);
88 if (quote) {
89 arrays[i] = append_quote(*arrays[i]);
90 }
91 }
92
93 return RecordBatch::Make(schema(fields), rows, arrays);
94}
95
96void BenchmarkWriteCsv(benchmark::State& state, const WriteOptions& options,
97 const RecordBatch& batch) {

Callers 3

WriteCsvStringNoQuoteFunction · 0.85
WriteCsvStringWithQuoteFunction · 0.85

Calls 13

to_stringFunction · 0.85
Int32Method · 0.80
fieldFunction · 0.50
MakeFunction · 0.50
schemaFunction · 0.50
lengthMethod · 0.45
IsValidMethod · 0.45
AppendMethod · 0.45
GetStringMethod · 0.45
AppendNullMethod · 0.45
FinishMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected