AshinGau commented on code in PR #17112: URL: https://github.com/apache/doris/pull/17112#discussion_r1124067588
########## be/src/vec/exec/format/parquet/delta_bit_pack_decoder.cpp: ########## @@ -0,0 +1,157 @@ +// 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 "delta_bit_pack_decoder.h" + +namespace doris::vectorized { + +template <typename T> +Status DeltaBitPackDecoder<T>::_init_header() { + if (!_bit_reader->GetUleb128<uint32_t>(&_values_per_block) || + !_bit_reader->GetUleb128<uint32_t>(&_mini_blocks_per_block) || + !_bit_reader->GetUleb128<uint32_t>(&_total_value_count) || + !_bit_reader->GetZigZagInteger(&_last_value)) { + return Status::EndOfFile("Init header eof"); Review Comment: ParquetReader takes `EndOfFile` as normal, not error. ########## be/src/vec/exec/format/parquet/delta_bit_pack_decoder.h: ########## @@ -0,0 +1,117 @@ +// 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/columns/column.h" +#include "vec/exec/format/parquet/decoder.h" + +namespace doris::vectorized { +/** + * 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 Decoder { +public: + using UT = std::make_unsigned_t<T>; + + DeltaBitPackDecoder() = default; + ~DeltaBitPackDecoder() override = default; + Status decode_values(MutableColumnPtr& doris_column, DataTypePtr& data_type, + ColumnSelectVector& select_vector) override { + size_t num_values = select_vector.num_values(); Review Comment: How about null values. ########## be/src/vec/exec/format/parquet/delta_bit_pack_decoder.h: ########## @@ -0,0 +1,117 @@ +// 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/columns/column.h" +#include "vec/exec/format/parquet/decoder.h" + +namespace doris::vectorized { +/** + * 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 Decoder { +public: + using UT = std::make_unsigned_t<T>; + + DeltaBitPackDecoder() = default; + ~DeltaBitPackDecoder() override = default; + Status decode_values(MutableColumnPtr& doris_column, DataTypePtr& data_type, + ColumnSelectVector& select_vector) override { + size_t num_values = select_vector.num_values(); + // decode values + std::vector<T> values(num_values); + int decoded_count = 0; + RETURN_IF_ERROR(_get_internal(values.data(), num_values, &decoded_count)); + + // set value + auto& column_data = static_cast<ColumnVector<T>&>(*doris_column).get_data(); + size_t data_index = column_data.size(); + column_data.resize(data_index + select_vector.num_values() - select_vector.num_filtered()); + ColumnSelectVector::DataReadType read_type; + while (size_t run_length = select_vector.get_next_run(&read_type)) { + switch (read_type) { + case ColumnSelectVector::CONTENT: { + for (size_t i = 0; i < run_length; ++i) { + column_data[data_index++] = values[i++]; + } + break; + } + case ColumnSelectVector::NULL_DATA: { + data_index += run_length; + break; + } + case ColumnSelectVector::FILTERED_CONTENT: { + // do nothing + break; + } + case ColumnSelectVector::FILTERED_NULL: { + // do nothing + break; + } + } + } + return Status::OK(); + } + + Status skip_values(size_t num_values) override { return Status::OK(); } + + void set_data(Slice* slice) override { + _bit_reader.reset(new BatchedBitReader((const uint8_t*)slice->data, slice->size)); + _init_header(); + _data = slice; + _offset = 0; + } + +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::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>; +} // namespace doris::vectorized Review Comment: new line ########## be/src/vec/exec/format/parquet/decoder.cpp: ########## @@ -88,6 +89,19 @@ Status Decoder::get_decoder(tparquet::Type::type type, tparquet::Encoding::type tparquet::to_string(type), tparquet::to_string(encoding)); } break; + case tparquet::Encoding::DELTA_BINARY_PACKED: + // Supports only INT32 and INT64. + switch (type) { + case tparquet::Type::INT32: + decoder.reset(new DeltaBitPackDecoder<Int32>()); Review Comment: should break -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org