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

Code before:
void YTsaurusClient::commitTx(const String& transaction_id)
{
    YTsaurusQueryPtr commit_tx_query(new YTsaurusCommitTxQuery(transaction_id));
    executeQuery(commit_tx_query);
}

String YTsaurusClient::lock(const String& cypress_path, const String& transaction_id)
{
    YTsaurusQueryPtr lock_query(new YTsaurusLockQuery(cypress_path, transaction_id));
    auto read_buff = executeQuery(lock_query);
    String res;
    // Generally the result of each YTsaurus query should be json.
    // But... for start_tx query the result always doble quoted string.
    readDoubleQuotedString(res, *read_buff);
    return res;
}

String YTsaurusClient::getNodeIdFromLock(const String & lock_id)
{

    String lock_metadata_path = fmt::format("{}/{}/@node_id", LOCKS_STORAGE_CYPRESS_PATH, lock_id);
    YTsaurusQueryPtr get_query(new YTsaurusGetQuery(lock_metadata_path));
    auto read_buff = executeQuery(get_query);
    String res;
    readDoubleQuotedString(res, *read_buff);
    return res;
}

YTsaurusNodeType YTsaurusClient::getNodeType(const String & cypress_path)
{
    auto json_ptr = getNodeMetadata(cypress_path);
    return getNodeTypeFromAttributes(json_ptr);
}


YTsaurusNodeType YTsaurusClient::getNodeTypeFromAttributes(const Poco::JSON::Object::Ptr & json_ptr)
{
    if (!json_ptr->has("type"))
        throw Exception(ErrorCodes::INCORRECT_DATA, "Incorrect json with yt attributes, no field 'type'.");

    if (json_ptr->getValue<String>("type") == "table" || json_ptr->getValue<String>("type") == "replicated_table")
    {
        if (!json_ptr->has("dynamic"))
            throw Exception(ErrorCodes::INCORRECT_DATA, "Incorrect json with yt attributes, no field 'dynamic'.");

        return json_ptr->getValue<bool>("dynamic") ? YTsaurusNodeType::DYNAMIC_TABLE : YTsaurusNodeType::STATIC_TABLE;
    }
    else
    {
        return YTsaurusNodeType::ANOTHER;
    }

Review comment (suggestion):
```suggestion
{
    String lock_metadata_path = fmt::format("{}/{}/@node_id", LOCKS_STORAGE_CYPRESS_PATH, lock_id);
```

Code after:
    // Generally the result of each YTsaurus query should be json.
    // But... for start_tx query the result always double quoted string.
    readDoubleQuotedString(res, *read_buff);
    return res;
}

void YTsaurusClient::commitTx(const String & transaction_id)
{
    YTsaurusQueryPtr commit_tx_query(new YTsaurusCommitTxQuery(transaction_id));
    executeQuery(commit_tx_query);
}

String YTsaurusClient::lock(const String & cypress_path, const String & transaction_id)
{
    YTsaurusQueryPtr lock_query(new YTsaurusLockQuery(cypress_path, transaction_id));
    auto read_buff = executeQuery(lock_query);
    String res;
    // Generally the result of each YTsaurus query should be json.
    // But... for start_tx query the result always double quoted string.
    readDoubleQuotedString(res, *read_buff);
    return res;
}

String YTsaurusClient::getNodeIdFromLock(const String & lock_id)
{
    String lock_metadata_path = fmt::format("{}/{}/@node_id", LOCKS_STORAGE_CYPRESS_PATH, lock_id);
    YTsaurusQueryPtr get_query(new YTsaurusGetQuery(lock_metadata_path));
    auto read_buff = executeQuery(get_query);
    String res;
    readDoubleQuotedString(res, *read_buff);
    return res;
}

YTsaurusNodeType YTsaurusClient::getNodeType(const String & cypress_path)
{
    auto json_ptr = getNodeMetadata(cypress_path);
    return getNodeTypeFromAttributes(json_ptr);
}


YTsaurusNodeType YTsaurusClient::getNodeTypeFromAttributes(const Poco::JSON::Object::Ptr & json_ptr)
{
    if (!json_ptr->has("type"))
        throw Exception(ErrorCodes::INCORRECT_DATA, "Incorrect json with yt attributes, no field 'type'.");

    if (json_ptr->getValue<String>("type") == "table" || json_ptr->getValue<String>("type") == "replicated_table")
    {
        if (!json_ptr->has("dynamic"))
            throw Exception(ErrorCodes::INCORRECT_DATA, "Incorrect json with yt attributes, no field 'dynamic'.");

        return json_ptr->getValue<bool>("dynamic") ? YTsaurusNodeType::DYNAMIC_TABLE : YTsaurusNodeType::STATIC_TABLE;