| 56 | } |
| 57 | |
| 58 | std::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 | |
| 96 | void BenchmarkWriteCsv(benchmark::State& state, const WriteOptions& options, |
| 97 | const RecordBatch& batch) { |
no test coverage detected