aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/io/yamr_table_writer.cpp
blob: cce7ceb0f0b6f772d877dda97dddcc31352d2a6a (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "yamr_table_writer.h"

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

namespace NYT {

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

TYaMRTableWriter::TYaMRTableWriter(THolder<IProxyOutput> output)
    : Output_(std::move(output))
{ }

TYaMRTableWriter::~TYaMRTableWriter()
{ }

size_t TYaMRTableWriter::GetTableCount() const
{
    return Output_->GetStreamCount();
}

void TYaMRTableWriter::FinishTable(size_t tableIndex) {
    Output_->GetStream(tableIndex)->Finish();
}

void TYaMRTableWriter::AddRow(const TYaMRRow& row, size_t tableIndex)
{
    auto* stream = Output_->GetStream(tableIndex);

    auto writeField = [&stream] (const TStringBuf& field) {
        i32 length = static_cast<i32>(field.length());
        stream->Write(&length, sizeof(length));
        stream->Write(field.data(), field.length());
    };

    writeField(row.Key);
    writeField(row.SubKey);
    writeField(row.Value);

    Output_->OnRowFinished(tableIndex);
}

void TYaMRTableWriter::AddRow(TYaMRRow&& row, size_t tableIndex) {
    TYaMRTableWriter::AddRow(row, tableIndex);
}

void TYaMRTableWriter::Abort()
{
    Output_->Abort();
}

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

} // namespace NYT