Skip to content

Commit 5287505

Browse files
csun5285claude
andcommitted
[refactor](be) Fix the clang-tidy findings on the StorageLayout read changes
### What problem does this PR solve? Issue Number: None Related PR: apache#68608 Problem Summary: Review follow-up. clang-tidy reports errors on lines this branch changed, in test files the earlier tidy pass did not cover: - The decimal12_t brace initializers in storage_layout_test and row_cursor_test now name their fields (modernize-use-designated-initializers). - The V1 DATE page tests of plain_page_test and bitshuffle_page_test build their page in a fixture helper, and decoding by batch and reading by row id into a Nullable column are now separate tests. Each test checks one path, and each body stays under the cognitive-complexity threshold. - key_coder_test's test_ordering, whose body is unchanged from master and whose signature line the rename touched, gets the NOLINTNEXTLINE that other long test bodies in be/test use. repack_to_column now tests for a Nullable destination with is_column_nullable, as the column reader does. IColumn::is_nullable() is also true for a ColumnConst over a Nullable, which the cast that follows would reject. A page decoder is only ever handed a column the reader created, so nothing changes at run time. ### Release note None ### Check List (For Author) - Test: Unit Test - Run on this revision (ASAN build): 675 tests from 31 suites, the set run for the rename, all pass; PlainPageTest (9) and BitShufflePageTest (15) now hold the split V1 DATE tests. - clang-format 16, build hygiene, clang-tidy on the six files this commit touches: no finding on a line the branch changes. - Behavior changed: No - Does this need documentation: No Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e84a373 commit 5287505

6 files changed

Lines changed: 103 additions & 63 deletions

File tree

