emkornfield commented on code in PR #14803:
URL: https://github.com/apache/arrow/pull/14803#discussion_r1040566647


##########
cpp/src/parquet/page_index.cc:
##########
@@ -0,0 +1,174 @@
+// 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.
+
+#include "parquet/page_index.h"
+#include "parquet/encoding.h"
+#include "parquet/statistics.h"
+#include "parquet/thrift_internal.h"
+
+#include <map>
+
+namespace parquet {
+
+namespace {
+
+template <typename DType>
+void Decode(std::unique_ptr<typename EncodingTraits<DType>::Decoder>& decoder,
+            const std::string& src, typename DType::c_type* dst) {
+  decoder->SetData(/*num_values=*/1, reinterpret_cast<const 
uint8_t*>(src.c_str()),
+                   static_cast<int>(src.size()));
+  decoder->Decode(dst, /*max_values=*/1);
+}
+
+template <>
+void Decode<ByteArrayType>(std::unique_ptr<ByteArrayDecoder>&, const 
std::string& src,
+                           ByteArray* dst) {
+  dst->len = static_cast<uint32_t>(src.size());
+  dst->ptr = reinterpret_cast<const uint8_t*>(src.c_str());
+}
+
+template <typename DType>
+class TypedColumnIndexImpl : public TypedColumnIndex<DType> {
+ public:
+  using T = typename DType::c_type;
+
+  TypedColumnIndexImpl(const ColumnDescriptor& descr,
+                       const format::ColumnIndex& column_index)
+      : column_index_(column_index) {
+    min_values_.reserve(column_index_.null_pages.size());
+    max_values_.reserve(column_index_.null_pages.size());
+    // Decode min and max values into a compact form (i.e. w/o null page)
+    auto plain_decoder = MakeTypedDecoder<DType>(Encoding::PLAIN, &descr);
+    T value;
+    for (size_t i = 0; i < column_index_.null_pages.size(); ++i) {
+      if (!column_index_.null_pages[i]) {
+        non_null_page_indices_.emplace_back(static_cast<int32_t>(i));
+        Decode<DType>(plain_decoder, column_index_.min_values[i], &value);
+        min_values_.emplace_back(value);
+        Decode<DType>(plain_decoder, column_index_.max_values[i], &value);
+        max_values_.emplace_back(value);
+      }
+    }
+  }
+
+  const std::vector<bool>& null_pages() const override {
+    return column_index_.null_pages;
+  }
+
+  const std::vector<std::string>& encoded_min_values() const override {
+    return column_index_.min_values;
+  }
+
+  const std::vector<std::string>& encoded_max_values() const override {
+    return column_index_.max_values;
+  }
+
+  BoundaryOrder boundary_order() const override {
+    return 
static_cast<BoundaryOrder>(static_cast<int>(column_index_.boundary_order));
+  }
+
+  bool has_null_counts() const override { return 
column_index_.__isset.null_counts; }
+
+  const std::vector<int64_t>& null_counts() const override {
+    return column_index_.null_counts;
+  }
+
+  const std::vector<T>& min_values() const override { return min_values_; }
+
+  const std::vector<T>& max_values() const override { return max_values_; }
+
+  const std::vector<int32_t> GetNonNullPageIndices() const override {
+    return non_null_page_indices_;
+  }
+
+ private:
+  /// Wrapped thrift column index.
+  const format::ColumnIndex column_index_;
+  /// Decoded typed min/max values. Null pages are set to std::nullopt.
+  std::vector<T> min_values_;
+  std::vector<T> max_values_;
+  /// A list of page indices for not-null pages.
+  std::vector<int32_t> non_null_page_indices_;
+};
+
+class OffsetIndexImpl : public OffsetIndex {
+ public:
+  explicit OffsetIndexImpl(const format::OffsetIndex& offset_index) {
+    page_locations_.reserve(offset_index.page_locations.size());
+    for (const auto& page_location : offset_index.page_locations) {

Review Comment:
   I'm a little bit concerned about the copying around vectors?  How big due we 
typically expected indexes to be?



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

Reply via email to