Light-City commented on code in PR #37171:
URL: https://github.com/apache/arrow/pull/37171#discussion_r1308105021
##########
cpp/src/arrow/record_batch.cc:
##########
@@ -283,6 +283,25 @@ bool RecordBatch::ApproxEquals(const RecordBatch& other,
const EqualOptions& opt
return true;
}
+Result<std::shared_ptr<RecordBatch>> RecordBatch::RewriteSchema(
+ std::shared_ptr<Schema> schema) const {
+ if (schema_->num_fields() != schema->num_fields())
+ return Status::Invalid("RecordBatch schema fields", schema_->num_fields(),
+ ", did not match new schema fields: ",
schema->num_fields());
+ auto fields = schema_->fields();
+ int n_fields = static_cast<int>(fields.size());
+ for (int i = 0; i < n_fields; i++) {
+ auto old_type = fields[i]->type();
+ auto replace_type = schema->field(i)->type();
+ if (!old_type->Equals(replace_type)) {
+ return Status::Invalid(
+ "RecordBatch schema field index ", i, " type is ",
old_type->ToString(),
+ ", did not match new schema field type: ", replace_type->ToString());
+ }
+ }
+ return RecordBatch::Make(std::move(schema), num_rows(),
std::move(columns()));
Review Comment:
Follow the previous writing method here, refer to:
```
std::shared_ptr<RecordBatch> RecordBatch::Make(
std::shared_ptr<Schema> schema, int64_t num_rows,
std::vector<std::shared_ptr<Array>> columns) {
DCHECK_EQ(schema->num_fields(), static_cast<int>(columns.size()));
return std::make_shared<SimpleRecordBatch>(std::move(schema), num_rows,
std::move(columns));
}
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]