Skip to content

Commit fe80f3c

Browse files
authored
[chore](compile)Fix some implicit casting (apache#53683)
1 parent 2edc237 commit fe80f3c

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

be/src/olap/rowset/segment_v2/segment_writer.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
// IWYU pragma: no_include <opentelemetry/common/threadlocal.h>
2525
#include "cloud/config.h"
26+
#include "common/cast_set.h"
2627
#include "common/compiler_util.h" // IWYU pragma: keep
2728
#include "common/config.h"
2829
#include "common/logging.h" // LOG
@@ -70,6 +71,7 @@
7071

7172
namespace doris {
7273
namespace segment_v2 {
74+
#include "common/compile_check_begin.h"
7375

7476
using namespace ErrorCode;
7577

@@ -106,7 +108,7 @@ SegmentWriter::SegmentWriter(io::FileWriter* file_writer, uint32_t segment_id,
106108
for (size_t cid = 0; cid < _num_sort_key_columns; ++cid) {
107109
const auto& column = _tablet_schema->column(cid);
108110
_key_coders.push_back(get_key_coder(column.type()));
109-
_key_index_size.push_back(column.index_length());
111+
_key_index_size.push_back(cast_set<uint16_t>(column.index_length()));
110112
}
111113
if (_is_mow()) {
112114
// encode the sequence id into the primary key index
@@ -127,7 +129,7 @@ SegmentWriter::SegmentWriter(io::FileWriter* file_writer, uint32_t segment_id,
127129
for (auto cid : _tablet_schema->cluster_key_uids()) {
128130
const auto& column = _tablet_schema->column_by_uid(cid);
129131
_key_coders.push_back(get_key_coder(column.type()));
130-
_key_index_size.push_back(column.index_length());
132+
_key_index_size.push_back(cast_set<uint16_t>(column.index_length()));
131133
}
132134
}
133135
}
@@ -168,7 +170,7 @@ void SegmentWriter::init_column_meta(ColumnMetaPB* meta, uint32_t column_id,
168170

169171
Status SegmentWriter::init() {
170172
std::vector<uint32_t> column_ids;
171-
int column_cnt = _tablet_schema->num_columns();
173+
auto column_cnt = cast_set<int>(_tablet_schema->num_columns());
172174
for (uint32_t i = 0; i < column_cnt; ++i) {
173175
column_ids.emplace_back(i);
174176
}
@@ -204,8 +206,8 @@ Status SegmentWriter::_create_column_writer(uint32_t cid, const TabletColumn& co
204206
return Status::NotSupported("Do not support ngram bloom filter for bf_size: ",
205207
gram_bf_size);
206208
}
207-
opts.gram_size = gram_size;
208-
opts.gram_bf_size = gram_bf_size;
209+
opts.gram_size = cast_set<uint8_t>(gram_size);
210+
opts.gram_bf_size = cast_set<uint16_t>(gram_bf_size);
209211
}
210212

211213
opts.need_bitmap_index = column.has_bitmap_index();
@@ -401,7 +403,7 @@ Status SegmentWriter::append_block_with_variant_subcolumns(vectorized::Block& da
401403
continue;
402404
}
403405
CHECK(entry->data.is_finalized());
404-
int current_column_id = column_id++;
406+
auto current_column_id = cast_set<int>(column_id++);
405407
TabletColumn tablet_column = generate_column_info(entry);
406408
vectorized::schema_util::inherit_column_attributes(*parent_column, tablet_column,
407409
_flush_schema);
@@ -473,8 +475,8 @@ void SegmentWriter::_serialize_block_to_row_column(vectorized::Block& block) {
473475
vectorized::DataTypeSerDeSPtrs serdes =
474476
vectorized::create_data_type_serdes(block.get_data_types());
475477
vectorized::JsonbSerializeUtil::block_to_jsonb(
476-
*_tablet_schema, block, *row_store_column, _tablet_schema->num_columns(),
477-
serdes,
478+
*_tablet_schema, block, *row_store_column,
479+
cast_set<int>(_tablet_schema->num_columns()), serdes,
478480
{_tablet_schema->row_columns_uids().begin(),
479481
_tablet_schema->row_columns_uids().end()});
480482
break;
@@ -496,9 +498,9 @@ Status SegmentWriter::probe_key_for_mow(
496498
RowLocation loc;
497499
// save rowset shared ptr so this rowset wouldn't delete
498500
RowsetSharedPtr rowset;
499-
auto st = _tablet->lookup_row_key(key, _tablet_schema.get(), have_input_seq_column,
500-
specified_rowsets, &loc, _mow_context->max_version,
501-
segment_caches, &rowset);
501+
auto st = _tablet->lookup_row_key(
502+
key, _tablet_schema.get(), have_input_seq_column, specified_rowsets, &loc,
503+
cast_set<uint32_t>(_mow_context->max_version), segment_caches, &rowset);
502504
if (st.is<KEY_NOT_FOUND>()) {
503505
if (!have_delete_sign) {
504506
RETURN_IF_ERROR(not_found_cb());
@@ -537,7 +539,7 @@ Status SegmentWriter::probe_key_for_mow(
537539
// for this row, we need to ensure that each column is aligned
538540
_mow_context->delete_bitmap->add(
539541
{_opts.rowset_ctx->rowset_id, _segment_id, DeleteBitmap::TEMP_VERSION_COMMON},
540-
segment_pos);
542+
cast_set<uint32_t>(segment_pos));
541543
++stats.num_rows_deleted;
542544
} else {
543545
_mow_context->delete_bitmap->add(
@@ -678,7 +680,8 @@ Status SegmentWriter::append_block_with_partial_content(const vectorized::Block*
678680
auto not_found_cb = [&]() {
679681
return _opts.rowset_ctx->partial_update_info->handle_new_key(
680682
*_tablet_schema, [&]() -> std::string {
681-
return block->dump_one_line(block_pos, _num_sort_key_columns);
683+
return block->dump_one_line(block_pos,
684+
cast_set<int>(_num_sort_key_columns));
682685
});
683686
};
684687
auto update_read_plan = [&](const RowLocation& loc) {
@@ -699,7 +702,8 @@ Status SegmentWriter::append_block_with_partial_content(const vectorized::Block*
699702
// read to fill full block
700703
RETURN_IF_ERROR(read_plan.fill_missing_columns(
701704
_opts.rowset_ctx, _rsid_to_rowset, *_tablet_schema, full_block,
702-
use_default_or_null_flag, has_default_or_nullable, segment_start_pos, block));
705+
use_default_or_null_flag, has_default_or_nullable,
706+
cast_set<uint32_t>(segment_start_pos), block));
703707

704708
// convert block to row store format
705709
_serialize_block_to_row_column(full_block);
@@ -959,7 +963,7 @@ std::string SegmentWriter::_encode_keys(
959963
template <typename RowType>
960964
Status SegmentWriter::append_row(const RowType& row) {
961965
for (size_t cid = 0; cid < _column_writers.size(); ++cid) {
962-
auto cell = row.cell(cid);
966+
auto cell = row.cell(cast_set<uint32_t>(cid));
963967
RETURN_IF_ERROR(_column_writers[cid]->append(cell));
964968
}
965969
std::string full_encoded_key;
@@ -1207,7 +1211,7 @@ Status SegmentWriter::_write_footer() {
12071211

12081212
faststring fixed_buf;
12091213
// footer's size
1210-
put_fixed32_le(&fixed_buf, footer_buf.size());
1214+
put_fixed32_le(&fixed_buf, cast_set<uint32_t>(footer_buf.size()));
12111215
// footer's checksum
12121216
uint32_t checksum = crc32c::Value(footer_buf.data(), footer_buf.size());
12131217
put_fixed32_le(&fixed_buf, checksum);
@@ -1324,5 +1328,6 @@ inline bool SegmentWriter::_is_mow() {
13241328
inline bool SegmentWriter::_is_mow_with_cluster_key() {
13251329
return _is_mow() && !_tablet_schema->cluster_key_uids().empty();
13261330
}
1331+
#include "common/compile_check_end.h"
13271332
} // namespace segment_v2
13281333
} // namespace doris

be/src/util/frame_of_reference_coding.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,19 @@
2222
#include <cstdlib>
2323
#include <vector>
2424

25+
#include "common/cast_set.h"
2526
#include "olap/olap_common.h"
2627
#include "olap/uint24.h"
2728
#include "util/faststring.h"
2829

2930
namespace doris {
31+
#include "common/compile_check_begin.h"
3032

3133
inline uint8_t leading_zeroes(const uint64_t v) {
3234
if (v == 0) {
3335
return 64;
3436
}
35-
return __builtin_clzll(v);
37+
return cast_set<uint8_t>(__builtin_clzll(v));
3638
}
3739

3840
inline uint8_t bits_less_than_64(const uint64_t v) {
@@ -46,18 +48,18 @@ inline uint8_t bits_may_more_than_64(const uint128_t v) {
4648
return 0;
4749
}
4850
uint64_t hi = v >> 64;
49-
uint64_t lo = v;
51+
auto lo = static_cast<uint64_t>(v); // Use static_cast to get low 64 bits without range check
5052
int z[3] = {leading_zeroes(hi), leading_zeroes(lo) + 64, 128};
5153
int idx = !hi + ((!lo) & (!hi));
52-
return 128 - z[idx];
54+
return cast_set<uint8_t>(128 - z[idx]);
5355
}
5456

5557
template <typename T>
5658
uint8_t bits(const T v) {
5759
if (sizeof(T) <= 8) {
58-
return bits_less_than_64(v);
60+
return bits_less_than_64(static_cast<uint64_t>(v));
5961
} else {
60-
return bits_may_more_than_64(v);
62+
return bits_may_more_than_64(static_cast<uint128_t>(v));
6163
}
6264
}
6365

@@ -105,7 +107,10 @@ class ForEncoder {
105107

106108
// underlying buffer size + footer meta size.
107109
// Note: should call this method before flush.
108-
uint32_t len() { return _buffer->size() + _storage_formats.size() + _bit_widths.size() + 5; }
110+
uint32_t len() {
111+
return cast_set<uint32_t>(_buffer->size() + _storage_formats.size() + _bit_widths.size() +
112+
5);
113+
}
109114

110115
// Resets all the state in the encoder.
111116
void clear() {
@@ -206,4 +211,5 @@ class ForDecoder {
206211
uint32_t _current_decoded_frame = -1;
207212
std::vector<T> _out_buffer; // store values of decoded frame
208213
};
214+
#include "common/compile_check_end.h"
209215
} // namespace doris

be/test/olap/index_builder_test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class IndexBuilderTest : public ::testing::Test {
9898
column_1.set_unique_id(1);
9999
column_1.set_name("k1");
100100
column_1.set_is_key(true);
101+
column_1.set_index_length(4);
101102
tablet_schema->append_column(column_1);
102103

103104
// Create the second key column
@@ -1094,6 +1095,7 @@ TEST_F(IndexBuilderTest, RenameColumnIndexTest) {
10941095
column_1.set_unique_id(1);
10951096
column_1.set_name("k1");
10961097
column_1.set_is_key(true);
1098+
column_1.set_index_length(4);
10971099
schema->append_column(column_1);
10981100

10991101
// Create the second key column
@@ -2088,6 +2090,7 @@ TEST_F(IndexBuilderTest, ArrayTypeIndexTest) {
20882090
column_1.set_unique_id(1);
20892091
column_1.set_is_key(true);
20902092
column_1.set_name("k1");
2093+
column_1.set_index_length(4);
20912094
tablet_schema->append_column(column_1);
20922095

20932096
// Array type column

0 commit comments

Comments
 (0)