You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/13 13:56:01 UTC

[GitHub] [arrow] pitrou commented on a diff in pull request #12055: ARROW-11989: [C++][Python] Improve ChunkedArray's complexity for the access of elements

pitrou commented on code in PR #12055:
URL: https://github.com/apache/arrow/pull/12055#discussion_r849504481


##########
cpp/src/arrow/chunk_resolver.h:
##########
@@ -0,0 +1,93 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <atomic>
+#include <cstdint>
+#include <vector>
+
+#include "arrow/type_fwd.h"
+#include "arrow/util/macros.h"
+
+namespace arrow {
+namespace internal {
+
+struct ChunkLocation {
+  int64_t chunk_index, index_in_chunk;
+};
+
+// An object that resolves an array chunk depending on the index
+struct ChunkResolver {
+  ChunkResolver(const ChunkResolver& chunks);

Review Comment:
   If a copy constructor is needed, can we add a move constructor as well?



##########
cpp/src/arrow/chunked_array.cc:
##########
@@ -44,18 +45,20 @@ class MemoryPool;
 
 ChunkedArray::ChunkedArray(ArrayVector chunks, std::shared_ptr<DataType> type)
     : chunks_(std::move(chunks)), type_(std::move(type)) {
-  length_ = 0;
-  null_count_ = 0;
-
   if (type_ == nullptr) {
     ARROW_CHECK_GT(chunks_.size(), 0)
         << "cannot construct ChunkedArray from empty vector and omitted type";
     type_ = chunks_[0]->type();
   }
+
+  length_ = 0;
+  null_count_ = 0;

Review Comment:
   Can we simply move those to the attribute initialization list above?



##########
cpp/src/arrow/chunked_array.h:
##########
@@ -182,6 +183,7 @@ class ARROW_EXPORT ChunkedArray {
   std::shared_ptr<DataType> type_;
 
  private:
+  std::unique_ptr<internal::ChunkResolver> chunk_resolver_;

Review Comment:
   Is this useful for this to be dynamically allocated, since the constructor always initializes it? If this is so as to defer initialization, this could use `util::optional` instead (but `ChunkResolver` could simply have a default constructor).



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org