aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Storages/MergeTree/PinnedPartUUIDs.cpp
blob: 1302d492c8cdf9311206b3e8f248f85b325bdf26 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "PinnedPartUUIDs.h"
#include <IO/ReadHelpers.h>
#include <IO/WriteHelpers.h>
#include <Poco/JSON/JSON.h>
#include <Poco/JSON/Object.h>
#include <Poco/JSON/Parser.h>

namespace DB
{

String PinnedPartUUIDs::toString() const
{
    std::vector<UUID> vec(part_uuids.begin(), part_uuids.end());

    Poco::JSON::Object json;
    json.set(JSON_KEY_UUIDS, DB::toString(vec));

    std::ostringstream oss; // STYLE_CHECK_ALLOW_STD_STRING_STREAM
    oss.exceptions(std::ios::failbit);
    json.stringify(oss);

    return oss.str();
}

void PinnedPartUUIDs::fromString(const String & buf)
{
    Poco::JSON::Parser parser;
    auto json = parser.parse(buf).extract<Poco::JSON::Object::Ptr>();

    std::vector<UUID> vec = parseFromString<std::vector<UUID>>(json->getValue<std::string>(PinnedPartUUIDs::JSON_KEY_UUIDS));

    part_uuids.clear();
    std::copy(vec.begin(), vec.end(), std::inserter(part_uuids, part_uuids.begin()));
}

}