Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Go] Expose number of fields in schema #36384

Closed
thorfour opened this issue Jun 29, 2023 · 0 comments · Fixed by #36365
Closed

[Go] Expose number of fields in schema #36384

thorfour opened this issue Jun 29, 2023 · 0 comments · Fixed by #36365

Comments

@thorfour
Copy link
Contributor

Describe the enhancement requested

Previously if one wanted to iterate over the fields in the schema you would call the Fields() function and just iterate over the slice. However, due to this commit there is now an allocation and copy that happens when that's called. So to iterate over the fields without allocations one now must use the Field(i int) method; however that means a user must already know exactly how many fields are in the schema which isn't possible today.

It would be idea if there were a NumFields() int method on schemas allowing users to iterate over the fields without copying.

Component(s)

Go

@kou kou changed the title Expose number of fields in schema [Go] Expose number of fields in schema Jun 29, 2023
zeroshade pushed a commit that referenced this issue Jul 2, 2023
### Rationale for this change

Previously if one wanted to iterate over the fields in the schema you would call the `Fields()` function and just iterate over the slice. However, due to [this commit](rtpsw@802674b) there is now an allocation and copy that happens when that's called. So to iterate over the fields without allocations one now must use the `Field(i int)` method; however that means a user must already know exactly how many fields are in the schema which isn't possible today.

This adds a simple `NumFields() int` method that returns the number of fields in a schema to allow a user to iterate over all the fields without having to copy them. 

### What changes are included in this PR?

Expose the number of fields in a schema for iteration over fields.

Single function added `NumFields() int` to schema

### Are these changes tested?

N/A

### Are there any user-facing changes?

Yes this is a new API

* Closes: #36384

Authored-by: thorfour <me@thor-hansen.com>
Signed-off-by: Matt Topol <zotthewizard@gmail.com>
@zeroshade zeroshade added this to the 13.0.0 milestone Jul 2, 2023
westonpace pushed a commit to westonpace/arrow that referenced this issue Jul 7, 2023
### Rationale for this change

Previously if one wanted to iterate over the fields in the schema you would call the `Fields()` function and just iterate over the slice. However, due to [this commit](rtpsw@802674b) there is now an allocation and copy that happens when that's called. So to iterate over the fields without allocations one now must use the `Field(i int)` method; however that means a user must already know exactly how many fields are in the schema which isn't possible today.

This adds a simple `NumFields() int` method that returns the number of fields in a schema to allow a user to iterate over all the fields without having to copy them. 

### What changes are included in this PR?

Expose the number of fields in a schema for iteration over fields.

Single function added `NumFields() int` to schema

### Are these changes tested?

N/A

### Are there any user-facing changes?

Yes this is a new API

* Closes: apache#36384

Authored-by: thorfour <me@thor-hansen.com>
Signed-off-by: Matt Topol <zotthewizard@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants