Skip to content

Commit 1b56ed9

Browse files
marsishandsomezanmato1984
authored andcommitted
[FLASH-466] improve code coverage (pingcap#219)
1 parent 73d1de4 commit 1b56ed9

13 files changed

+849
-339
lines changed

Diff for: dbms/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ if (TEST_COVERAGE AND CMAKE_BUILD_TYPE STREQUAL "Debug")
298298
)
299299
SETUP_TARGET_FOR_COVERAGE_GCOVR_HTML(
300300
NAME tiflash_gcovr_coverage
301-
DEPENDENCIES unit_tests_dbms
302-
EXECUTABLE unit_tests_dbms
301+
DEPENDENCIES gtests_dbms
302+
EXECUTABLE gtests_dbms
303303
)
304304
endif()

Diff for: dbms/src/Storages/DeltaMerge/Chunk.cpp

+3-36
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
431431
assert(!disk_type_not_null->isNullable());
432432
assert(!read_type_not_null->isNullable());
433433

434+
/// Caller should ensure that dist_type != read_type
435+
assert(!disk_type_not_null->equals(*read_type_not_null));
436+
434437
if (checkDataType<DataTypeUInt32>(disk_type_not_null))
435438
{
436439
using FromType = UInt32;
@@ -440,12 +443,6 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
440443
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
441444
return true;
442445
}
443-
else if (checkDataType<DataTypeUInt32>(read_type_not_null))
444-
{
445-
insertRangeFromWithNumericTypeCast<FromType, UInt32>(
446-
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
447-
return true;
448-
}
449446
}
450447
else if (checkDataType<DataTypeInt32>(disk_type_not_null))
451448
{
@@ -456,12 +453,6 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
456453
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
457454
return true;
458455
}
459-
else if (checkDataType<DataTypeInt32>(read_type_not_null))
460-
{
461-
insertRangeFromWithNumericTypeCast<FromType, Int32>(
462-
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
463-
return true;
464-
}
465456
}
466457
else if (checkDataType<DataTypeUInt16>(disk_type_not_null))
467458
{
@@ -478,12 +469,6 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
478469
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
479470
return true;
480471
}
481-
else if (checkDataType<DataTypeUInt16>(read_type_not_null))
482-
{
483-
insertRangeFromWithNumericTypeCast<FromType, UInt16>(
484-
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
485-
return true;
486-
}
487472
}
488473
else if (checkDataType<DataTypeInt16>(disk_type_not_null))
489474
{
@@ -500,12 +485,6 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
500485
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
501486
return true;
502487
}
503-
else if (checkDataType<DataTypeInt16>(read_type_not_null))
504-
{
505-
insertRangeFromWithNumericTypeCast<FromType, Int16>(
506-
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
507-
return true;
508-
}
509488
}
510489
else if (checkDataType<DataTypeUInt8>(disk_type_not_null))
511490
{
@@ -528,12 +507,6 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
528507
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
529508
return true;
530509
}
531-
else if (checkDataType<DataTypeUInt8>(read_type_not_null))
532-
{
533-
insertRangeFromWithNumericTypeCast<FromType, UInt8>(
534-
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
535-
return true;
536-
}
537510
}
538511
else if (checkDataType<DataTypeInt8>(disk_type_not_null))
539512
{
@@ -556,12 +529,6 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
556529
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
557530
return true;
558531
}
559-
else if (checkDataType<DataTypeInt8>(read_type_not_null))
560-
{
561-
insertRangeFromWithNumericTypeCast<FromType, Int8>(
562-
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
563-
return true;
564-
}
565532
}
566533

567534
// else is not support

