github-actions[bot] commented on code in PR #17112:
URL: https://github.com/apache/doris/pull/17112#discussion_r1124466057


##########
be/src/vec/exec/format/parquet/delta_bit_pack_decoder.h:
##########
@@ -0,0 +1,262 @@
+// 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 "util/bit_stream_utils.h"
+#include "vec/exec/format/parquet/fix_length_plain_decoder.h"
+
+namespace doris::vectorized {
+
+class DeltaDecoder : public Decoder {
+public:
+    DeltaDecoder(FixLengthPlainDecoder* fix_plain_decoder) {
+        _fix_plain_decoder.reset(fix_plain_decoder);
+    }
+    ~DeltaDecoder() = default;

Review Comment:
   warning: annotate this function with 'override' or (rarely) 'final' 
[modernize-use-override]
   
   ```suggestion
       ~DeltaDecoder() override = default;
   ```
   



##########
be/src/vec/exec/format/parquet/delta_bit_pack_decoder.h:
##########
@@ -0,0 +1,262 @@
+// 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 "util/bit_stream_utils.h"
+#include "vec/exec/format/parquet/fix_length_plain_decoder.h"
+
+namespace doris::vectorized {
+
+class DeltaDecoder : public Decoder {
+public:
+    DeltaDecoder(FixLengthPlainDecoder* fix_plain_decoder) {
+        _fix_plain_decoder.reset(fix_plain_decoder);
+    }
+    ~DeltaDecoder() = default;
+    Status skip_values(size_t num_values) override {
+        return _fix_plain_decoder->skip_values(num_values);
+    }
+
+protected:
+    void init_values_converter() {
+        _fix_plain_decoder->set_data(_data);
+        _fix_plain_decoder->set_type_length(_type_length);
+        _fix_plain_decoder->init(_field_schema, _decode_params->ctz);
+    }
+    std::unique_ptr<FixLengthPlainDecoder> _fix_plain_decoder;
+};
+
+/**
+ *   Format
+ *      [header] [block 1] [block 2] ... [block N]
+ *   Header
+ *      [block size] [_mini_blocks_per_block] [_total_value_count] [first 
value]
+ *   Block
+ *      [min delta] [list of bitwidths of the mini blocks] [miniblocks]
+ */
+template <typename T>
+class DeltaBitPackDecoder final : public DeltaDecoder {
+public:
+    using UT = std::make_unsigned_t<T>;
+
+    DeltaBitPackDecoder(const tparquet::Type::type& physical_type)
+            : DeltaDecoder(new FixLengthPlainDecoder(physical_type)) {}
+    ~DeltaBitPackDecoder() override = default;
+    Status decode_values(MutableColumnPtr& doris_column, DataTypePtr& 
data_type,
+                         ColumnSelectVector& select_vector) override {
+        size_t non_null_size = select_vector.num_values() - 
select_vector.num_nulls();
+        // decode values
+        _values.resize(non_null_size);
+        int decoded_count = 0;
+        RETURN_IF_ERROR(_get_internal(_values.data(), non_null_size, 
&decoded_count));
+        _data->data = reinterpret_cast<char*>(_values.data());
+        _type_length = sizeof(T);
+        _data->size = _values.size() * _type_length;
+        // set decoded value with fix plain decoder
+        init_values_converter();
+        return _fix_plain_decoder->decode_values(doris_column, data_type, 
select_vector);
+    }
+
+    Status decode(T* buffer, int num_values, int* out_num_values) {
+        return _get_internal(buffer, num_values, out_num_values);
+    }
+
+    int valid_values_count() {
+        // _total_value_count in header ignores of null values
+        return static_cast<int>(_total_value_count);
+    }
+
+    void set_data(Slice* slice) override {
+        _bit_reader.reset(new BatchedBitReader((const uint8_t*)slice->data, 
slice->size));
+        _init_header();
+        _data = slice;
+        _offset = 0;
+    }
+
+    // Set BitReader which is already initialized by 
DeltaLengthByteArrayDecoder or
+    // DeltaByteArrayDecoder
+    void set_decoder(std::shared_ptr<BatchedBitReader> bit_reader) {
+        _bit_reader = std::move(bit_reader);
+        _init_header();
+    }
+
+private:
+    static constexpr int kMaxDeltaBitWidth = static_cast<int>(sizeof(T) * 8);
+    Status _init_header();
+    Status _init_block();
+    Status _init_mini_block(int bit_width);
+    Status _get_internal(T* buffer, int max_values, int* out_num_values);
+
+    std::vector<T> _values;
+
+    std::shared_ptr<BatchedBitReader> _bit_reader;
+    uint32_t _values_per_block;
+    uint32_t _mini_blocks_per_block;
+    uint32_t _values_per_mini_block;
+    uint32_t _total_value_count;
+
+    T _min_delta;
+    T _last_value;
+
+    uint32_t _mini_block_idx;
+    std::vector<uint8_t> _delta_bit_widths;
+    int _delta_bit_width;
+    // If the page doesn't contain any block, `_block_initialized` will
+    // always be false. Otherwise, it will be true when first block 
initialized.
+    bool _block_initialized;
+
+    uint32_t _total_values_remaining;
+    // Remaining values in current mini block. If the current block is the 
last mini block,
+    // _values_remaining_current_mini_block may greater than 
_total_values_remaining.
+    uint32_t _values_remaining_current_mini_block;
+};
+template class DeltaBitPackDecoder<int32_t>;
+template class DeltaBitPackDecoder<int64_t>;
+
+class DeltaLengthByteArrayDecoder final : public DeltaDecoder {
+public:
+    explicit DeltaLengthByteArrayDecoder(const tparquet::Type::type& 
physical_type)
+            : DeltaDecoder(new FixLengthPlainDecoder(physical_type)),
+              _len_decoder(physical_type),
+              _buffered_length(0),
+              _buffered_data(0) {}
+
+    Status decode_values(MutableColumnPtr& doris_column, DataTypePtr& 
data_type,
+                         ColumnSelectVector& select_vector) override {
+        size_t num_values = select_vector.num_values();
+        size_t null_count = select_vector.num_nulls();
+        _values.resize(num_values - null_count);
+        int num_valid_values;
+        RETURN_IF_ERROR(_get_internal(_values.data(), num_values - null_count, 
&num_valid_values));
+
+        if (PREDICT_FALSE(num_values - null_count != num_valid_values)) {
+            return Status::EndOfFile("Expected to decode ", num_values - 
null_count,
+                                     " values, but decoded ", 
num_valid_values, " values.");
+        }
+        _data->data = reinterpret_cast<char*>(_values.data());
+        _type_length = sizeof(_field_schema->parquet_schema.type_length);
+        _data->size = _values.size() * _type_length;
+        init_values_converter();
+        return _fix_plain_decoder->decode_values(doris_column, data_type, 
select_vector);
+    }
+
+    Status decode(Slice* buffer, int num_values, int* out_num_values) {
+        return _get_internal(buffer, num_values, out_num_values);
+    }
+
+    void set_data(Slice* slice) override {
+        if (slice->size == 0) {
+            return;
+        }
+        _bit_reader = std::make_shared<BatchedBitReader>((const 
uint8_t*)slice->data, slice->size);
+        _data = slice;
+        _offset = 0;
+        _decode_lengths();
+    }
+
+    void set_decoder(std::shared_ptr<BatchedBitReader> bit_reader) {
+        _bit_reader = std::move(bit_reader);
+        _decode_lengths();
+    }
+
+private:
+    // Decode all the encoded lengths. The decoder_ will be at the start of 
the encoded data
+    // after that.
+    void _decode_lengths();
+    Status _get_internal(Slice* buffer, int max_values, int* out_num_values);
+
+    std::vector<Slice> _values;
+    std::shared_ptr<BatchedBitReader> _bit_reader;
+    DeltaBitPackDecoder<int32_t> _len_decoder;
+
+    int _num_valid_values;
+    uint32_t _length_idx;
+    std::vector<char> _buffered_length;
+    std::vector<char> _buffered_data;
+};
+
+class DeltaByteArrayDecoder : public DeltaDecoder {
+public:
+    explicit DeltaByteArrayDecoder(const tparquet::Type::type& physical_type)
+            : DeltaDecoder(new FixLengthPlainDecoder(physical_type)),
+              _prefix_len_decoder(physical_type),
+              _suffix_decoder(physical_type),
+              _last_value_in_previous_page(""),

Review Comment:
   warning: redundant string initialization [readability-redundant-string-init]
   
   ```suggestion
                 ,
   ```
   



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to