diff options
author | bulatman <bulatman@yandex-team.com> | 2023-10-25 16:54:09 +0300 |
---|---|---|
committer | bulatman <bulatman@yandex-team.com> | 2023-10-25 17:34:07 +0300 |
commit | c79726a5aedde9c9a148a5e5442bfe0b3821a84d (patch) | |
tree | c4f62e51d4222916b69ffc72dd2876ae30b9ff45 | |
parent | 4ab894e832e544c1d970615cccaa03d1d8dadf57 (diff) | |
download | ydb-c79726a5aedde9c9a148a5e5442bfe0b3821a84d.tar.gz |
YT: Support literal aliases in protobuf enum interop
-rw-r--r-- | yt/yt/core/yson/protobuf_interop.cpp | 7 | ||||
-rw-r--r-- | yt/yt/core/yson/unittests/proto/protobuf_yson_ut.proto | 1 | ||||
-rw-r--r-- | yt/yt/core/yson/unittests/protobuf_yson_ut.cpp | 1 |
3 files changed, 6 insertions, 3 deletions
diff --git a/yt/yt/core/yson/protobuf_interop.cpp b/yt/yt/core/yson/protobuf_interop.cpp index 6cd80f3689..6df2d4854d 100644 --- a/yt/yt/core/yson/protobuf_interop.cpp +++ b/yt/yt/core/yson/protobuf_interop.cpp @@ -657,10 +657,11 @@ public: for (int index = 0; index < Underlying_->value_count(); ++index) { const auto* valueDescriptor = Underlying_->value(index); auto literal = Registry_->GetYsonLiteral(valueDescriptor); - YT_VERIFY(LiteralToValue_.emplace(literal, valueDescriptor->number()).second); - // Allow aliases, i.e. different literals for the same tag, which can be helpful during migration. + int number = valueDescriptor->number(); + // Allow aliases, i.e. different literals for the same tag or same literal for different tags. // The first literal is selected as canonical for each tag. - ValueToLiteral_.try_emplace(valueDescriptor->number(), literal); + YT_VERIFY(LiteralToValue_.try_emplace(literal, number).first->second == number); + ValueToLiteral_.try_emplace(number, literal); } } diff --git a/yt/yt/core/yson/unittests/proto/protobuf_yson_ut.proto b/yt/yt/core/yson/unittests/proto/protobuf_yson_ut.proto index db781c9b12..3ca0813ce5 100644 --- a/yt/yt/core/yson/unittests/proto/protobuf_yson_ut.proto +++ b/yt/yt/core/yson/unittests/proto/protobuf_yson_ut.proto @@ -20,6 +20,7 @@ enum EFlag Flag_No = 0 [(NYT.NYson.NProto.enum_value_name) = "no"]; Flag_True = 1 [(NYT.NYson.NProto.enum_value_name) = "true"]; Flag_Yes = 1 [(NYT.NYson.NProto.enum_value_name) = "yes"]; + Flag_AnotherYes = 1 [(NYT.NYson.NProto.enum_value_name) = "yes"]; } message TNestedMessage diff --git a/yt/yt/core/yson/unittests/protobuf_yson_ut.cpp b/yt/yt/core/yson/unittests/protobuf_yson_ut.cpp index dd76e05e7a..2719f939a2 100644 --- a/yt/yt/core/yson/unittests/protobuf_yson_ut.cpp +++ b/yt/yt/core/yson/unittests/protobuf_yson_ut.cpp @@ -2211,6 +2211,7 @@ TEST(TProtobufEnums, FindLiteralByValueWithAlias) static const auto* type = ReflectProtobufEnumType(NYT::NYson::NProto::EFlag_descriptor()); ASSERT_EQ("true", FindProtobufEnumLiteralByValue(type, NYT::NYson::NProto::Flag_True)); ASSERT_EQ("true", FindProtobufEnumLiteralByValue(type, NYT::NYson::NProto::Flag_Yes)); + ASSERT_EQ("true", FindProtobufEnumLiteralByValue(type, NYT::NYson::NProto::Flag_AnotherYes)); } TEST(TProtobufEnums, ConvertToProtobufEnumValueUntyped) |