pitrou commented on a change in pull request #12055:
URL: https://github.com/apache/arrow/pull/12055#discussion_r824043140



##########
File path: cpp/src/arrow/chunk_resolver.h
##########
@@ -0,0 +1,60 @@
+// 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 <cstdint>
+#include <utility>
+#include <vector>
+
+#include "arrow/type_fwd.h"
+
+namespace arrow {
+namespace compute {

Review comment:
       This shouldn't be in the `compute` namespace at all, just 
`arrow::internal`.

##########
File path: python/pyarrow/table.pxi
##########
@@ -209,10 +209,14 @@ cdef class ChunkedArray(_PandasConvertible):
         -------
         value : Scalar (index) or ChunkedArray (slice)
         """
+        cdef shared_ptr[CScalar] c_scalar
+
         if isinstance(key, slice):
             return _normalize_slice(self, key)
 
-        return self.getitem(_normalize_index(key, self.chunked_array.length()))
+        c_scalar = GetResultValue(self.chunked_array.GetScalar(
+            _normalize_index(key, self.chunked_array.length())))
+        return Scalar.wrap(<shared_ptr[CScalar]> c_scalar)

Review comment:
       I'm curious, why do you need the cast to `shared_ptr[CScalar]`?

##########
File path: cpp/src/arrow/chunk_resolver.h
##########
@@ -0,0 +1,60 @@
+// 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 <cstdint>
+#include <utility>
+#include <vector>
+
+#include "arrow/type_fwd.h"
+
+namespace arrow {
+namespace compute {
+namespace internal {
+
+struct ChunkLocation {
+  int64_t chunk_index, index_in_chunk;
+};
+
+// An object that resolves an array chunk depending on the index.
+struct ChunkResolver {
+  explicit ChunkResolver(std::vector<int64_t> lengths)
+      : num_chunks_(static_cast<int64_t>(lengths.size())),
+        offsets_(MakeEndOffsets(std::move(lengths))),
+        cached_chunk_(0) {}
+
+  ChunkLocation Resolve(int64_t index) const;

Review comment:
       The fast path (cache hit) should probably be inline in this header file, 
for potentially better performance.




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