aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgrigminakov <grigminakov@yandex-team.com>2023-08-30 19:02:55 +0300
committergrigminakov <grigminakov@yandex-team.com>2023-08-30 19:19:13 +0300
commitb71f43754a0f3586be618e1913e4d3632c413e17 (patch)
tree0fe0a64a6b402e8959edf8ec44d0569f51d5dae7
parent87c0c1a041ba727af4306729d692554f251a2aa0 (diff)
downloadydb-b71f43754a0f3586be618e1913e4d3632c413e17.tar.gz
YT-19872: Store protobuf scalar element type
Added typing support
-rw-r--r--yt/yt/core/yson/protobuf_interop.cpp4
-rw-r--r--yt/yt/core/yson/protobuf_interop.h2
-rw-r--r--yt/yt/core/yson/unittests/proto/protobuf_scalar_type_ut.proto49
-rw-r--r--yt/yt/core/yson/unittests/protobuf_scalar_type_ut.cpp189
-rw-r--r--yt/yt/core/yson/unittests/protobuf_yson_ut.cpp20
-rw-r--r--yt/yt/core/yson/unittests/ya.make2
6 files changed, 258 insertions, 8 deletions
diff --git a/yt/yt/core/yson/protobuf_interop.cpp b/yt/yt/core/yson/protobuf_interop.cpp
index 343cbf8090e..51e0f1245fd 100644
--- a/yt/yt/core/yson/protobuf_interop.cpp
+++ b/yt/yt/core/yson/protobuf_interop.cpp
@@ -631,7 +631,9 @@ TProtobufElement TProtobufField::GetElement(bool insideRepeated) const
MessageType_
});
} else {
- return std::make_unique<TProtobufScalarElement>();
+ return std::make_unique<TProtobufScalarElement>(TProtobufScalarElement{
+ static_cast<TProtobufScalarElement::TType>(GetType())
+ });
}
}
diff --git a/yt/yt/core/yson/protobuf_interop.h b/yt/yt/core/yson/protobuf_interop.h
index 78d51a10cb7..1f3ea004423 100644
--- a/yt/yt/core/yson/protobuf_interop.h
+++ b/yt/yt/core/yson/protobuf_interop.h
@@ -75,6 +75,8 @@ struct TProtobufMessageElement
struct TProtobufScalarElement
{
+ YT_DEFINE_STRONG_TYPEDEF(TType, int);
+ TType Type;
};
struct TProtobufAttributeDictionaryElement
diff --git a/yt/yt/core/yson/unittests/proto/protobuf_scalar_type_ut.proto b/yt/yt/core/yson/unittests/proto/protobuf_scalar_type_ut.proto
new file mode 100644
index 00000000000..de5f80bc531
--- /dev/null
+++ b/yt/yt/core/yson/unittests/proto/protobuf_scalar_type_ut.proto
@@ -0,0 +1,49 @@
+package NYT.NYson.NProto;
+
+import "yt_proto/yt/core/misc/proto/protobuf_helpers.proto";
+import "yt_proto/yt/core/yson/proto/protobuf_interop.proto";
+import "yt_proto/yt/core/ytree/proto/attributes.proto";
+
+message TExampleMessage
+{
+ optional int32 int32_field = 1;
+ optional uint32 uint32_field = 2;
+ optional sint32 sint32_field = 3;
+ optional int64 int64_field = 4;
+ optional uint64 uint64_field = 5;
+ optional sint64 sint64_field = 6;
+ optional fixed32 fixed32_field = 7;
+ optional fixed64 fixed64_field = 8;
+ optional sfixed32 sfixed32_field = 9;
+ optional sfixed64 sfixed64_field = 10;
+ optional bool bool_field = 11;
+ optional string string_field = 12;
+ optional float float_field = 13;
+ optional double double_field = 14;
+
+ repeated int32 repeated_int32_field = 15;
+ repeated uint32 repeated_uint32_field = 16;
+ repeated sint32 repeated_sint32_field = 17;
+ repeated int64 repeated_int64_field = 18;
+ repeated uint64 repeated_uint64_field = 19;
+ repeated sint64 repeated_sint64_field = 20;
+ repeated fixed32 repeated_fixed32_field = 21;
+ repeated fixed64 repeated_fixed64_field = 22;
+ repeated sfixed32 repeated_sfixed32_field = 23;
+ repeated sfixed64 repeated_sfixed64_field = 24;
+ repeated bool repeated_bool_field = 25;
+ repeated string repeated_string_field = 26;
+ repeated float repeated_float_field = 27;
+ repeated double repeated_double_field = 28;
+
+ optional TExampleMessage nested_message1 = 29;
+ optional TExampleMessage nested_message2 = 30;
+
+ repeated TExampleMessage repeated_nested_message = 31;
+
+ map<string, TExampleMessage> nested_message_map = 33[(NYT.NYson.NProto.yson_map) = true];
+ map<string, int32> string_to_int32_map = 34[(NYT.NYson.NProto.yson_map) = true];
+ map<string, string> string_to_string_map = 35[(NYT.NYson.NProto.yson_map) = true];
+ map<int32, int32> int32_to_int32_map = 36[(NYT.NYson.NProto.yson_map) = true];
+ map<int32, string> int32_to_string_map = 37[(NYT.NYson.NProto.yson_map) = true];
+}
diff --git a/yt/yt/core/yson/unittests/protobuf_scalar_type_ut.cpp b/yt/yt/core/yson/unittests/protobuf_scalar_type_ut.cpp
new file mode 100644
index 00000000000..1aecd27a363
--- /dev/null
+++ b/yt/yt/core/yson/unittests/protobuf_scalar_type_ut.cpp
@@ -0,0 +1,189 @@
+#include <yt/yt/core/test_framework/framework.h>
+
+#include <yt/yt/core/yson/protobuf_interop.h>
+
+#include <yt/yt/core/yson/unittests/proto/protobuf_scalar_type_ut.pb.h>
+
+#include <google/protobuf/descriptor.h>
+
+namespace NYT::NYson {
+namespace {
+
+using namespace google::protobuf;
+
+#define EXPECT_SCALAR_TYPE(messageType, path, expectedType) \
+ do { \
+ auto type = ReflectProtobufMessageType<NProto::messageType>(); \
+ auto element = ResolveProtobufElementByYPath(type, path).Element; \
+ EXPECT_TRUE(std::holds_alternative<std::unique_ptr<TProtobufScalarElement>>(element)); \
+ int fieldType = static_cast<int>( \
+ std::get<std::unique_ptr<TProtobufScalarElement>>(element)->Type \
+ ); \
+ EXPECT_EQ(fieldType, expectedType); \
+ } while (false);
+
+TEST(TProtobufScalarTypeTest, Types)
+{
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/int32_field", FieldDescriptor::TYPE_INT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/uint32_field", FieldDescriptor::TYPE_UINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/sint32_field", FieldDescriptor::TYPE_SINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/fixed32_field", FieldDescriptor::TYPE_FIXED32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/sfixed32_field", FieldDescriptor::TYPE_SFIXED32);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/int64_field", FieldDescriptor::TYPE_INT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/uint64_field", FieldDescriptor::TYPE_UINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/sint64_field", FieldDescriptor::TYPE_SINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/fixed64_field", FieldDescriptor::TYPE_FIXED64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/sfixed64_field", FieldDescriptor::TYPE_SFIXED64);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/bool_field", FieldDescriptor::TYPE_BOOL);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/string_field", FieldDescriptor::TYPE_STRING);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/float_field", FieldDescriptor::TYPE_FLOAT);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/double_field", FieldDescriptor::TYPE_DOUBLE);
+}
+
+TEST(TProtobufScalarTypeTest, RepeatedNestedTypes)
+{
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/int32_field", FieldDescriptor::TYPE_INT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/uint32_field", FieldDescriptor::TYPE_UINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/sint32_field", FieldDescriptor::TYPE_SINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/fixed32_field", FieldDescriptor::TYPE_FIXED32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/sfixed32_field", FieldDescriptor::TYPE_SFIXED32);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/int64_field", FieldDescriptor::TYPE_INT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/uint64_field", FieldDescriptor::TYPE_UINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/sint64_field", FieldDescriptor::TYPE_SINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/fixed64_field", FieldDescriptor::TYPE_FIXED64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/sfixed64_field", FieldDescriptor::TYPE_SFIXED64);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/bool_field", FieldDescriptor::TYPE_BOOL);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/string_field", FieldDescriptor::TYPE_STRING);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/float_field", FieldDescriptor::TYPE_FLOAT);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/0/double_field", FieldDescriptor::TYPE_DOUBLE);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/int32_field", FieldDescriptor::TYPE_INT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/uint32_field", FieldDescriptor::TYPE_UINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/sint32_field", FieldDescriptor::TYPE_SINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/fixed32_field", FieldDescriptor::TYPE_FIXED32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/sfixed32_field", FieldDescriptor::TYPE_SFIXED32);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/int64_field", FieldDescriptor::TYPE_INT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/uint64_field", FieldDescriptor::TYPE_UINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/sint64_field", FieldDescriptor::TYPE_SINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/fixed64_field", FieldDescriptor::TYPE_FIXED64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/sfixed64_field", FieldDescriptor::TYPE_SFIXED64);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/bool_field", FieldDescriptor::TYPE_BOOL);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/string_field", FieldDescriptor::TYPE_STRING);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/float_field", FieldDescriptor::TYPE_FLOAT);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_nested_message/1/double_field", FieldDescriptor::TYPE_DOUBLE);
+}
+
+TEST(TProtobufScalarTypeTest, NestedTypes)
+{
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/int32_field", FieldDescriptor::TYPE_INT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/uint32_field", FieldDescriptor::TYPE_UINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/sint32_field", FieldDescriptor::TYPE_SINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/fixed32_field", FieldDescriptor::TYPE_FIXED32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/sfixed32_field", FieldDescriptor::TYPE_SFIXED32);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/int64_field", FieldDescriptor::TYPE_INT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/uint64_field", FieldDescriptor::TYPE_UINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/sint64_field", FieldDescriptor::TYPE_SINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/fixed64_field", FieldDescriptor::TYPE_FIXED64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/sfixed64_field", FieldDescriptor::TYPE_SFIXED64);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/bool_field", FieldDescriptor::TYPE_BOOL);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/string_field", FieldDescriptor::TYPE_STRING);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/float_field", FieldDescriptor::TYPE_FLOAT);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message1/double_field", FieldDescriptor::TYPE_DOUBLE);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/int32_field", FieldDescriptor::TYPE_INT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/uint32_field", FieldDescriptor::TYPE_UINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/sint32_field", FieldDescriptor::TYPE_SINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/fixed32_field", FieldDescriptor::TYPE_FIXED32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/sfixed32_field", FieldDescriptor::TYPE_SFIXED32);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/int64_field", FieldDescriptor::TYPE_INT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/uint64_field", FieldDescriptor::TYPE_UINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/sint64_field", FieldDescriptor::TYPE_SINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/fixed64_field", FieldDescriptor::TYPE_FIXED64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/sfixed64_field", FieldDescriptor::TYPE_SFIXED64);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/bool_field", FieldDescriptor::TYPE_BOOL);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/string_field", FieldDescriptor::TYPE_STRING);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/float_field", FieldDescriptor::TYPE_FLOAT);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message2/double_field", FieldDescriptor::TYPE_DOUBLE);
+}
+
+TEST(TProtobufScalarTypeTest, RepeatedTypes)
+{
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_int32_field/0", FieldDescriptor::TYPE_INT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_uint32_field/0", FieldDescriptor::TYPE_UINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_sint32_field/0", FieldDescriptor::TYPE_SINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_fixed32_field/0", FieldDescriptor::TYPE_FIXED32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_sfixed32_field/0", FieldDescriptor::TYPE_SFIXED32);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_int64_field/0", FieldDescriptor::TYPE_INT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_uint64_field/0", FieldDescriptor::TYPE_UINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_sint64_field/0", FieldDescriptor::TYPE_SINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_fixed64_field/0", FieldDescriptor::TYPE_FIXED64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_sfixed64_field/0", FieldDescriptor::TYPE_SFIXED64);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_bool_field/0", FieldDescriptor::TYPE_BOOL);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_string_field/0", FieldDescriptor::TYPE_STRING);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_float_field/0", FieldDescriptor::TYPE_FLOAT);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_double_field/0", FieldDescriptor::TYPE_DOUBLE);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_int32_field/1", FieldDescriptor::TYPE_INT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_uint32_field/1", FieldDescriptor::TYPE_UINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_sint32_field/1", FieldDescriptor::TYPE_SINT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_fixed32_field/1", FieldDescriptor::TYPE_FIXED32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_sfixed32_field/1", FieldDescriptor::TYPE_SFIXED32);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_int64_field/1", FieldDescriptor::TYPE_INT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_uint64_field/1", FieldDescriptor::TYPE_UINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_sint64_field/1", FieldDescriptor::TYPE_SINT64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_fixed64_field/1", FieldDescriptor::TYPE_FIXED64);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_sfixed64_field/1", FieldDescriptor::TYPE_SFIXED64);
+
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_bool_field/1", FieldDescriptor::TYPE_BOOL);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_string_field/1", FieldDescriptor::TYPE_STRING);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_float_field/1", FieldDescriptor::TYPE_FLOAT);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/repeated_double_field/1", FieldDescriptor::TYPE_DOUBLE);
+}
+
+TEST(TProtobufScalarTypeTest, MapTypes)
+{
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/string_to_int32_map/hello",
+ FieldDescriptor::TYPE_INT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/string_to_int32_map/world",
+ FieldDescriptor::TYPE_INT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/string_to_string_map/hello",
+ FieldDescriptor::TYPE_STRING);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/string_to_string_map/world",
+ FieldDescriptor::TYPE_STRING);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/int32_to_int32_map/0",
+ FieldDescriptor::TYPE_INT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/int32_to_int32_map/1",
+ FieldDescriptor::TYPE_INT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/int32_to_string_map/0",
+ FieldDescriptor::TYPE_STRING);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/int32_to_string_map/1",
+ FieldDescriptor::TYPE_STRING);
+}
+
+TEST(TProtobufScalarTypeTest, MapNestedTypes)
+{
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message_map/hello/int32_field",
+ FieldDescriptor::TYPE_INT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message_map/world/int32_field",
+ FieldDescriptor::TYPE_INT32);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message_map/hello/string_field",
+ FieldDescriptor::TYPE_STRING);
+ EXPECT_SCALAR_TYPE(TExampleMessage, "/nested_message_map/world/string_field",
+ FieldDescriptor::TYPE_STRING);
+}
+
+} // namespace
+} // namespace NYT::NYson
diff --git a/yt/yt/core/yson/unittests/protobuf_yson_ut.cpp b/yt/yt/core/yson/unittests/protobuf_yson_ut.cpp
index d5799401320..9deda7e7fa3 100644
--- a/yt/yt/core/yson/unittests/protobuf_yson_ut.cpp
+++ b/yt/yt/core/yson/unittests/protobuf_yson_ut.cpp
@@ -47,6 +47,8 @@ using namespace NYPath;
using namespace ::google::protobuf::io;
using namespace ::google::protobuf::internal;
+using FieldDescriptor = google::protobuf::FieldDescriptor;
+
////////////////////////////////////////////////////////////////////////////////
struct TNestedMessageWithCustomConverter
@@ -2030,22 +2032,26 @@ TEST(TResolveProtobufElementByYPath, Message)
////////////////////////////////////////////////////////////////////////////////
-void TestScalarByYPath(const TYPath& path)
+void TestScalarByYPath(const TYPath& path, FieldDescriptor::Type type)
{
auto result = ResolveProtobufElementByYPath(ReflectProtobufMessageType<NYT::NYson::NProto::TMessage>(), path);
EXPECT_TRUE(std::holds_alternative<std::unique_ptr<TProtobufScalarElement>>(result.Element));
EXPECT_EQ(path, result.HeadPath);
EXPECT_EQ("", result.TailPath);
+ EXPECT_EQ(
+ static_cast<TProtobufScalarElement::TType>(type),
+ std::get<std::unique_ptr<TProtobufScalarElement>>(result.Element)->Type
+ );
}
TEST(TResolveProtobufElementByYPath, Scalar)
{
- TestScalarByYPath("/uint32_field");
- TestScalarByYPath("/repeated_int32_field/123");
- TestScalarByYPath("/repeated_nested_message1/0/color");
- TestScalarByYPath("/nested_message_map/abc/int32_field");
- TestScalarByYPath("/string_to_int32_map/abc");
- TestScalarByYPath("/int32_to_int32_map/100");
+ TestScalarByYPath("/uint32_field", FieldDescriptor::TYPE_UINT32);
+ TestScalarByYPath("/repeated_int32_field/123", FieldDescriptor::TYPE_INT32);
+ TestScalarByYPath("/repeated_nested_message1/0/color", FieldDescriptor::TYPE_ENUM);
+ TestScalarByYPath("/nested_message_map/abc/int32_field", FieldDescriptor::TYPE_INT32);
+ TestScalarByYPath("/string_to_int32_map/abc", FieldDescriptor::TYPE_INT32);
+ TestScalarByYPath("/int32_to_int32_map/100", FieldDescriptor::TYPE_INT32);
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/yt/yt/core/yson/unittests/ya.make b/yt/yt/core/yson/unittests/ya.make
index e2029b8ec8b..97f0db356f9 100644
--- a/yt/yt/core/yson/unittests/ya.make
+++ b/yt/yt/core/yson/unittests/ya.make
@@ -12,6 +12,7 @@ SRCS(
depth_limiting_yson_consumer_ut.cpp
filter_ut.cpp
lexer_ut.cpp
+ protobuf_scalar_type_ut.cpp
protobuf_yson_ut.cpp
ypath_designated_yson_consumer_ut.cpp
yson_parser_ut.cpp
@@ -20,6 +21,7 @@ SRCS(
yson_ut.cpp
yson_writer_ut.cpp
+ proto/protobuf_scalar_type_ut.proto
proto/protobuf_yson_ut.proto
proto/protobuf_yson_casing_ut.proto
)