Newer versions can't clear columns which are used in default expressions for other columns. Maybe it's caused by https://github.com/ClickHouse/ClickHouse/issues/6913

CH version 20.5.2


create database Temp;
create table Temp.Test (`impression_id` String,`impression_id_compressed` FixedString(16) DEFAULT UUIDStringToNum(substring(impression_id, 1, 36)), `impression_id_hashed` UInt16 DEFAULT reinterpretAsUInt16(impression_id_compressed), `event_date` Date ) ENGINE = MergeTree(event_date, impression_id_hashed, (event_date, impression_id_hashed), 8192);
alter table Temp.Test clear column `impression_id` in partition '202001';


Received exception from server (version 20.5.2):
Code: 44. DB::Exception: Received from ch7r1.local:9000. DB::Exception: Cannot drop column `impression_id`, because column `impression_id_compressed` depends on it. 




Older versions (tested with 19.17.4 and 20.3.5):

CREATE DATABASE Temp;
create table Temp.Test (`impression_id` String,`impression_id_compressed` FixedString(16) DEFAULT UUIDStringToNum(substring(impression_id, 1, 36)), `impression_id_hashed` UInt16 DEFAULT reinterpretAsUInt16(impression_id_compressed), `event_date` Date ) ENGINE = MergeTree(event_date, impression_id_hashed, (event_date, impression_id_hashed), 8192);
alter table Temp.Test clear column `impression_id` in partition '202001';

ALTER TABLE Temp.Test
    CLEAR COLUMN impression_id     IN PARTITION '202001'


Ok.

metadata_copy.sorting_key.recalculateWithNewAST(metadata_copy.sorting_key.definition_ast, metadata_copy.columns, context);
    if (metadata_copy.primary_key.definition_ast != nullptr)
    {
        metadata_copy.primary_key.recalculateWithNewAST(metadata_copy.primary_key.definition_ast, metadata_copy.columns, context);
    }
    else
    {
        metadata_copy.primary_key = KeyDescription::getKeyFromAST(metadata_copy.sorting_key.definition_ast, metadata_copy.columns, context);
        metadata_copy.primary_key.definition_ast = nullptr;
    }
    
    if (metadata_copy.partition_key.definition_ast != nullptr)
        metadata_copy.partition_key.recalculateWithNewAST(metadata_copy.partition_key.definition_ast, metadata_copy.columns, context);
    
    for (auto & index : metadata_copy.secondary_indices)
        index = IndexDescription::getIndexFromAST(index.definition_ast, metadata_copy.columns, context);
    
    auto column_ttl_asts = metadata_copy.columns.getColumnTTLs();
    for (const auto & [name, ast] : column_ttl_asts)
    {
        auto new_ttl_entry = TTLDescription::getTTLFromAST(ast, metadata_copy.columns, context, metadata_copy.primary_key);
        metadata_copy.column_ttls_by_name[name] = new_ttl_entry;
    }
    if (metadata_copy.table_ttl.definition_ast != nullptr)
        metadata.table_ttl = TTLTableDescription::getTTLForTableFromAST(
            metadata_copy.table_ttl.definition_ast, metadata_copy.columns, context, metadata_copy.primary_key);
    metadata = std::move(metadata_copy);
}
void AlterCommands::prepare(const StorageInMemoryMetadata & metadata)