Skip to content

Commit

Permalink
[FLASH-466] improve code coverage (pingcap#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
marsishandsome authored and JaySon-Huang committed Oct 18, 2019
1 parent 00219bb commit 4f57898
Show file tree
Hide file tree
Showing 13 changed files with 849 additions and 339 deletions.
4 changes: 2 additions & 2 deletions dbms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ if (TEST_COVERAGE AND CMAKE_BUILD_TYPE STREQUAL "Debug")
)
SETUP_TARGET_FOR_COVERAGE_GCOVR_HTML(
NAME tiflash_gcovr_coverage
DEPENDENCIES unit_tests_dbms
EXECUTABLE unit_tests_dbms
DEPENDENCIES gtests_dbms
EXECUTABLE gtests_dbms
)
endif()
39 changes: 3 additions & 36 deletions dbms/src/Storages/DeltaMerge/Chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
assert(!disk_type_not_null->isNullable());
assert(!read_type_not_null->isNullable());

/// Caller should ensure that dist_type != read_type
assert(!disk_type_not_null->equals(*read_type_not_null));

if (checkDataType<DataTypeUInt32>(disk_type_not_null))
{
using FromType = UInt32;
Expand All @@ -440,12 +443,6 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
return true;
}
else if (checkDataType<DataTypeUInt32>(read_type_not_null))
{
insertRangeFromWithNumericTypeCast<FromType, UInt32>(
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
return true;
}
}
else if (checkDataType<DataTypeInt32>(disk_type_not_null))
{
Expand All @@ -456,12 +453,6 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
return true;
}
else if (checkDataType<DataTypeInt32>(read_type_not_null))
{
insertRangeFromWithNumericTypeCast<FromType, Int32>(
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
return true;
}
}
else if (checkDataType<DataTypeUInt16>(disk_type_not_null))
{
Expand All @@ -478,12 +469,6 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
return true;
}
else if (checkDataType<DataTypeUInt16>(read_type_not_null))
{
insertRangeFromWithNumericTypeCast<FromType, UInt16>(
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
return true;
}
}
else if (checkDataType<DataTypeInt16>(disk_type_not_null))
{
Expand All @@ -500,12 +485,6 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
return true;
}
else if (checkDataType<DataTypeInt16>(read_type_not_null))
{
insertRangeFromWithNumericTypeCast<FromType, Int16>(
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
return true;
}
}
else if (checkDataType<DataTypeUInt8>(disk_type_not_null))
{
Expand All @@ -528,12 +507,6 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
return true;
}
else if (checkDataType<DataTypeUInt8>(read_type_not_null))
{
insertRangeFromWithNumericTypeCast<FromType, UInt8>(
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
return true;
}
}
else if (checkDataType<DataTypeInt8>(disk_type_not_null))
{
Expand All @@ -556,12 +529,6 @@ bool castNonNullNumericColumn(const DataTypePtr & disk_type_not_null_,
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
return true;
}
else if (checkDataType<DataTypeInt8>(read_type_not_null))
{
insertRangeFromWithNumericTypeCast<FromType, Int8>(
disk_col_not_null, null_map, read_define, memory_col_not_null, rows_offset, rows_limit);
return true;
}
}

