Skip to content

GH-36867: [C++] Add a struct_ and schema overload taking a vector of (name, type) pairs - #36915

Merged
pitrou merged 6 commits into
apache:mainfrom
jsjtxietian:gh-36867-add-struct_-overload-taking-a-vector-of-name-type-pairs
Aug 9, 2023
Merged

pitrou merged 6 commits into
apache:mainfrom
jsjtxietian:gh-36867-add-struct_-overload-taking-a-vector-of-name-type-pairs

Conversation

@jsjtxietian

@jsjtxietian jsjtxietian commented Jul 27, 2023 •

Copy link
Copy Markdown
Contributor

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.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #36867 has been automatically assigned in GitHub to PR creator.

@jsjtxietian
jsjtxietian force-pushed the gh-36867-add-struct_-overload-taking-a-vector-of-name-type-pairs branch from 6bf4506 to f396384 Compare July 27, 2023 16:40
@mapleFU

mapleFU commented Jul 28, 2023

Copy link
Copy Markdown
Member
C:\projects\arrow\cpp\build\src\arrow\engine\CMakeFiles\arrow_substrait_shared.dir\Unity\unity_1_cxx.cxx
C:/projects/arrow/cpp/src/arrow/engine/substrait/type_internal.cc(80): error C2672: 'arrow::Result<arrow::FieldVector>::Map': no matching overloaded function found
C:/projects/arrow/cpp/src/arrow/engine/substrait/type_internal.cc(164): note: see reference to function template instantiation 'arrow::Result<arrow::FieldVector> arrow::engine::`anonymous-namespace'::FieldsFromProto<google::protobuf::RepeatedPtrField<substrait::Type>,arrow::engine::FromProto::<lambda_998f5b636b6257cbec583f504695a06c>>(int,const Types &,const NextName &,const arrow::engine::ExtensionSet &,const arrow::engine::ConversionOptions &)' being compiled
        with
        [
            Types=google::protobuf::RepeatedPtrField<substrait::Type>,
            NextName=arrow::engine::FromProto::<lambda_998f5b636b6257cbec583f504695a06c>
        ]
C:/projects/arrow/cpp/src/arrow/engine/substrait/type_internal.cc(80): error C2783: 'EnsureResult<unknown-type>::type arrow::Result<arrow::FieldVector>::Map(M &&) const &': could not deduce template argument for 'M'
C:\projects\arrow\cpp\src\arrow/result.h(392): note: see declaration of 'arrow::Result<arrow::FieldVector>::Map'
C:/projects/arrow/cpp/src/arrow/engine/substrait/type_internal.cc(80): error C2783: 'EnsureResult<unknown-type>::type arrow::Result<arrow::FieldVector>::Map(M &&) &&': could not deduce template argument for 'M'
C:\projects\arrow\cpp\src\arrow/result.h(380): note: see declaration of 'arrow::Result<arrow::FieldVector>::Map'
C:/projects/arrow/cpp/src/arrow/engine/substrait/type_internal.cc(80): error C2530: '_error_or_value20': references must be initialized
C:/projects/arrow/cpp/src/arrow/engine/substrait/type_internal.cc(80): error C3536: '_error_or_value20': cannot be used before it is initialized

Would you mind fix lint first?

Comment thread cpp/src/arrow/type.cc Resolved
Comment thread cpp/src/arrow/type.cc Resolved
@jsjtxietian

Copy link
Copy Markdown
Contributor Author

ok, will take a look

@jsjtxietian
jsjtxietian force-pushed the gh-36867-add-struct_-overload-taking-a-vector-of-name-type-pairs branch 2 times, most recently from 2e34a9a to e8f73c4 Compare July 31, 2023 11:25

@mapleFU mapleFU left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks ok to me. @bkietz @pitrou would you mind take a look?

@bkietz bkietz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this!

Comment thread cpp/src/arrow/type_fwd.h Resolved
Comment thread cpp/src/arrow/type.cc Resolved
@jsjtxietian
jsjtxietian force-pushed the gh-36867-add-struct_-overload-taking-a-vector-of-name-type-pairs branch from e8f73c4 to c884f85 Compare August 3, 2023 09:56
Comment thread cpp/src/arrow/type_fwd.h Resolved
@jsjtxietian
jsjtxietian force-pushed the gh-36867-add-struct_-overload-taking-a-vector-of-name-type-pairs branch from c884f85 to 6736aa7 Compare August 4, 2023 03:15
@jsjtxietian
jsjtxietian force-pushed the gh-36867-add-struct_-overload-taking-a-vector-of-name-type-pairs branch from 6736aa7 to 87ea858 Compare August 4, 2023 04:23

@bkietz bkietz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @jsjtxietian ! A couple more comments, mostly on the documentation side.

Comment thread cpp/src/arrow/type_fwd.h Resolved
Comment thread cpp/src/arrow/type_fwd.h Resolved
Comment thread cpp/src/arrow/type_fwd.h Resolved
Comment thread cpp/src/arrow/type_fwd.h Resolved
Comment thread cpp/src/arrow/type_fwd.h Resolved
Comment thread cpp/src/arrow/type.cc Resolved
Comment thread cpp/src/arrow/type.cc Resolved
Comment thread cpp/src/parquet/arrow/schema.cc Resolved
@jsjtxietian
jsjtxietian force-pushed the gh-36867-add-struct_-overload-taking-a-vector-of-name-type-pairs branch from 87ea858 to 107b5e7 Compare August 9, 2023 09:44
@jsjtxietian

Copy link
Copy Markdown
Contributor Author

Thank you very much for all your help!

@pitrou

pitrou commented Aug 9, 2023

Copy link
Copy Markdown
Member

CI failures are unrelated, will merge.

@pitrou
pitrou merged commit d3ccc83 into apache:main Aug 9, 2023
@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit d3ccc83.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about possible false positives for unstable benchmarks that are known to sometimes produce them.

loicalleyne pushed a commit to loicalleyne/arrow that referenced this pull request 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 <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
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.

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

4 participants