aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/interface/protobuf_format.h
blob: aafbced38696b38c1fa2ca343f87983a6f5f8faa (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#pragma once

#include "common.h"

#include <yt/yt_proto/yt/formats/extension.pb.h>

#include <util/generic/maybe.h>

#include <google/protobuf/message.h>

/// @cond Doxygen_Suppress
namespace NYT::NDetail {

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

enum class EProtobufType
{
    EnumInt       /* "enum_int" */,
    EnumString    /* "enum_string" */,
    Any           /* "any" */,
    OtherColumns  /* "other_columns" */,
};

enum class EProtobufSerializationMode
{
    Protobuf,
    Yt,
    Embedded,
};

enum class EProtobufListMode
{
    Optional,
    Required,
};

enum class EProtobufMapMode
{
    ListOfStructsLegacy,
    ListOfStructs,
    Dict,
    OptionalDict,
};

enum class EProtobufFieldSortOrder
{
    AsInProtoFile,
    ByFieldNumber,
};

enum class EProtobufOneofMode
{
    SeparateFields,
    Variant,
};

enum class EProtobufEnumWritingMode
{
    SkipUnknownValues,
    CheckValues,
};

struct TProtobufOneofOptions
{
    EProtobufOneofMode Mode = EProtobufOneofMode::Variant;
    TString VariantFieldName;
};

struct TProtobufFieldOptions
{
    TMaybe<EProtobufType> Type;
    EProtobufSerializationMode SerializationMode = EProtobufSerializationMode::Protobuf;
    EProtobufListMode ListMode = EProtobufListMode::Required;
    EProtobufMapMode MapMode = EProtobufMapMode::ListOfStructsLegacy;
};

struct TProtobufMessageOptions
{
    EProtobufFieldSortOrder FieldSortOrder = EProtobufFieldSortOrder::ByFieldNumber;
};

TString GetColumnName(const ::google::protobuf::FieldDescriptor& field);

TProtobufFieldOptions GetFieldOptions(
    const ::google::protobuf::FieldDescriptor* fieldDescriptor,
    const TMaybe<TProtobufFieldOptions>& defaultFieldOptions = {});

TProtobufOneofOptions GetOneofOptions(
    const ::google::protobuf::OneofDescriptor* oneofDescriptor,
    const TMaybe<TProtobufOneofOptions>& defaultOneofOptions = {});

TProtobufMessageOptions GetMessageOptions(const ::google::protobuf::Descriptor* descriptor);

TMaybe<TVector<TString>> InferColumnFilter(const ::google::protobuf::Descriptor& descriptor);

TNode MakeProtoFormatConfigWithTables(const TVector<const ::google::protobuf::Descriptor*>& descriptors);
TNode MakeProtoFormatConfigWithDescriptors(const TVector<const ::google::protobuf::Descriptor*>& descriptors);

TTableSchema CreateTableSchemaImpl(
    const ::google::protobuf::Descriptor& messageDescriptor,
    bool keepFieldsWithoutExtension);

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

} // namespace NYT::NDetail
/// @endcond