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

[C++] Add a struct_ overload taking a vector of (name, type) pairs #36867

Closed
pitrou opened this issue Jul 25, 2023 · 4 comments · Fixed by #36915
Closed

[C++] Add a struct_ overload taking a vector of (name, type) pairs #36867

pitrou opened this issue Jul 25, 2023 · 4 comments · Fixed by #36915

Comments

@pitrou
Copy link
Member

pitrou commented Jul 25, 2023

Describe the enhancement requested

It would be nice to be able to write:

 struct_({{"a", int8()}, {"b", utf8()}});

instead of:

 struct_({field("a", int8()), field("b", utf8())});

Same with the schema factory.

Component(s)

C++

@jsjtxietian
Copy link
Contributor

jsjtxietian commented Jul 25, 2023

I can take this issue if no one has started working on it yet.

@pitrou
Copy link
Member Author

pitrou commented Jul 25, 2023

@jsjtxietian Yes, you can submit a PR if you want.

@jsjtxietian
Copy link
Contributor

jsjtxietian commented Jul 26, 2023

@pitrou Hi,I have a question regarding this issue and I want to ask for your advice.

In this code, because field is a function with default parameters, one can pass not only name and type to this function, but also nullable and metadata
struct_({field("a", int8()), field("b", utf8())});

but in the following form, I can use std::initializer_list<std::pair<std::string, std::shared_ptr>> as the input parameter, but in this way it's hard to add support for passing in nullable and metadata conveniently like the field function. std::tuple doesn't support default parameters too.
struct_({{"a", int8()}, {"b", utf8()}});

I guess there is a better way to write this overload function or shall we just support (name, type) pairs for now?
Thanks for your time.

@pitrou
Copy link
Member Author

pitrou commented Jul 26, 2023

hi @jsjtxietian

I guess there is a better way to write this overload function or shall we just support (name, type) pairs for now?

We can just support (name, type) pairs since that's the common case anyway.

pitrou pushed a commit that referenced this issue Aug 9, 2023
…(name, type) pairs (#36915)

### Rationale for this change
Mostly for convenience. It would be nice to be able to write:
```struct_({{"a", int8()}, {"b", utf8()}});```
instead of:
```struct_({field("a", int8()), field("b", utf8())});```
Same with the schema factory.

### What changes are included in this PR?
Add a struct_ overload and two schema overload taking a vector of (name, type) pairs to construct a vector of fields.

### Are these changes tested?
Yes.

### Are there any user-facing changes?
Yes. Add three ARROW_EXPORT functions.

* Closes: #36867

Authored-by: jsjtxietian <jsjtxietian@outlook.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
@pitrou pitrou added this to the 14.0.0 milestone Aug 9, 2023
loicalleyne pushed a commit to loicalleyne/arrow that referenced this issue Nov 13, 2023
…or of (name, type) pairs (apache#36915)

### Rationale for this change
Mostly for convenience. It would be nice to be able to write:
```struct_({{"a", int8()}, {"b", utf8()}});```
instead of:
```struct_({field("a", int8()), field("b", utf8())});```
Same with the schema factory.

### What changes are included in this PR?
Add a struct_ overload and two schema overload taking a vector of (name, type) pairs to construct a vector of fields.

### Are these changes tested?
Yes.

### Are there any user-facing changes?
Yes. Add three ARROW_EXPORT functions.

* Closes: apache#36867

Authored-by: jsjtxietian <jsjtxietian@outlook.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment