aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/tests/yt_unittest_lib/yt_unittest_lib-inl.h
blob: 084db72d01e799a8f780b448cbdfb2731debeff0 (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
37
#pragma once

#ifndef YT_UNITTEST_LIB_H_
#error "Direct inclusion of this file is not allowed, use yt_unittest_lib.h"
#endif
#undef YT_UNITTEST_LIB_H_

#include <yt/cpp/mapreduce/interface/client.h>

namespace NYT::NTesting {

////////////////////////////////////////////////////////////////////////////////

template <class TMessage>
TVector<TMessage> ReadProtoTable(const IClientBasePtr& client, const TString& tablePath)
{
    TVector<TMessage> result;
    auto reader = client->CreateTableReader<TMessage>(tablePath);
    for (; reader->IsValid(); reader->Next()) {
        result.push_back(reader->GetRow());
    }
    return result;
}

template <class TMessage>
void WriteProtoTable(const IClientBasePtr& client, const TString& tablePath, const std::vector<TMessage>& rowList)
{
    auto writer = client->CreateTableWriter<TMessage>(tablePath);
    for (const auto& row : rowList) {
        writer->AddRow(row);
    }
    writer->Finish();
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::Testing