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

Code before:
bool YTsaurusClient::checkSchemaCompatibility(const String & table_path, const SharedHeader & sample_block, String & reason, bool allow_nullable)
{
    auto yt_schema = getTableSchema(table_path);

    if (!yt_schema.is_strict)
        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())
        client->commitTx(transaction_id);
}

}

Review comment (suggestion):
```suggestion
size_t YTsaurusClient::getTableNumberOfRows(const String & table_path)
```

Code after:
        yt_columns.insert({std::move(yt_column_name), data_type});
    }
    return {true, std::move(yt_columns)};
}

bool YTsaurusClient::checkSchemaCompatibility(const String & table_path, const SharedHeader & sample_block, String & reason, bool allow_nullable)
{
    auto yt_schema = getTableSchema(table_path);

    if (!yt_schema.is_strict)
        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()
{