benibus commented on code in PR #35197: URL: https://github.com/apache/arrow/pull/35197#discussion_r1194117861
########## cpp/src/arrow/type.h: ########## @@ -1698,10 +1698,45 @@ class ARROW_EXPORT FieldPath { /// \brief Retrieve the referenced child from a ChunkedArray Result<std::shared_ptr<ChunkedArray>> Get(const ChunkedArray& chunked_array) const; + /// \brief Retrieve the referenced child/column from an Array, ArrayData, ChunkedArray, + /// RecordBatch, or Table + /// + /// Unlike `FieldPath::Get`, these variants are not zero-copy and the retrieved child's + /// null bitmap is ANDed with its parent's + Result<std::shared_ptr<Array>> GetFlattened(const Array& array, + MemoryPool* pool = NULLPTR) const; + Result<std::shared_ptr<ArrayData>> GetFlattened(const ArrayData& data, + MemoryPool* pool = NULLPTR) const; + Result<std::shared_ptr<ChunkedArray>> GetFlattened(const ChunkedArray& chunked_array, + MemoryPool* pool = NULLPTR) const; + Result<std::shared_ptr<Array>> GetFlattened(const RecordBatch& batch, + MemoryPool* pool = NULLPTR) const; + Result<std::shared_ptr<ChunkedArray>> GetFlattened(const Table& table, + MemoryPool* pool = NULLPTR) const; + private: std::vector<int> indices_; }; +namespace internal { + +template <typename T> +using FieldPathGetType = + decltype(std::declval<FieldPath>().Get(std::declval<T>()).ValueOrDie()); + +template <bool Flattened, typename T> +std::enable_if_t<!Flattened, Result<FieldPathGetType<T>>> GetChild( + const T& root, const FieldPath& path, MemoryPool* = NULLPTR) { + return path.Get(root); +} +template <bool Flattened, typename T> +std::enable_if_t<Flattened, Result<FieldPathGetType<T>>> GetChild( + const T& root, const FieldPath& path, MemoryPool* pool = NULLPTR) { + return path.GetFlattened(root, pool); +} Review Comment: Yeah, unfortunately `if constexpr` wouldn't work here since `GetFlattened` doesn't have overloads for `Schema`, `Field`, etc. But I'm fine with just duplicating the definitions as well (in that case, the helpers probably wouldn't be too useful outside of the tests so no need to expose them). -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org