Skip to content

Commit

Permalink
[Fix](multi-catalog) Fix some undefined behaviors. (apache#38274)
Browse files Browse the repository at this point in the history
## Proposed changes

backport apache#37845
  • Loading branch information
kaka11chen authored Jul 24, 2024
1 parent c6cd1e2 commit ef00dad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions be/src/vec/exec/format/orc/vorc_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ Status OrcReader::get_next_block_impl(Block* block, size_t* read_rows, bool* eof
_decimal_scale_params_index = 0;
try {
rr = _row_reader->nextBatch(*_batch, block);
if (rr == 0) {
if (rr == 0 || _batch->numElements == 0) {
*eof = true;
*read_rows = 0;
return Status::OK();
Expand Down Expand Up @@ -1656,7 +1656,7 @@ Status OrcReader::get_next_block_impl(Block* block, size_t* read_rows, bool* eof
_decimal_scale_params_index = 0;
try {
rr = _row_reader->nextBatch(*_batch, block);
if (rr == 0) {
if (rr == 0 || _batch->numElements == 0) {
*eof = true;
*read_rows = 0;
return Status::OK();
Expand Down
26 changes: 14 additions & 12 deletions be/src/vec/exec/format/parquet/parquet_column_convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,20 @@ class StringToDecimal : public PhysicalToLogicalConverter {
// When Decimal in parquet is stored in byte arrays, binary and fixed,
// the unscaled number must be encoded as two's complement using big-endian byte order.
ValueCopyType value = 0;
memcpy(reinterpret_cast<char*>(&value), buf + offset[i - 1], len);
value = BitUtil::big_endian_to_host(value);
value = value >> ((sizeof(value) - len) * 8);
if constexpr (ScaleType == DecimalScaleParams::SCALE_UP) {
value *= scale_params.scale_factor;
} else if constexpr (ScaleType == DecimalScaleParams::SCALE_DOWN) {
value /= scale_params.scale_factor;
} else if constexpr (ScaleType == DecimalScaleParams::NO_SCALE) {
// do nothing
} else {
LOG(FATAL) << "__builtin_unreachable";
__builtin_unreachable();
if (len > 0) {
memcpy(reinterpret_cast<char*>(&value), buf + offset[i - 1], len);
value = BitUtil::big_endian_to_host(value);
value = value >> ((sizeof(value) - len) * 8);
if constexpr (ScaleType == DecimalScaleParams::SCALE_UP) {
value *= scale_params.scale_factor;
} else if constexpr (ScaleType == DecimalScaleParams::SCALE_DOWN) {
value /= scale_params.scale_factor;
} else if constexpr (ScaleType == DecimalScaleParams::NO_SCALE) {
// do nothing
} else {
LOG(FATAL) << "__builtin_unreachable";
__builtin_unreachable();
}
}
auto& v = reinterpret_cast<DecimalType&>(data[start_idx + i]);
v = (DecimalType)value;
Expand Down

0 comments on commit ef00dad

Please sign in to comment.