Diff for: dbms/src/Storages/DeltaMerge/HandleFilter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ inline Block filterUnsorted(const HandleRange & handle_range, Block && block, si
6262

6363
IColumn::Filter filter(rows);
6464
size_t passed_count = 0;
65-
for (size_t i = 0; i < rows - 1; ++i)
65+
for (size_t i = 0; i < rows; ++i)
6666
{
6767
bool ok = handle_range.check(handle_col_data[i]);
6868
filter[i] = ok;

Diff for: dbms/src/Storages/DeltaMerge/Segment.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ SegmentPtr Segment::flush(DMContext & dm_context)
369369
return new_me;
370370
}
371371

372-
void Segment::flushCache(DMContext &dm_context)
372+
void Segment::flushCache(DMContext & dm_context)
373373
{
374374
std::unique_lock lock(read_write_mutex);
375375
delta->tryFlushCache(OpContext::createForLogStorage(dm_context), /* force= */ true);
@@ -913,7 +913,14 @@ size_t Segment::estimatedRows()
913913
size_t Segment::estimatedBytes()
914914
{
915915
size_t stable_bytes = stable->num_bytes();
916-
return stable_bytes + delta->num_bytes() - (stable_bytes / stable->num_rows()) * delta_tree->numDeletes();
916+
if (stable->num_rows() == 0)
917+
{
918+
return stable_bytes + delta->num_bytes();
919+
}
920+
else
921+
{
922+
return stable_bytes + delta->num_bytes() - (stable_bytes / stable->num_rows()) * delta_tree->numDeletes();
923+
}
917924
}
918925

919926
} // namespace DM

Diff for: dbms/src/Storages/DeltaMerge/tests/gtest_dm_chunk.cpp

+100-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ DataTypePtr typeFromString(const String & str)
109109
TEST(ChunkColumnCast_test, CastNumeric)
110110
{
111111
{
112-
const Strings to_types = {"UInt16", "UInt32", "UInt64"};
112+
const Strings to_types = {"UInt8", "UInt16", "UInt32", "UInt64"};
113113

114114
DataTypePtr disk_data_type = typeFromString("UInt8");
115115
MutableColumnPtr disk_col = disk_data_type->createColumn();
@@ -133,7 +133,55 @@ TEST(ChunkColumnCast_test, CastNumeric)
133133
}
134134

135135
{
136-
const Strings to_types = {"Int16", "Int32", "Int64"};
136+
const Strings to_types = {"UInt16", "UInt32", "UInt64"};
137+
138+
DataTypePtr disk_data_type = typeFromString("UInt16");
139+
MutableColumnPtr disk_col = disk_data_type->createColumn();
140+
disk_col->insert(Field(UInt64(15)));
141+
disk_col->insert(Field(UInt64(255)));
142+
143+
for (const String & to_type : to_types)
144+
{
145+
DataTypePtr read_data_type = typeFromString(to_type);
146+
ColumnDefine read_define(0, "c", read_data_type);
147+
MutableColumnPtr memory_column = read_data_type->createColumn();
148+
memory_column->reserve(2);
149+
150+
castColumnAccordingToColumnDefine(disk_data_type, disk_col->getPtr(), read_define, memory_column->getPtr(), 0, 2);
151+
152+
UInt64 val1 = memory_column->getUInt(0);
153+
ASSERT_EQ(val1, 15UL);
154+
UInt64 val2 = memory_column->getUInt(1);
155+
ASSERT_EQ(val2, 255UL);
156+
}
157+
}
158+
159+
{
160+
const Strings to_types = {"UInt32", "UInt64"};
161+
162+
DataTypePtr disk_data_type = typeFromString("UInt32");
163+
MutableColumnPtr disk_col = disk_data_type->createColumn();
164+
disk_col->insert(Field(UInt64(15)));
165+
disk_col->insert(Field(UInt64(255)));
166+
167+
for (const String & to_type : to_types)
168+
{
169+
DataTypePtr read_data_type = typeFromString(to_type);
170+
ColumnDefine read_define(0, "c", read_data_type);
171+
MutableColumnPtr memory_column = read_data_type->createColumn();
172+
memory_column->reserve(2);
173+
174+
castColumnAccordingToColumnDefine(disk_data_type, disk_col->getPtr(), read_define, memory_column->getPtr(), 0, 2);
175+
176+
UInt64 val1 = memory_column->getUInt(0);
177+
ASSERT_EQ(val1, 15UL);
178+
UInt64 val2 = memory_column->getUInt(1);
179+
ASSERT_EQ(val2, 255UL);
180+
}
181+
}
182+
183+
{
184+
const Strings to_types = {"Int8", "Int16", "Int32", "Int64"};
137185

138186
DataTypePtr disk_data_type = typeFromString("Int8");
139187
MutableColumnPtr disk_col = disk_data_type->createColumn();
@@ -155,6 +203,54 @@ TEST(ChunkColumnCast_test, CastNumeric)
155203
ASSERT_EQ(val2, -1L);
156204
}
157205
}
206+
207+
{
208+
const Strings to_types = {"Int16", "Int32", "Int64"};
209+
210+
DataTypePtr disk_data_type = typeFromString("Int16");
211+
MutableColumnPtr disk_col = disk_data_type->createColumn();
212+
disk_col->insert(Field(Int64(127)));
213+
disk_col->insert(Field(Int64(-1)));
214+
215+
for (const String & to_type : to_types)
216+
{
217+
DataTypePtr read_data_type = typeFromString(to_type);
218+
ColumnDefine read_define(0, "c", read_data_type);
219+
MutableColumnPtr memory_column = read_data_type->createColumn();
220+
memory_column->reserve(2);
221+
222+
castColumnAccordingToColumnDefine(disk_data_type, disk_col->getPtr(), read_define, memory_column->getPtr(), 0, 2);
223+
224+
Int64 val1 = memory_column->getInt(0);
225+
ASSERT_EQ(val1, 127L);
226+
Int64 val2 = memory_column->getInt(1);
227+
ASSERT_EQ(val2, -1L);
228+
}
229+
}
230+
231+
{
232+
const Strings to_types = {"Int32", "Int64"};
233+
234+
DataTypePtr disk_data_type = typeFromString("Int32");
235+
MutableColumnPtr disk_col = disk_data_type->createColumn();
236+
disk_col->insert(Field(Int64(127)));
237+
disk_col->insert(Field(Int64(-1)));
238+
239+
for (const String & to_type : to_types)
240+
{
241+
DataTypePtr read_data_type = typeFromString(to_type);
242+
ColumnDefine read_define(0, "c", read_data_type);
243+
MutableColumnPtr memory_column = read_data_type->createColumn();
244+
memory_column->reserve(2);
245+
246+
castColumnAccordingToColumnDefine(disk_data_type, disk_col->getPtr(), read_define, memory_column->getPtr(), 0, 2);
247+
248+
Int64 val1 = memory_column->getInt(0);
249+
ASSERT_EQ(val1, 127L);
250+
Int64 val2 = memory_column->getInt(1);
251+
ASSERT_EQ(val2, -1L);
252+
}
253+
}
158254
}
159255

