[ https://issues.apache.org/jira/browse/ARROW-1886?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16407658#comment-16407658 ]
ASF GitHub Bot commented on ARROW-1886: --------------------------------------- pitrou commented on a change in pull request #1768: ARROW-1886: [C++/Python] Flatten struct columns in table URL: https://github.com/apache/arrow/pull/1768#discussion_r176018968 ########## File path: cpp/src/arrow/util/bit-util-test.cc ########## @@ -41,6 +44,59 @@ static void EnsureCpuInfoInitialized() { } } +void WriteVectorToWriter(internal::BitmapWriter& writer, const std::vector<int> values) { + for (const auto& value : values) { + if (value) { + writer.Set(); + } else { + writer.Clear(); + } + writer.Next(); + } + writer.Finish(); +} + +void BitmapFromVector(const std::vector<int>& values, int64_t bit_offset, + std::shared_ptr<Buffer>* out_buffer, int64_t* out_length) { + const int64_t length = values.size(); + *out_length = length; + ASSERT_OK(GetEmptyBitmap(default_memory_pool(), length + bit_offset, out_buffer)); + auto writer = internal::BitmapWriter((*out_buffer)->mutable_data(), bit_offset, length); + WriteVectorToWriter(writer, values); +} + +#define ASSERT_READER_SET(reader) \ + do { \ + ASSERT_TRUE(reader.IsSet()); \ + ASSERT_FALSE(reader.IsNotSet()); \ + reader.Next(); \ + } while (0) + +#define ASSERT_READER_NOT_SET(reader) \ + do { \ + ASSERT_FALSE(reader.IsSet()); \ + ASSERT_TRUE(reader.IsNotSet()); \ + reader.Next(); \ + } while (0) + +// Assert that a BitmapReader yields the given bit values +void ASSERT_READER_VALUES(internal::BitmapReader& reader, std::vector<int> values) { + for (const auto& value : values) { + if (value) { + ASSERT_READER_SET(reader); + } else { + ASSERT_READER_NOT_SET(reader); + } + } +} + +// Assert equal contents of a memory area and a vector of bytes +void ASSERT_BYTES_EQ(const uint8_t* left, const std::vector<uint8_t>& right) { + // No direct conversion from (T*, size) to vector<T> Review comment: Hmm... you may be right, I'll give it a try. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > [Python] Add function to "flatten" structs within tables > -------------------------------------------------------- > > Key: ARROW-1886 > URL: https://issues.apache.org/jira/browse/ARROW-1886 > Project: Apache Arrow > Issue Type: Improvement > Components: Python > Reporter: Wes McKinney > Assignee: Antoine Pitrou > Priority: Major > Labels: pull-request-available > Fix For: 0.10.0 > > > See discussion in https://issues.apache.org/jira/browse/ARROW-1873 > When a user has a struct column, it may be more efficient to flatten the > struct into multiple columns of the form {{struct_name.field_name}} for each > field in the struct. Then when you call {{to_pandas}}, Python dictionaries do > not have to be created, and the conversion will be much more efficient -- This message was sent by Atlassian JIRA (v7.6.3#76005)