Add test for already working code

This commit is contained in:
alesapin 2020-12-23 14:53:49 +03:00
parent ddfe9f61e0
commit 54455b4740
2 changed files with 33 additions and 0 deletions

View File

@ -549,6 +549,13 @@ CompressionCodecPtr IMergeTreeDataPart::detectDefaultCompressionCodec() const
auto column_size = getColumnSize(part_column.name, *part_column.type);
if (column_size.data_compressed != 0 && !storage_columns.hasCompressionCodec(part_column.name))
{
String path_to_data_file = getFullRelativePath() + getFileNameForColumn(part_column) + ".bin";
if (!volume->getDisk()->exists(path_to_data_file))
{
LOG_WARNING(storage.log, "Part's {} column {} has non zero data compressed size, but data file {} doesn't exists", name, backQuoteIfNeed(part_column.name), path_to_data_file);
continue;
}
result = getCompressionCodecForFile(volume->getDisk(), getFullRelativePath() + getFileNameForColumn(part_column) + ".bin");
break;
}

View File

@ -9,6 +9,7 @@ cluster = ClickHouseCluster(__file__)
node1 = cluster.add_instance('node1', main_configs=['configs/default_compression.xml', 'configs/wide_parts_only.xml'], with_zookeeper=True)
node2 = cluster.add_instance('node2', main_configs=['configs/default_compression.xml', 'configs/wide_parts_only.xml'], with_zookeeper=True)
node3 = cluster.add_instance('node3', main_configs=['configs/default_compression.xml', 'configs/wide_parts_only.xml'], image='yandex/clickhouse-server', tag='20.3.16', stay_alive=True, with_installed_binary=True)
node4 = cluster.add_instance('node4')
@pytest.fixture(scope="module")
def start_cluster():
@ -228,3 +229,28 @@ def test_default_codec_version_update(start_cluster):
"SELECT default_compression_codec FROM system.parts WHERE table = 'compression_table' and name = '2_2_2_1'") == "LZ4HC(5)\n"
assert node3.query(
"SELECT default_compression_codec FROM system.parts WHERE table = 'compression_table' and name = '3_3_3_1'") == "LZ4\n"
def test_default_codec_for_compact_parts(start_cluster):
node4.query("""
CREATE TABLE compact_parts_table (
key UInt64,
data String
)
ENGINE MergeTree ORDER BY tuple()
""")
node4.query("INSERT INTO compact_parts_table VALUES (1, 'Hello world')")
assert node4.query("SELECT COUNT() FROM compact_parts_table") == "1\n"
node4.query("ALTER TABLE compact_parts_table DETACH PART 'all_1_1_0'")
node4.exec_in_container(["bash", "-c", "rm /var/lib/clickhouse/data/default/compact_parts_table/detached/all_1_1_0/default_compression_codec.txt"])
node4.query("ALTER TABLE compact_parts_table ATTACH PART 'all_1_1_0'")
assert node4.query("SELECT COUNT() FROM compact_parts_table") == "1\n"
node4.query("DETACH TABLE compact_parts_table")
node4.query("ATTACH TABLE compact_parts_table")
assert node4.query("SELECT COUNT() FROM compact_parts_table") == "1\n"