160256
TEST(ChunkColumnCast_test, CastNullableToNotNull)
@@ -216,7 +312,7 @@ TEST(ChunkColumnCast_test, DISABLED_CastNullableToNotNullWithNonZeroDefaultValue
216312

217313
TEST(ChunkColumnCast_test, CastNullableToNullable)
218314
{
219-
const Strings to_types = {"Nullable(Int16)", "Nullable(Int32)", "Nullable(Int64)"};
315+
const Strings to_types = {"Nullable(Int8)", "Nullable(Int16)", "Nullable(Int32)", "Nullable(Int64)"};
220316

221317
DataTypePtr disk_data_type = typeFromString("Nullable(Int8)");
222318
MutableColumnPtr disk_col = disk_data_type->createColumn();
@@ -251,7 +347,7 @@ TEST(ChunkColumnCast_test, CastNullableToNullable)
251347

252348
TEST(ChunkColumnCast_test, CastNotNullToNullable)
253349
{
254-
const Strings to_types = {"Nullable(Int16)", "Nullable(Int32)", "Nullable(Int64)"};
350+
const Strings to_types = {"Nullable(Int8)", "Nullable(Int16)", "Nullable(Int32)", "Nullable(Int64)"};
255351

256352
DataTypePtr disk_data_type = typeFromString("Int8");
257353
MutableColumnPtr disk_col = disk_data_type->createColumn();

0 commit comments

Comments
 (0)