Copilot commented on code in PR #50629:
URL: https://github.com/apache/arrow/pull/50629#discussion_r4205673333


##########
cpp/src/parquet/level_decoder_internal.h:
##########
@@ -0,0 +1,314 @@
+// 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 <sstream>
+#include <variant>
+
+#include "arrow/util/bit_util.h"
+#include "arrow/util/int_util_overflow.h"
+#include "arrow/util/logging.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/rle_bitmap_internal.h"
+#include "arrow/util/rle_encoding_internal.h"
+#include "arrow/util/ubsan.h"
+#include "parquet/exception.h"
+#include "parquet/level_comparison.h"
+#include "parquet/types.h"
+
+namespace parquet {
+
+/*******************************
+ *  PageLevelDecoder Adapters  *
+ *******************************/
+
+/// BitPackedDecoder adapter for PageLevelDecoder.
+struct LevelBitPackedDecoder : ::arrow::util::BitPackedDecoder<int16_t> {
+  using Base = BitPackedDecoder<int16_t>;
+
+  LevelBitPackedDecoder(const uint8_t* data, int32_t data_size, const auto& 
params)
+      : Base(data, data_size,
+             /* value_bit_width= */ ::arrow::bit_util::Log2(params.max_level + 
1),
+             params.value_count) {}
+
+  int32_t GetBatch(int16_t* out, int32_t batch_size, int16_t max_level);
+};
+
+/// RleBitPackedDecoder adapter for PageLevelDecoder.
+struct LevelRleBitPackedDecoder : ::arrow::util::RleBitPackedDecoder<int16_t> {
+  using Base = RleBitPackedDecoder<int16_t>;
+
+  LevelRleBitPackedDecoder(const uint8_t* data, int32_t data_size, const auto& 
params)
+      : Base(data, data_size,
+             /* value_bit_width= */ ::arrow::bit_util::Log2(params.max_level + 
1)) {}
+
+  int32_t GetBatch(int16_t* out, int32_t batch_size, int16_t max_level);
+};
+
+/**************************************
+ *  PageLevelDecoder Bitmap Adapters  *
+ **************************************/
+
+struct LevelToBitmapBitPackedDecoder : ::arrow::util::BitPackedToBitmapDecoder 
{
+  using Base = BitPackedToBitmapDecoder;
+
+  LevelToBitmapBitPackedDecoder(const uint8_t* data, int32_t data_size,
+                                const auto& params)
+      : Base(data, data_size, params.value_count) {
+    ARROW_DCHECK_EQ(params.max_level, 1);
+  }
+
+  template <typename Out>
+  int32_t GetBatch(Out&& out, int32_t batch_size, int16_t /* max_level */) {
+    return Base::GetBatch(out, batch_size);
+  }
+};
+
+struct LevelToBitmapRleBitPackedDecoder : 
::arrow::util::RleBitPackedToBitmapDecoder {
+  using Base = RleBitPackedToBitmapDecoder;
+
+  LevelToBitmapRleBitPackedDecoder(const uint8_t* data, int32_t data_size,
+                                   const auto& params)
+      : Base(data, data_size) {
+    ARROW_DCHECK_EQ(params.max_level, 1);
+  }
+
+  template <typename Out>
+  int32_t GetBatch(Out&& out, int32_t batch_size, int16_t /* max_level */) {
+    return Base::GetBatch(out, batch_size);

Review Comment:
   This optimized RLE path changes corruption handling for definition levels. 
`RleRunToBitmapDecoder::Reset` interprets any nonzero run payload as `true`, so 
a malformed bit-width-1 RLE value such as `0x02` is accepted as level 1; the 
previous `int16_t` decoder followed by `CheckLevelMinMax` rejected values above 
`max_level`. Please preserve that validation (or reject non-0/1 run payloads) 
before using this decoder for definition levels.



##########
cpp/src/parquet/column_reader.h:
##########
@@ -63,52 +63,63 @@ struct PARQUET_EXPORT DataPageStats {
   std::optional<int32_t> num_rows;
 };
 
+/// Decoder for repetition or definition level.
+///
+/// This decoder is used with either a deprecated bit packed (`BIT_PACKED = 4`)
+/// encoding or a mixed bit packed and RLE one (`RLE = 3`).
+/// Because it takes as input a single buffer, `SetData` and `Decode` are 
typically
+/// used on each of the Parquet `DataPage`.
+/// The number of levels is guaranteed to fit into an `int32_t` by the 
specification.
+///
+/// @see https://research.google.com/pubs/archive/36632.pdf
 class PARQUET_EXPORT LevelDecoder {
  public:
   explicit LevelDecoder(int16_t max_level = 0);
 
+  LevelDecoder(LevelDecoder&&);
+  LevelDecoder& operator=(LevelDecoder&&);

Review Comment:
   `LevelDecoder` is an exported public class, but this refactor removes 
`num_values_remaining_` and `max_level_` from its object layout, changing its 
size and ABI for consumers that mix this header with an existing Parquet 
binary. If Arrow's supported ABI is expected to remain compatible here, 
preserve the layout (or explicitly defer this to an ABI-breaking release) 
rather than silently changing it.



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