Skip to content

Conversation

@yashwantbezawada
Copy link

@yashwantbezawada yashwantbezawada commented Dec 27, 2025

Rationale for this change

Table.rename_columns() was dropping schema metadata, which is unexpected behavior. When you rename columns, you'd expect everything else about the schema to stay the same - including any metadata attached to it.

I noticed RecordBatch.rename_columns() and Schema.WithNames() had the same problem, so I fixed those too.

What changes are included in this PR?

The issue was that these methods were calling ::arrow::schema(fields) without passing along the original metadata. The fix just adds schema()->metadata() as the second argument, same pattern that SelectColumns() and Flatten() already use.

Files changed:

  • cpp/src/arrow/table.cc - fix for Table::RenameColumns
  • cpp/src/arrow/record_batch.cc - fix for RecordBatch::RenameColumns
  • cpp/src/arrow/type.cc - fix for Schema::WithNames
  • Added tests in the corresponding test files
  • Added a Python test covering both Table and RecordBatch

Are these changes tested?

Yes, added tests for each fix:

  • C++ test for Table in table_test.cc
  • C++ test for RecordBatch in record_batch_test.cc
  • C++ test for Schema in type_test.cc
  • Python test in test_table.py (covers both Table and RecordBatch)

Are there any user-facing changes?

Yes, this is a bug fix. After this change, rename_columns() will preserve schema metadata instead of dropping it.

Both `Table::RenameColumns()` and `RecordBatch::RenameColumns()` were
dropping schema metadata when creating the renamed table/batch. This
also affected `Schema::WithNames()` which had the same issue.

The fix passes `schema()->metadata()` when constructing the new schema,
following the same pattern used by `SelectColumns()` and `Flatten()`.

Changes:
- Fix `Table::RenameColumns()` in table.cc
- Fix `RecordBatch::RenameColumns()` in record_batch.cc
- Fix `Schema::WithNames()` in type.cc
- Add C++ tests for all three fixes
- Add Python test for Table and RecordBatch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant