Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLASH-466] improve code coverage #219

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dbms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,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()
36 changes: 0 additions & 36 deletions dbms/src/Storages/DeltaMerge/Chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,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))
marsishandsome marked this conversation as resolved.
Show resolved Hide resolved
{
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 +450,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 +466,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 +482,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 +504,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 +526,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