Skip to content

ARROW-6284: [C++] Allow references in std::tuple when converting tuple to arrow array#5112

Closed
ozars wants to merge 3 commits intoapache:masterfrom
ozars:stl-ref
Closed

ARROW-6284: [C++] Allow references in std::tuple when converting tuple to arrow array#5112
ozars wants to merge 3 commits intoapache:masterfrom
ozars:stl-ref

Conversation

@ozars
Copy link
Copy Markdown

@ozars ozars commented Aug 17, 2019

Currently std::vector<std::tuple> can be converted to a table by treating each tuple as a row and by building arrays corresponding to each element of the tuple. This PR allows reference types (and const reference types) in elements of std::tuple which is to be converted. This is useful for converting user defined types. For example a vector of CustomType:

struct CustomType {
  int8_t i8;
  uint64_t u64;
  bool b;
  std::string s;

  auto tie() const {
    return std::tie(i8, u64, b, s);
  }
};

can be converted to a table like this:

using boost::adaptors::transform;

std::vector<CustomType> rows();
std::shared_ptr<Table> table;
auto rng_rows =
  transform(rows(), [](const CustomType& c) { return c.tie(); });
TableFromTupleRange(default_memory_pool(), rng_rows, names, &table);

This makes it easier to convert user defined types to arrow tables.

@ozars ozars changed the title ARROW-6284: Allow references in std::tuple when converting tuple to arrow array ARROW-6284: [C++] Allow references in std::tuple when converting tuple to arrow array Aug 17, 2019
@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #5112 into master will increase coverage by 1.58%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5112      +/-   ##
==========================================
+ Coverage   87.64%   89.22%   +1.58%     
==========================================
  Files        1014      731     -283     
  Lines      145922   104999   -40923     
  Branches     1437        0    -1437     
==========================================
- Hits       127887    93690   -34197     
+ Misses      17673    11309    -6364     
+ Partials      362        0     -362
Impacted Files Coverage Δ
cpp/src/arrow/stl.h 100% <ø> (ø) ⬆️
cpp/src/arrow/stl-test.cc 100% <100%> (ø) ⬆️
cpp/src/arrow/util/thread-pool-test.cc 97.66% <0%> (-0.94%) ⬇️
python/pyarrow/tests/test_parquet.py 96.38% <0%> (-0.07%) ⬇️
js/src/util/fn.ts
go/arrow/memory/memory_avx2_amd64.go
rust/datafusion/src/execution/filter.rs
rust/arrow/src/csv/writer.rs
rust/datafusion/src/bin/main.rs
go/arrow/ipc/file_reader.go
... and 277 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2ba0566...6376d10. Read the comment docs.

Copy link
Copy Markdown
Contributor

@fsaintjacques fsaintjacques left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants