@@ -31,30 +31,35 @@ FieldDescriptorPtr Annotator::CheckAndAddInputFieldDescriptor(FieldPtr field) {
3131 return found->second ;
3232 }
3333
34- auto desc = MakeDesc (field);
34+ auto desc = MakeDesc (field, false /* is_output */ );
3535 in_name_to_desc_[field->name ()] = desc;
3636 return desc;
3737}
3838
3939FieldDescriptorPtr Annotator::AddOutputFieldDescriptor (FieldPtr field) {
40- auto desc = MakeDesc (field);
40+ auto desc = MakeDesc (field, true /* is_output */ );
4141 out_descs_.push_back (desc);
4242 return desc;
4343}
4444
45- FieldDescriptorPtr Annotator::MakeDesc (FieldPtr field) {
45+ FieldDescriptorPtr Annotator::MakeDesc (FieldPtr field, bool is_output ) {
4646 int data_idx = buffer_count_++;
4747 int validity_idx = buffer_count_++;
4848 int offsets_idx = FieldDescriptor::kInvalidIdx ;
4949 if (arrow::is_binary_like (field->type ()->id ())) {
5050 offsets_idx = buffer_count_++;
5151 }
52- return std::make_shared<FieldDescriptor>(field, data_idx, validity_idx, offsets_idx);
52+ int data_buffer_ptr_idx = FieldDescriptor::kInvalidIdx ;
53+ if (is_output) {
54+ data_buffer_ptr_idx = buffer_count_++;
55+ }
56+ return std::make_shared<FieldDescriptor>(field, data_idx, validity_idx, offsets_idx,
57+ data_buffer_ptr_idx);
5358}
5459
5560void Annotator::PrepareBuffersForField (const FieldDescriptor& desc,
5661 const arrow::ArrayData& array_data,
57- EvalBatch* eval_batch) {
62+ EvalBatch* eval_batch, bool is_output ) {
5863 int buffer_idx = 0 ;
5964
6065 // The validity buffer is optional. Use nullptr if it does not have one.
@@ -74,7 +79,12 @@ void Annotator::PrepareBuffersForField(const FieldDescriptor& desc,
7479
7580 uint8_t * data_buf = const_cast <uint8_t *>(array_data.buffers [buffer_idx]->data ());
7681 eval_batch->SetBuffer (desc.data_idx (), data_buf);
77- ++buffer_idx;
82+ if (is_output) {
83+ // pass in the Buffer object for output data buffers. Can be used for resizing.
84+ uint8_t * data_buf_ptr =
85+ reinterpret_cast <uint8_t *>(array_data.buffers [buffer_idx].get ());
86+ eval_batch->SetBuffer (desc.data_buffer_ptr_idx (), data_buf_ptr);
87+ }
7888}
7989
8090EvalBatchPtr Annotator::PrepareEvalBatch (const arrow::RecordBatch& record_batch,
@@ -92,14 +102,14 @@ EvalBatchPtr Annotator::PrepareEvalBatch(const arrow::RecordBatch& record_batch,
92102 }
93103
94104 PrepareBuffersForField (*(found->second ), *(record_batch.column (i))->data (),
95- eval_batch.get ());
105+ eval_batch.get (), false /* is_output */ );
96106 }
97107
98108 // Fill in the entries for the output fields.
99109 int idx = 0 ;
100110 for (auto & arraydata : out_vector) {
101111 const FieldDescriptorPtr& desc = out_descs_.at (idx);
102- PrepareBuffersForField (*desc, *arraydata, eval_batch.get ());
112+ PrepareBuffersForField (*desc, *arraydata, eval_batch.get (), true /* is_output */ );
103113 ++idx;
104114 }
105115 return eval_batch;
0 commit comments