aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/io/proto_table_writer.h
blob: 532cf3302bd0cfa3c5926fcb142ce7fab1ca4e07 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once

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

namespace NYT {

class IProxyOutput;
class TNodeTableWriter;

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

class TProtoTableWriter
    : public IProtoWriterImpl
{
public:
    TProtoTableWriter(
        THolder<IProxyOutput> output,
        TVector<const ::google::protobuf::Descriptor*>&& descriptors);
    ~TProtoTableWriter() override;

    void AddRow(const Message& row, size_t tableIndex) override;
    void AddRow(Message&& row, size_t tableIndex) override;

    size_t GetBufferMemoryUsage() const override;
    size_t GetTableCount() const override;
    void FinishTable(size_t) override;
    void Abort() override;

private:
    THolder<TNodeTableWriter> NodeWriter_;
    TVector<const ::google::protobuf::Descriptor*> Descriptors_;
};

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

class TLenvalProtoTableWriter
    : public IProtoWriterImpl
{
public:
    TLenvalProtoTableWriter(
        THolder<IProxyOutput> output,
        TVector<const ::google::protobuf::Descriptor*>&& descriptors);
    ~TLenvalProtoTableWriter() override;

    void AddRow(const Message& row, size_t tableIndex) override;
    void AddRow(Message&& row, size_t tableIndex) override;

    size_t GetBufferMemoryUsage() const override;
    size_t GetTableCount() const override;
    void FinishTable(size_t) override;
    void Abort() override;

protected:
    THolder<IProxyOutput> Output_;
    TVector<const ::google::protobuf::Descriptor*> Descriptors_;
};

/// [Deprecated] Create TNode from protobuf message
///
/// @deprecated This function works only in simple cases. On nontrivial messages its interpretation
/// of protobuf messages might significantly differ from YT interpretation.
///
/// This function doesn't support composite types and many attributes supported by protobuf Reader/Writer.
TNode MakeNodeFromMessage(const ::google::protobuf::Message& row);

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

class TLenvalProtoSingleTableWriter
    : public TLenvalProtoTableWriter
{
public:
    TLenvalProtoSingleTableWriter(
        THolder<IProxyOutput> output,
        const ::google::protobuf::Descriptor* descriptor);
    ~TLenvalProtoSingleTableWriter() override = default;

    void AddRow(const Message& row, size_t tableIndex) override;
};

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

} // namespace NYT