Repository: ClickHouse/ClickHouse
File: src/Core/YTsaurus/YTsaurusClient.cpp (C++)

Code before:
        if (iter == yt_schema.columns.end())
        {
            reason = fmt::format("There are no column with name {} in YtSaurus table", column_type_with_name.name);
            return false;
        }
        auto yt_column_type = iter->second;
        if (!isYTSaurusTypesCompatible(column_type_with_name.type, yt_column_type, allow_nullable))
        {
            reason = fmt::format("Column {} types mismatch. YtSaurus converted type {} table column type {}", column_type_with_name.name, yt_column_type->getName(), column_type_with_name.type->getName());
            return false;
        }
    }
    return true;
}

size_t YTsaurusClient::getTableNumberOfRows(const String& table_path)
{
    String lock_metadata_path = fmt::format("{}/@row_count", table_path);
    YTsaurusQueryPtr get_query(new YTsaurusGetQuery(lock_metadata_path));
    auto read_buff = executeQuery(get_query);
    size_t row_count;
    DB::readIntText(row_count, *read_buff);
    return row_count;
}

YTsaurusTableLock::YTsaurusTableLock(YTsaurusClientPtr client_, const String& cypress_path_, size_t transaction_timeout_ms)
    : client(client_)
{
    transaction_id = client->startTx(transaction_timeout_ms);
    lock_id = client->lock(cypress_path_, transaction_id);
    auto node_id = client->getNodeIdFromLock(lock_id);
    node_cypress_path = fmt::format("#{}",node_id);
}

YTsaurusTableLock::~YTsaurusTableLock()
{
    if (!transaction_id.empty())
        client->commitTx(transaction_id);
}

}
#endif


Review comment (suggestion):
```suggestion
YTsaurusTableLock::YTsaurusTableLock(YTsaurusClientPtr client_, const String & cypress_path_, size_t transaction_timeout_ms)
```

Code after:
        return true;

    for (const auto & column_type_with_name : sample_block->getColumnsWithTypeAndName())
    {
        auto iter = yt_schema.columns.find(column_type_with_name.name);
        if (iter == yt_schema.columns.end())
        {
            reason = fmt::format("There are no column with name {} in YtSaurus table", column_type_with_name.name);
            return false;
        }
        auto yt_column_type = iter->second;
        if (!isYTSaurusTypesCompatible(column_type_with_name.type, yt_column_type, allow_nullable))
        {
            reason = fmt::format("Column {} types mismatch. YtSaurus converted type {} table column type {}", column_type_with_name.name, yt_column_type->getName(), column_type_with_name.type->getName());
            return false;
        }
    }
    return true;
}

size_t YTsaurusClient::getTableNumberOfRows(const String & table_path)
{
    String lock_metadata_path = fmt::format("{}/@row_count", table_path);
    YTsaurusQueryPtr get_query(new YTsaurusGetQuery(lock_metadata_path));
    auto read_buff = executeQuery(get_query);
    size_t row_count;
    DB::readIntText(row_count, *read_buff);
    return row_count;
}

YTsaurusTableLock::YTsaurusTableLock(YTsaurusClientPtr client_, const String & cypress_path_, size_t transaction_timeout_ms)
    : client(client_)
{
    transaction_id = client->startTx(transaction_timeout_ms);
    lock_id = client->lock(cypress_path_, transaction_id);
    auto node_id = client->getNodeIdFromLock(lock_id);
    node_cypress_path = fmt::format("#{}",node_id);
}

YTsaurusTableLock::~YTsaurusTableLock()
{
    if (!transaction_id.empty())
    {
        try {
            client->commitTx(transaction_id);
        }
        catch (Exception & e)
        {
            LOG_WARNING(getLogger("YTsaurusTableLock"), "Can't commit transaction {}. Leave it. Exception: {}",
                transaction_id, e.displayText());
        }