‎be/src/storage/storage_layout.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void repack_from_column(const IColumn& column, size_t row_pos, size_t n, uint8_t
6868
// Appends n stored values of a repacked layout, each turned back into its PrimitiveValue.
6969
template <FieldType FT>
7070
void repack_to_column(const uint8_t* values, size_t n, IColumn& dst) {
71-
if (dst.is_nullable()) {
71+
if (is_column_nullable(dst)) {
7272
// A page holds no NULL row: the n rows it decodes are all not NULL.
7373
auto& nullable = assert_cast<ColumnNullable&>(dst);
7474
nullable.push_false_to_nullmap(n);

‎be/test/storage/key_coder_test.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ void test_encode_decode(typename StorageTypeTraits<field_type>::StorageType valu
135135
}
136136

137137
template <FieldType field_type>
138+
// NOLINTNEXTLINE(readability-function-cognitive-complexity) -- GTest assertion macros inflate it.
138139
void test_ordering(typename StorageTypeTraits<field_type>::StorageType a,
139140
typename StorageTypeTraits<field_type>::StorageType b) {
140141
std::string encoded_a = encode_float<field_type>(a);

‎be/test/storage/row_cursor_test.cpp‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,8 @@ TEST_F(TestRowCursor, encode_key_double_nan_decimal_string) {
468468
row.mutable_field(0) =
469469
Field::create_field<TYPE_DOUBLE>(std::numeric_limits<double>::quiet_NaN());
470470
// DECIMAL(123.456000000): stored as decimal12_t{123, 456000000}
471-
row.mutable_field(1) = field_of_cell<TYPE_DECIMALV2>(decimal12_t {123, 456000000});
471+
row.mutable_field(1) =
472+
field_of_cell<TYPE_DECIMALV2>(decimal12_t {.integer = 123, .fraction = 456000000});
472473
row.mutable_field(2) = Field::create_field<TYPE_STRING>(String("hello world"));
473474

474475
// encode_key: STRING truncated to 4 bytes
@@ -607,7 +608,8 @@ TEST_F(TestRowCursor, encode_key_negative_values) {
607608
row.mutable_field(0) = Field::create_field<TYPE_INT>(int32_t(-12345));
608609
row.mutable_field(1) = Field::create_field<TYPE_DOUBLE>(-1.0);
609610
// DECIMAL(-123, -456000000) representing -123.456000000
610-
row.mutable_field(2) = field_of_cell<TYPE_DECIMALV2>(decimal12_t {-123, -456000000});
611+
row.mutable_field(2) =
612+
field_of_cell<TYPE_DECIMALV2>(decimal12_t {.integer = -123, .fraction = -456000000});
611613

612614
{
613615
std::string buf;

‎be/test/storage/segment/bitshuffle_page_test.cpp‎

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,39 @@ class BitShufflePageTest : public testing::Test {
168168
status = page_decoder.seek_at_or_after_value(bigger_than_biggest, &exact_match);
169169
EXPECT_EQ(status.code(), ENTRY_NOT_FOUND);
170170
}
171+
172+
// Eight consecutive days from 2020-01-01 in one bitshuffle page of V1 DATE cells, each date
173+
// stored as a uint24, unshuffled into `decoded_page` as the page cache holds it. `page` is
174+
// left pointing at the unshuffled page.
175+
void build_date_v1_page(std::vector<VecDateTimeValue>* days,
176+
std::unique_ptr<DataPage>* decoded_page, Slice* page) {
177+
using Layout = StorageLayout<FieldType::OLAP_FIELD_TYPE_DATE>;
178+
constexpr size_t kRows = 8;
179+
days->resize(kRows);
180+
std::vector<uint24_t> cells(kRows);
181+
for (size_t i = 0; i < kRows; ++i) {
182+
ASSERT_TRUE((*days)[i].from_date_int64(static_cast<int64_t>(20200101 + i)));
183+
cells[i] = Layout::to_storage((*days)[i]);
184+
}
185+
PageBuilderOptions options;
186+
options.data_page_size = 256 * 1024;
187+
segment_v2::PageBuilder* builder = nullptr;
188+
ASSERT_TRUE(segment_v2::BitshufflePageBuilder<FieldType::OLAP_FIELD_TYPE_DATE>::create(
189+
&builder, options)
190+
.ok());
191+
std::unique_ptr<segment_v2::PageBuilder> page_builder(builder);
192+
size_t added = kRows;
193+
ASSERT_TRUE(page_builder->add(reinterpret_cast<const uint8_t*>(cells.data()), &added).ok());
194+
ASSERT_EQ(added, kRows);
195+
OwnedSlice encoded;
196+
ASSERT_TRUE(page_builder->finish(&encoded).ok());
197+
segment_v2::BitShufflePagePreDecoder pre_decoder;
198+
*page = encoded.slice();
199+
ASSERT_TRUE(
200+
pre_decoder
201+
.decode(decoded_page, page, 0, false, segment_v2::PageTypePB::DATA_PAGE, "")
202+
.ok());
203+
}
171204
};
172205

173206
// Test for bitshuffle block, for INT32, INT64, FLOAT, DOUBLE
@@ -369,55 +402,42 @@ TEST_F(BitShufflePageTest, TestBitShuffleDecimal12BlockEncoderSeekValue) {
369402
decimals.get(), size, &small_than_smallest, &bigger_than_biggest);
370403
}
371404

372-
// A V1 DATE page holds uint24 cells, which the decoder unpacks into the dates of a ColumnDate,
373-
// or of a Nullable over it, by batch and by row id.
405+
// A V1 DATE page holds each date as a uint24 cell; a batch decodes the cells into the dates
406+
// of a ColumnDate.
374407
TEST_F(BitShufflePageTest, TestBitShuffleDateV1DecodesIntoDates) {
375-
using Layout = StorageLayout<FieldType::OLAP_FIELD_TYPE_DATE>;
376-
constexpr size_t kRows = 8;
377-
std::vector<VecDateTimeValue> days(kRows);
378-
std::vector<uint24_t> cells(kRows);
379-
for (size_t i = 0; i < kRows; ++i) {
380-
ASSERT_TRUE(days[i].from_date_int64(static_cast<int64_t>(20200101 + i)));
381-
cells[i] = Layout::to_storage(days[i]);
382-
}
383-
384-
PageBuilderOptions options;
385-
options.data_page_size = 256 * 1024;
386-
segment_v2::PageBuilder* builder = nullptr;
387-
ASSERT_TRUE(segment_v2::BitshufflePageBuilder<FieldType::OLAP_FIELD_TYPE_DATE>::create(&builder,
388-
options)
389-
.ok());
390-
std::unique_ptr<segment_v2::PageBuilder> page_builder(builder);
391-
size_t added = kRows;
392-
ASSERT_TRUE(page_builder->add(reinterpret_cast<const uint8_t*>(cells.data()), &added).ok());
393-
ASSERT_EQ(added, kRows);
394-
OwnedSlice encoded;
395-
ASSERT_TRUE(page_builder->finish(&encoded).ok());
396-
397-
segment_v2::BitShufflePagePreDecoder pre_decoder;
398-
Slice page = encoded.slice();
408+
std::vector<VecDateTimeValue> days;
399409
std::unique_ptr<DataPage> decoded_page;
400-
ASSERT_TRUE(
401-
pre_decoder
402-
.decode(&decoded_page, &page, 0, false, segment_v2::PageTypePB::DATA_PAGE, "")
403-
.ok());
410+
Slice page;
411+
ASSERT_NO_FATAL_FAILURE(build_date_v1_page(&days, &decoded_page, &page));
404412
segment_v2::PageDecoderOptions decoder_options;
405413
segment_v2::BitShufflePageDecoder<FieldType::OLAP_FIELD_TYPE_DATE> decoder(page,
406414
decoder_options);
407415
ASSERT_TRUE(decoder.init().ok());
408416

409417
MutableColumnPtr dates = ColumnDate::create();
410-
size_t n = kRows;
418+
size_t n = days.size();
411419
ASSERT_TRUE(decoder.next_batch(&n, dates).ok());
412-
ASSERT_EQ(n, kRows);
420+
ASSERT_EQ(n, days.size());
413421
const auto& decoded = assert_cast<const ColumnDate&>(*dates).get_data();
414-
for (size_t i = 0; i < kRows; ++i) {
422+
for (size_t i = 0; i < days.size(); ++i) {
415423
EXPECT_EQ(decoded[i], days[i]) << "row " << i;
416424
}
425+
}
426+
427+
// Rows read by id into a Nullable over ColumnDate come back as their dates, none of them NULL.
428+
TEST_F(BitShufflePageTest, TestBitShuffleDateV1ReadsRowIdsIntoNullableDates) {
429+
std::vector<VecDateTimeValue> days;
430+
std::unique_ptr<DataPage> decoded_page;
431+
Slice page;
432+
ASSERT_NO_FATAL_FAILURE(build_date_v1_page(&days, &decoded_page, &page));
433+
segment_v2::PageDecoderOptions decoder_options;
434+
segment_v2::BitShufflePageDecoder<FieldType::OLAP_FIELD_TYPE_DATE> decoder(page,
435+
decoder_options);
436+
ASSERT_TRUE(decoder.init().ok());
417437

418438
const segment_v2::rowid_t rowids[] = {1, 3, 6};
419439
MutableColumnPtr picked = ColumnNullable::create(ColumnDate::create(), ColumnUInt8::create());
420-
n = 3;
440+
size_t n = 3;
421441
ASSERT_TRUE(decoder.read_by_rowids(rowids, 0, &n, picked).ok());
422442
ASSERT_EQ(n, 3);
423443
const auto& nullable = assert_cast<const ColumnNullable&>(*picked);

‎be/test/storage/segment/plain_page_test.cpp‎

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,29 @@ class PlainPageTest : public testing::Test {
160160
EXPECT_EQ(status.code(), ENTRY_NOT_FOUND);
161161
}
162162
}
163+
164+
// Eight consecutive days from 2020-01-01 in one plain page of V1 DATE cells, each date
165+
// stored as a uint24.
166+
void build_date_v1_page(std::vector<VecDateTimeValue>* days, OwnedSlice* page) {
167+
using Layout = StorageLayout<FieldType::OLAP_FIELD_TYPE_DATE>;
168+
constexpr size_t kRows = 8;
169+
days->resize(kRows);
170+
std::vector<uint24_t> cells(kRows);
171+
for (size_t i = 0; i < kRows; ++i) {
172+
ASSERT_TRUE((*days)[i].from_date_int64(static_cast<int64_t>(20200101 + i)));
173+
cells[i] = Layout::to_storage((*days)[i]);
174+
}
175+
PageBuilderOptions options;
176+
options.data_page_size = 256 * 1024;
177+
PageBuilder* builder = nullptr;
178+
ASSERT_TRUE(
179+
PlainPageBuilder<FieldType::OLAP_FIELD_TYPE_DATE>::create(&builder, options).ok());
180+
std::unique_ptr<PageBuilder> page_builder(builder);
181+
size_t added = kRows;
182+
ASSERT_TRUE(page_builder->add(reinterpret_cast<const uint8_t*>(cells.data()), &added).ok());
183+
ASSERT_EQ(added, kRows);
184+
ASSERT_TRUE(page_builder->finish(page).ok());
185+
}
163186
};
164187

165188
TEST_F(PlainPageTest, TestInt32PlainPageRandom) {
@@ -272,45 +295,38 @@ TEST_F(PlainPageTest, TestBoolPlainPageSeekValue) {
272295
nullptr);
273296
}
274297

275-
// A V1 DATE page holds uint24 cells, which the decoder unpacks into the dates of a ColumnDate,
276-
// or of a Nullable over it, by batch and by row id.
298+
// A V1 DATE page holds each date as a uint24 cell; a batch decodes the cells into the dates
299+
// of a ColumnDate.
277300
TEST_F(PlainPageTest, TestDateV1PlainPageDecodesIntoDates) {
278-
using Layout = StorageLayout<FieldType::OLAP_FIELD_TYPE_DATE>;
279-
constexpr size_t kRows = 8;
280-
std::vector<VecDateTimeValue> days(kRows);
281-
std::vector<uint24_t> cells(kRows);
282-
for (size_t i = 0; i < kRows; ++i) {
283-
ASSERT_TRUE(days[i].from_date_int64(static_cast<int64_t>(20200101 + i)));
284-
cells[i] = Layout::to_storage(days[i]);
285-
}
286-
287-
PageBuilderOptions options;
288-
options.data_page_size = 256 * 1024;
289-
PageBuilder* builder = nullptr;
290-
ASSERT_TRUE(PlainPageBuilder<FieldType::OLAP_FIELD_TYPE_DATE>::create(&builder, options).ok());
291-
std::unique_ptr<PageBuilder> page_builder(builder);
292-
size_t added = kRows;
293-
ASSERT_TRUE(page_builder->add(reinterpret_cast<const uint8_t*>(cells.data()), &added).ok());
294-
ASSERT_EQ(added, kRows);
301+
std::vector<VecDateTimeValue> days;
295302
OwnedSlice page;
296-
ASSERT_TRUE(page_builder->finish(&page).ok());
297-
303+
ASSERT_NO_FATAL_FAILURE(build_date_v1_page(&days, &page));
298304
PageDecoderOptions decoder_options;
299305
PlainPageDecoder<FieldType::OLAP_FIELD_TYPE_DATE> decoder(page.slice(), decoder_options);
300306
ASSERT_TRUE(decoder.init().ok());
301307

302308
MutableColumnPtr dates = ColumnDate::create();
303-
size_t n = kRows;
309+
size_t n = days.size();
304310
ASSERT_TRUE(decoder.next_batch(&n, dates).ok());
305-
ASSERT_EQ(n, kRows);
311+
ASSERT_EQ(n, days.size());
306312
const auto& decoded = assert_cast<const ColumnDate&>(*dates).get_data();
307-
for (size_t i = 0; i < kRows; ++i) {
313+
for (size_t i = 0; i < days.size(); ++i) {
308314
EXPECT_EQ(decoded[i], days[i]) << "row " << i;
309315
}
316+
}
317+
318+
// Rows read by id into a Nullable over ColumnDate come back as their dates, none of them NULL.
319+
TEST_F(PlainPageTest, TestDateV1PlainPageReadsRowIdsIntoNullableDates) {
320+
std::vector<VecDateTimeValue> days;
321+
OwnedSlice page;
322+
ASSERT_NO_FATAL_FAILURE(build_date_v1_page(&days, &page));
323+
PageDecoderOptions decoder_options;
324+
PlainPageDecoder<FieldType::OLAP_FIELD_TYPE_DATE> decoder(page.slice(), decoder_options);
325+
ASSERT_TRUE(decoder.init().ok());
310326

311327
const rowid_t rowids[] = {1, 3, 6};
312328
MutableColumnPtr picked = ColumnNullable::create(ColumnDate::create(), ColumnUInt8::create());
313-
n = 3;
329+
size_t n = 3;
314330
ASSERT_TRUE(decoder.read_by_rowids(rowids, 0, &n, picked).ok());
315331
ASSERT_EQ(n, 3);
316332
const auto& nullable = assert_cast<const ColumnNullable&>(*picked);

‎be/test/storage/storage_layout_test.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ TEST(StorageLayoutTest, ToPrimitiveInvertsToStorage) {
432432
EXPECT_EQ(DecimalLayout::to_primitive(DecimalLayout::to_storage(amount)), amount);
433433
const DecimalV2Value debt(-123, -456000000);
434434
EXPECT_EQ(DecimalLayout::to_primitive(DecimalLayout::to_storage(debt)), debt);
435-
const DecimalV2Value read_debt = DecimalLayout::to_primitive(decimal12_t {-123, -456000000});
435+
const DecimalV2Value read_debt =
436+
DecimalLayout::to_primitive(decimal12_t {.integer = -123, .fraction = -456000000});
436437
EXPECT_EQ(read_debt.int_value(), -123);
437438
EXPECT_EQ(read_debt.frac_value(), -456000000);
438439

0 commit comments

Comments
 (0)