troels commented on a change in pull request #8178:
URL: https://github.com/apache/arrow/pull/8178#discussion_r489772747
##########
File path: cpp/src/arrow/table_builder.cc
##########
@@ -62,7 +62,21 @@ Status RecordBatchBuilder::Flush(bool reset_builders,
}
length = fields[i]->length();
}
- *batch = RecordBatch::Make(schema_, length, std::move(fields));
+
+ // For certain types like dictionaries, types may not be fully
+ // determined before we have flushed. Make sure that the RecordBatch
+ // gets the correct types in schema.
+ // See: #ARROW-9969
+ std::shared_ptr<Schema> schema(schema_);
+ std::vector<std::shared_ptr<Field>> schema_fields(schema->fields());
+ for (int i = 0; i < this->num_fields(); ++i) {
+ if (!schema_fields[i]->type()->Equals(fields[i]->type())) {
+ std::shared_ptr<Field>
new_type(schema_fields[i]->WithType(fields[i]->type()));
+ ARROW_ASSIGN_OR_RAISE(schema, schema->SetField(i, new_type));
+ }
+ }
Review comment:
Hi @pitrou
I've changed the logic to what you suggested, just building a vector of
fields to use for creating a new schema.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]