cpcloud commented on a change in pull request #11466:
URL: https://github.com/apache/arrow/pull/11466#discussion_r741531355



##########
File path: cpp/src/arrow/array/array_nested.cc
##########
@@ -541,56 +541,62 @@ std::shared_ptr<Array> StructArray::GetFieldByName(const 
std::string& name) cons
 
 Result<ArrayVector> StructArray::Flatten(MemoryPool* pool) const {
   ArrayVector flattened;
-  flattened.reserve(data_->child_data.size());
+  flattened.resize(data_->child_data.size());
   std::shared_ptr<Buffer> null_bitmap = data_->buffers[0];
 
-  for (const auto& child_data_ptr : data_->child_data) {
-    auto child_data = child_data_ptr->Copy();
+  for (int i = 0; static_cast<size_t>(i) < data_->child_data.size(); i++) {
+    ARROW_ASSIGN_OR_RAISE(flattened[i], Flatten(i, pool));
+  }
 
-    std::shared_ptr<Buffer> flattened_null_bitmap;
-    int64_t flattened_null_count = kUnknownNullCount;
+  return flattened;
+}
 
-    // Need to adjust for parent offset
-    if (data_->offset != 0 || data_->length != child_data->length) {
-      child_data = child_data->Slice(data_->offset, data_->length);
-    }
-    std::shared_ptr<Buffer> child_null_bitmap = child_data->buffers[0];
-    const int64_t child_offset = child_data->offset;
-
-    // The validity of a flattened datum is the logical AND of the struct
-    // element's validity and the individual field element's validity.
-    if (null_bitmap && child_null_bitmap) {
-      ARROW_ASSIGN_OR_RAISE(
-          flattened_null_bitmap,
-          BitmapAnd(pool, child_null_bitmap->data(), child_offset, 
null_bitmap_data_,
-                    data_->offset, data_->length, child_offset));
-    } else if (child_null_bitmap) {
-      flattened_null_bitmap = child_null_bitmap;
-      flattened_null_count = child_data->null_count;
-    } else if (null_bitmap) {
-      if (child_offset == data_->offset) {
-        flattened_null_bitmap = null_bitmap;
-      } else {
-        // If the child has an offset, need to synthesize a validity
-        // buffer with an offset too
-        ARROW_ASSIGN_OR_RAISE(flattened_null_bitmap,
-                              AllocateEmptyBitmap(child_offset + 
data_->length, pool));
-        CopyBitmap(null_bitmap_data_, data_->offset, data_->length,
-                   flattened_null_bitmap->mutable_data(), child_offset);
-      }
-      flattened_null_count = data_->null_count;
-    } else {
-      flattened_null_count = 0;
-    }
+Result<std::shared_ptr<Array>> StructArray::Flatten(int index, MemoryPool* 
pool) const {
+  std::shared_ptr<Buffer> null_bitmap = data_->buffers[0];
+
+  auto child_data = data_->child_data[index]->Copy();

Review comment:
       Sweet.

##########
File path: cpp/src/arrow/compute/exec/expression.cc
##########
@@ -512,7 +511,31 @@ Result<Datum> ExecuteScalarExpression(const Expression& 
expr, const ExecBatch& i
       return MakeNullScalar(null());
     }
 
-    const Datum& field = input[param->index];
+    Datum field = input[param->indices[0]];
+    for (auto it = param->indices.begin() + 1; it != param->indices.end(); 
++it) {

Review comment:
       Ah, I missed the `+ 1`. Roger.

##########
File path: cpp/src/arrow/compute/exec/expression.h
##########
@@ -112,7 +113,7 @@ class ARROW_EXPORT Expression {
 
     // post-bind properties
     ValueDescr descr;
-    int index;
+    internal::SmallVector<int, 2> indices;

Review comment:
       Got it, thanks.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to