Skip to content

Commit

Permalink
[Enhancement]reserve size before reading strings
Browse files Browse the repository at this point in the history
Signed-off-by: zombee0 <[email protected]>
  • Loading branch information
zombee0 committed Jan 3, 2025
1 parent 2bce91f commit 0e57b15
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions be/src/formats/parquet/encoding_plain.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "column/column.h"
#include "column/column_helper.h"
#include "common/status.h"
#include "formats/parquet/encoding.h"
#include "gutil/strings/substitute.h"
Expand Down Expand Up @@ -173,18 +174,21 @@ class PlainDecoder<Slice> final : public Decoder {
slices.reserve(count);

size_t num_decoded = 0;
size_t byte_size = 0;
while (num_decoded < count && _offset < _data.size) {
uint32_t length = decode_fixed32_le(reinterpret_cast<const uint8_t*>(_data.data) + _offset);
_offset += sizeof(int32_t);
slices.emplace_back(_data.data + _offset, length);
_offset += length;
byte_size += length;
num_decoded++;
}
// never happend
if (num_decoded < count || _offset > _data.size) {
return Status::InternalError(strings::Substitute(
"going to read out-of-bounds data, offset=$0,count=$1,size=$2", _offset, count, _data.size));
}
ColumnHelper::get_column_by_type<LogicalType::TYPE_VARCHAR>(dst)->reserve(count, byte_size);
auto ret = dst->append_strings(slices);
if (UNLIKELY(!ret)) {
return Status::InternalError("PlainDecoder append strings to column failed");
Expand Down

0 comments on commit 0e57b15

Please sign in to comment.