ZhangHuiGui commented on code in PR #41092:
URL: https://github.com/apache/arrow/pull/41092#discussion_r1560380435


##########
cpp/src/arrow/array/array_nested.cc:
##########
@@ -469,6 +469,69 @@ inline void SetListData(VarLengthListLikeArray<TYPE>* self,
   self->values_ = MakeArray(self->data_->child_data[0]);
 }
 
+Result<std::shared_ptr<Array>> FlattenLogicalListRecursively(const Array& 
array,
+                                                             MemoryPool* 
memory_pool) {
+  Type::type kind = array.type_id();
+  std::shared_ptr<Array> in_array = array.Slice(0, array.length());
+  while (is_list_like(kind) || is_list_view(kind)) {
+    const bool has_nulls = array.null_count() > 0;
+    std::shared_ptr<Array> out;
+    switch (kind) {
+      case Type::LIST: {
+        ARROW_ASSIGN_OR_RAISE(
+            out,
+            FlattenListArray(checked_cast<const ListArray&>(*in_array), 
memory_pool));
+        break;
+      }
+      case Type::LARGE_LIST: {
+        ARROW_ASSIGN_OR_RAISE(
+            out, FlattenListArray(checked_cast<const 
LargeListArray&>(*in_array),
+                                  memory_pool));
+        break;
+      }
+      case Type::FIXED_SIZE_LIST: {
+        ARROW_ASSIGN_OR_RAISE(
+            out, FlattenListArray(checked_cast<const 
FixedSizeListArray&>(*in_array),
+                                  memory_pool));
+        break;
+      }
+      case Type::LIST_VIEW: {
+        if (has_nulls) {
+          ARROW_ASSIGN_OR_RAISE(
+              out, (FlattenListViewArray<ListViewArray, true>(
+                       checked_cast<const ListViewArray&>(*in_array), 
memory_pool)));
+          break;
+        } else {
+          ARROW_ASSIGN_OR_RAISE(
+              out, (FlattenListViewArray<ListViewArray, false>(
+                       checked_cast<const ListViewArray&>(*in_array), 
memory_pool)));
+          break;
+        }
+      }
+      case Type::LARGE_LIST_VIEW: {
+        if (has_nulls) {
+          ARROW_ASSIGN_OR_RAISE(
+              out, (FlattenListViewArray<LargeListViewArray, true>(
+                       checked_cast<const LargeListViewArray&>(*in_array), 
memory_pool)));
+          break;
+        } else {
+          ARROW_ASSIGN_OR_RAISE(
+              out, (FlattenListViewArray<LargeListViewArray, false>(
+                       checked_cast<const LargeListViewArray&>(*in_array), 
memory_pool)));
+          break;
+        }
+      }
+      default:
+        return Status::Invalid("Unknown or unsupported arrow nested type: ",
+                               in_array->type()->ToString());
+    }
+
+    in_array = out;
+    kind = in_array->type_id();
+  }
+  return std::move(in_array);

Review Comment:
   Thank you so much for this!



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