| 51 | } |
| 52 | |
| 53 | Result<std::shared_ptr<RecordBatch>> RecordBatchBuilder::Flush(bool reset_builders) { |
| 54 | std::vector<std::shared_ptr<Array>> fields; |
| 55 | fields.resize(this->num_fields()); |
| 56 | |
| 57 | int64_t length = 0; |
| 58 | for (int i = 0; i < this->num_fields(); ++i) { |
| 59 | RETURN_NOT_OK(raw_field_builders_[i]->Finish(&fields[i])); |
| 60 | if (i > 0 && fields[i]->length() != length) { |
| 61 | return Status::Invalid("All fields must be same length when calling Flush"); |
| 62 | } |
| 63 | length = fields[i]->length(); |
| 64 | } |
| 65 | |
| 66 | // For certain types like dictionaries, types may not be fully |
| 67 | // determined before we have flushed. Make sure that the RecordBatch |
| 68 | // gets the correct types in schema. |
| 69 | // See: #ARROW-9969 |
| 70 | std::vector<std::shared_ptr<Field>> schema_fields(schema_->fields()); |
| 71 | for (int i = 0; i < this->num_fields(); ++i) { |
| 72 | if (!schema_fields[i]->type()->Equals(fields[i]->type())) { |
| 73 | schema_fields[i] = schema_fields[i]->WithType(fields[i]->type()); |
| 74 | } |
| 75 | } |
| 76 | std::shared_ptr<Schema> schema = |
| 77 | std::make_shared<Schema>(std::move(schema_fields), schema_->metadata()); |
| 78 | |
| 79 | std::shared_ptr<RecordBatch> batch = |
| 80 | RecordBatch::Make(std::move(schema), length, std::move(fields)); |
| 81 | |
| 82 | if (reset_builders) { |
| 83 | ARROW_RETURN_NOT_OK(InitBuilders()); |
| 84 | } |
| 85 | |
| 86 | return batch; |
| 87 | } |
| 88 | |
| 89 | Result<std::shared_ptr<RecordBatch>> RecordBatchBuilder::Flush() { return Flush(true); } |
| 90 |
nothing calls this directly
no test coverage detected