mapleFU commented on code in PR #37171:
URL: https://github.com/apache/arrow/pull/37171#discussion_r1302430191


##########
cpp/src/arrow/record_batch.cc:
##########
@@ -283,6 +283,25 @@ bool RecordBatch::ApproxEquals(const RecordBatch& other, 
const EqualOptions& opt
   return true;
 }
 
+Status RecordBatch::RewriteSchema(std::shared_ptr<Schema> schema) {
+  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();

Review Comment:
   If the `schema` contains nested field, the equal would still compare the 
name?



##########
cpp/src/arrow/record_batch.cc:
##########
@@ -283,6 +283,25 @@ bool RecordBatch::ApproxEquals(const RecordBatch& other, 
const EqualOptions& opt
   return true;
 }
 
+Status RecordBatch::RewriteSchema(std::shared_ptr<Schema> schema) {

Review Comment:
   So, this is used as:
   
   ```c++
   auto schema = recordBatch->GetSchema();
   auto new_schema = schema->WithNames(new_names).ValueOrDie(); 
   recordBatch->RewriteSchema(new_schema);
   ```
   
   ?
   
   Personally I think `RecordBatch` is immutable. Maybe 
`Result<std::shared_ptr<RecordBatch>> 
RecordBatch::RewriteSchema(std::shared_ptr<Schema> schema) const` is better



-- 
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]

Reply via email to