// else is not support
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/DeltaMerge/HandleFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ inline Block filterUnsorted(const HandleRange & handle_range, Block && block, si

IColumn::Filter filter(rows);
size_t passed_count = 0;
for (size_t i = 0; i < rows - 1; ++i)
for (size_t i = 0; i < rows; ++i)
{
bool ok = handle_range.check(handle_col_data[i]);
filter[i] = ok;
Expand Down
11 changes: 9 additions & 2 deletions dbms/src/Storages/DeltaMerge/Segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ SegmentPtr Segment::flush(DMContext & dm_context)
return new_me;
}

void Segment::flushCache(DMContext &dm_context)
void Segment::flushCache(DMContext & dm_context)
{
std::unique_lock lock(read_write_mutex);
delta->tryFlushCache(OpContext::createForLogStorage(dm_context), /* force= */ true);
Expand Down Expand Up @@ -913,7 +913,14 @@ size_t Segment::estimatedRows()
size_t Segment::estimatedBytes()
{
size_t stable_bytes = stable->num_bytes();
return stable_bytes + delta->num_bytes() - (stable_bytes / stable->num_rows()) * delta_tree->numDeletes();
if (stable->num_rows() == 0)
{
return stable_bytes + delta->num_bytes();
}
else
{
return stable_bytes + delta->num_bytes() - (stable_bytes / stable->num_rows()) * delta_tree->numDeletes();
}
}

} // namespace DM
Expand Down
104 changes: 100 additions & 4 deletions dbms/src/Storages/DeltaMerge/tests/gtest_dm_chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ DataTypePtr typeFromString(const String & str)
TEST(ChunkColumnCast_test, CastNumeric)
{
{
const Strings to_types = {"UInt16", "UInt32", "UInt64"};
const Strings to_types = {"UInt8", "UInt16", "UInt32", "UInt64"};

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

{
const Strings to_types = {"Int16", "Int32", "Int64"};
const Strings to_types = {"UInt16", "UInt32", "UInt64"};

DataTypePtr disk_data_type = typeFromString("UInt16");
MutableColumnPtr disk_col = disk_data_type->createColumn();
disk_col->insert(Field(UInt64(15)));
disk_col->insert(Field(UInt64(255)));

for (const String & to_type : to_types)
{
DataTypePtr read_data_type = typeFromString(to_type);
ColumnDefine read_define(0, "c", read_data_type);
MutableColumnPtr memory_column = read_data_type->createColumn();
memory_column->reserve(2);

castColumnAccordingToColumnDefine(disk_data_type, disk_col->getPtr(), read_define, memory_column->getPtr(), 0, 2);

UInt64 val1 = memory_column->getUInt(0);
ASSERT_EQ(val1, 15UL);
UInt64 val2 = memory_column->getUInt(1);
ASSERT_EQ(val2, 255UL);
}
}

{
const Strings to_types = {"UInt32", "UInt64"};

DataTypePtr disk_data_type = typeFromString("UInt32");
MutableColumnPtr disk_col = disk_data_type->createColumn();
disk_col->insert(Field(UInt64(15)));
disk_col->insert(Field(UInt64(255)));

for (const String & to_type : to_types)
{
DataTypePtr read_data_type = typeFromString(to_type);
ColumnDefine read_define(0, "c", read_data_type);
MutableColumnPtr memory_column = read_data_type->createColumn();
memory_column->reserve(2);

castColumnAccordingToColumnDefine(disk_data_type, disk_col->getPtr(), read_define, memory_column->getPtr(), 0, 2);

UInt64 val1 = memory_column->getUInt(0);
ASSERT_EQ(val1, 15UL);
UInt64 val2 = memory_column->getUInt(1);
ASSERT_EQ(val2, 255UL);
}
}

{
const Strings to_types = {"Int8", "Int16", "Int32", "Int64"};

DataTypePtr disk_data_type = typeFromString("Int8");
MutableColumnPtr disk_col = disk_data_type->createColumn();
Expand All @@ -155,6 +203,54 @@ TEST(ChunkColumnCast_test, CastNumeric)
ASSERT_EQ(val2, -1L);
}
}

{
const Strings to_types = {"Int16", "Int32", "Int64"};

DataTypePtr disk_data_type = typeFromString("Int16");
MutableColumnPtr disk_col = disk_data_type->createColumn();
disk_col->insert(Field(Int64(127)));
disk_col->insert(Field(Int64(-1)));

for (const String & to_type : to_types)
{
DataTypePtr read_data_type = typeFromString(to_type);
ColumnDefine read_define(0, "c", read_data_type);
MutableColumnPtr memory_column = read_data_type->createColumn();
memory_column->reserve(2);

castColumnAccordingToColumnDefine(disk_data_type, disk_col->getPtr(), read_define, memory_column->getPtr(), 0, 2);

Int64 val1 = memory_column->getInt(0);
ASSERT_EQ(val1, 127L);
Int64 val2 = memory_column->getInt(1);
ASSERT_EQ(val2, -1L);
}
}

{
const Strings to_types = {"Int32", "Int64"};

DataTypePtr disk_data_type = typeFromString("Int32");
MutableColumnPtr disk_col = disk_data_type->createColumn();
disk_col->insert(Field(Int64(127)));
disk_col->insert(Field(Int64(-1)));

for (const String & to_type : to_types)
{
DataTypePtr read_data_type = typeFromString(to_type);
ColumnDefine read_define(0, "c", read_data_type);
MutableColumnPtr memory_column = read_data_type->createColumn();
memory_column->reserve(2);

castColumnAccordingToColumnDefine(disk_data_type, disk_col->getPtr(), read_define, memory_column->getPtr(), 0, 2);

Int64 val1 = memory_column->getInt(0);
ASSERT_EQ(val1, 127L);
Int64 val2 = memory_column->getInt(1);
ASSERT_EQ(val2, -1L);
}
}
}

TEST(ChunkColumnCast_test, CastNullableToNotNull)
Expand Down Expand Up @@ -216,7 +312,7 @@ TEST(ChunkColumnCast_test, DISABLED_CastNullableToNotNullWithNonZeroDefaultValue

TEST(ChunkColumnCast_test, CastNullableToNullable)
{
const Strings to_types = {"Nullable(Int16)", "Nullable(Int32)", "Nullable(Int64)"};
const Strings to_types = {"Nullable(Int8)", "Nullable(Int16)", "Nullable(Int32)", "Nullable(Int64)"};

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

TEST(ChunkColumnCast_test, CastNotNullToNullable)
{
const Strings to_types = {"Nullable(Int16)", "Nullable(Int32)", "Nullable(Int64)"};
const Strings to_types = {"Nullable(Int8)", "Nullable(Int16)", "Nullable(Int32)", "Nullable(Int64)"};

DataTypePtr disk_data_type = typeFromString("Int8");
MutableColumnPtr disk_col = disk_data_type->createColumn();
Expand Down
Loading

0 comments on commit 4f57898

Please sign in to comment.