[ 
https://issues.apache.org/jira/browse/ARROW-1886?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16407178#comment-16407178
 ] 

ASF GitHub Bot commented on ARROW-1886:
---------------------------------------

cpcloud 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_r175940858
 
 

 ##########
 File path: cpp/src/arrow/table.cc
 ##########
 @@ -127,6 +127,38 @@ std::shared_ptr<ChunkedArray> ChunkedArray::Slice(int64_t 
offset) const {
   return Slice(offset, length_);
 }
 
+Status ChunkedArray::Flatten(MemoryPool* pool,
+                             std::vector<std::shared_ptr<ChunkedArray>>* out) 
const {
+  std::vector<std::shared_ptr<ChunkedArray>> flattened;
+  if (type()->id() != Type::STRUCT) {
+    // Emulate non-existent copy constructor
+    flattened.emplace_back(std::make_shared<ChunkedArray>(chunks_));
+    *out = flattened;
+    return Status::OK();
+  }
+  std::vector<ArrayVector> flattened_chunks;
+  for (const auto& chunk : chunks_) {
+    ArrayVector res;
+    RETURN_NOT_OK(dynamic_cast<const StructArray&>(*chunk).Flatten(pool, 
&res));
 
 Review comment:
   This can be turned into a `static_cast`

----------------------------------------------------------------
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)

Reply via email to