You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@arrow.apache.org by Ryan McKinley <ry...@gmail.com> on 2020/06/25 23:04:35 UTC

[JavaScript] how to set column name after creation?

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

Re: [JavaScript] how to set column name after creation?

Posted by Ryan McKinley <ry...@gmail.com>.
excellent thank you:

https://github.com/grafana/grafana/pull/25871/files#diff-ad1ca51923ba5a2e01652c1686ae6797R169

On Fri, Jun 26, 2020 at 7:54 AM Brian Hulette <hu...@gmail.com> 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 <ry...@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
> >
>

Re: [JavaScript] how to set column name after creation?

Posted by Paul Taylor <pt...@gmail.com>.
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 <ry...@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
>>

Re: [JavaScript] how to set column name after creation?

Posted by Brian Hulette <hu...@gmail.com>.
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 <ry...@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
>