You can also use the `Field.prototype.clone()` method[1] like this to
further reduce the boilerplate:
function renameColumn(col, new_name) {
return Column.new(col.field.clone(new_name), col.chunks);
}
1. https://github.com/apache/arrow/blob/master/js/src/schema.ts#L139-L146
On 6/26/20 7:54 AM, Brian Hulette wrote:
Hi Ryan,
Here or user@arrow.apache.orgis a fine place to ask :)
The metadata on Table/Column/Field objects are all immutable, so doing this
right now would require creating a new instance of Table with the field
renamed, which takes quite a lot of boilerplate. A helper for renaming a
column (or even better a generalization of select [1] that lets you do a
full projection, including column renames) would be a great contribution.
Here's an example of creating a renamed column, which should get you most
of the way to creating a Table with a renamed column:
https://observablehq.com/@theneuralbit/renaming-an-arrow-column
Brian
[1]
https://github.com/apache/arrow/blob/ff7ee06020949daf66ac05090753e1a17736d9fa/js/src/table.ts#L249
On Thu, Jun 25, 2020 at 4:04 PM Ryan McKinley <ryan...@gmail.com> wrote:
Apologies if this is the wrong list or place to ask...
What is the best way to update a column name for a Table in javascript?
const col = table.getColumnAt(i);
col.name = 'new name!'
Currently: Cannot assign to 'name' because it is a read-only property
Thanks!
ryan