| 2878 | }; |
| 2879 | |
| 2880 | Status ProduceCallback(size_t thread_index) { |
| 2881 | if (done_.load()) return Status::OK(); |
| 2882 | ThreadLocalData& tld = thread_local_data_[thread_index]; |
| 2883 | tld.custkey_start = rows_generated_.fetch_add(batch_size_); |
| 2884 | if (tld.custkey_start >= rows_to_generate_) return Status::OK(); |
| 2885 | |
| 2886 | tld.to_generate = std::min(batch_size_, rows_to_generate_ - tld.custkey_start); |
| 2887 | |
| 2888 | tld.batch.resize(CUSTOMER::kNumCols); |
| 2889 | std::fill(tld.batch.begin(), tld.batch.end(), Datum()); |
| 2890 | for (int col : gen_list_) RETURN_NOT_OK(kGenerators[col](thread_index)); |
| 2891 | |
| 2892 | std::vector<Datum> result(gen_list_.size()); |
| 2893 | for (size_t i = 0; i < gen_list_.size(); i++) { |
| 2894 | int col_idx = gen_list_[i]; |
| 2895 | result[i] = tld.batch[col_idx]; |
| 2896 | } |
| 2897 | ARROW_ASSIGN_OR_RAISE(ExecBatch eb, ExecBatch::Make(std::move(result))); |
| 2898 | int64_t batches_to_generate = (rows_to_generate_ + batch_size_ - 1) / batch_size_; |
| 2899 | int64_t batches_generated_before_this_one = batches_outputted_.fetch_add(1); |
| 2900 | bool is_last_batch = batches_generated_before_this_one == (batches_to_generate - 1); |
| 2901 | ARROW_RETURN_NOT_OK(output_callback_(std::move(eb))); |
| 2902 | if (is_last_batch) { |
| 2903 | bool expected = false; |
| 2904 | if (done_.compare_exchange_strong(expected, true)) |
| 2905 | ARROW_RETURN_NOT_OK(finished_callback_(batches_outputted_.load())); |
| 2906 | return Status::OK(); |
| 2907 | } |
| 2908 | return schedule_callback_( |
| 2909 | [this](size_t thread_index) { return this->ProduceCallback(thread_index); }); |
| 2910 | } |
| 2911 | |
| 2912 | Status AllocateColumn(size_t thread_index, int column) { |
| 2913 | ThreadLocalData& tld = thread_local_data_[thread_index]; |