summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbabenko <[email protected]>2024-08-17 20:50:35 +0300
committerbabenko <[email protected]>2024-08-17 21:00:31 +0300
commit72cbe4bad58add0912623ba51351ff1db8587249 (patch)
treef7f2b5a6b5e20e3c760a47309907be35ebc34e96
parent08c062b6cc9a8e38eba558b4a939457558d8a9ae (diff)
YT-22593: Replace TString with std::string for YTree map keys
cfad05c1366e859aadbfc3777aafc13e955757b0
-rw-r--r--yt/yt/client/api/rpc_proxy/client_base.cpp2
-rw-r--r--yt/yt/core/misc/protobuf_helpers.cpp3
-rw-r--r--yt/yt/core/ytree/attributes.cpp6
-rw-r--r--yt/yt/core/ytree/ephemeral_node_factory.cpp19
-rw-r--r--yt/yt/core/ytree/node-inl.h6
-rw-r--r--yt/yt/core/ytree/node.cpp4
-rw-r--r--yt/yt/core/ytree/node.h24
-rw-r--r--yt/yt/core/ytree/serialize-inl.h8
-rw-r--r--yt/yt/core/ytree/tree_visitor.cpp3
-rw-r--r--yt/yt/core/ytree/unittests/ytree_ut.cpp2
-rw-r--r--yt/yt/library/formats/protobuf.cpp12
11 files changed, 48 insertions, 41 deletions
diff --git a/yt/yt/client/api/rpc_proxy/client_base.cpp b/yt/yt/client/api/rpc_proxy/client_base.cpp
index 31c9950f714..74aecebfa61 100644
--- a/yt/yt/client/api/rpc_proxy/client_base.cpp
+++ b/yt/yt/client/api/rpc_proxy/client_base.cpp
@@ -392,7 +392,7 @@ TFuture<void> TClientBase::MultisetAttributesNode(
std::sort(children.begin(), children.end());
for (const auto& [attribute, value] : children) {
auto* protoSubrequest = req->add_subrequests();
- protoSubrequest->set_attribute(attribute);
+ protoSubrequest->set_attribute(ToProto<TProtobufString>(attribute));
protoSubrequest->set_value(ConvertToYsonString(value).ToString());
}
diff --git a/yt/yt/core/misc/protobuf_helpers.cpp b/yt/yt/core/misc/protobuf_helpers.cpp
index 3a1913eaa28..cae9a285fa9 100644
--- a/yt/yt/core/misc/protobuf_helpers.cpp
+++ b/yt/yt/core/misc/protobuf_helpers.cpp
@@ -442,7 +442,8 @@ void Deserialize(TExtensionSet& extensionSet, NYTree::INodePtr node)
{
auto mapNode = node->AsMap();
for (const auto& [name, value] : mapNode->GetChildren()) {
- const auto* extensionDescriptor = IProtobufExtensionRegistry::Get()->FindDescriptorByName(name);
+ // TODO(babenko): migrate to std::string
+ const auto* extensionDescriptor = IProtobufExtensionRegistry::Get()->FindDescriptorByName(TString(name));
// Do not parse unknown extensions.
if (!extensionDescriptor) {
continue;
diff --git a/yt/yt/core/ytree/attributes.cpp b/yt/yt/core/ytree/attributes.cpp
index ed1ab329d62..58b88e72c8a 100644
--- a/yt/yt/core/ytree/attributes.cpp
+++ b/yt/yt/core/ytree/attributes.cpp
@@ -28,7 +28,8 @@ TYsonString IAttributeDictionary::GetYsonAndRemove(const TString& key)
void IAttributeDictionary::MergeFrom(const IMapNodePtr& other)
{
for (const auto& [key, value] : other->GetChildren()) {
- SetYson(key, ConvertToYsonString(value));
+ // TODO(babenko): migrate to std::string
+ SetYson(TString(key), ConvertToYsonString(value));
}
}
@@ -63,7 +64,8 @@ IAttributeDictionaryPtr IAttributeDictionary::FromMap(const IMapNodePtr& node)
auto attributes = CreateEphemeralAttributes();
auto children = node->GetChildren();
for (int index = 0; index < std::ssize(children); ++index) {
- attributes->SetYson(children[index].first, ConvertToYsonString(children[index].second));
+ // TODO(babenko): migrate to std::string
+ attributes->SetYson(TString(children[index].first), ConvertToYsonString(children[index].second));
}
return attributes;
}
diff --git a/yt/yt/core/ytree/ephemeral_node_factory.cpp b/yt/yt/core/ytree/ephemeral_node_factory.cpp
index fe15dabb29c..64ffcbd9e47 100644
--- a/yt/yt/core/ytree/ephemeral_node_factory.cpp
+++ b/yt/yt/core/ytree/ephemeral_node_factory.cpp
@@ -193,14 +193,14 @@ public:
return KeyToChild_.ysize();
}
- std::vector< std::pair<TString, INodePtr> > GetChildren() const override
+ std::vector<std::pair<std::string, INodePtr>> GetChildren() const override
{
- return std::vector< std::pair<TString, INodePtr> >(KeyToChild_.begin(), KeyToChild_.end());
+ return {KeyToChild_.begin(), KeyToChild_.end()};
}
- std::vector<TString> GetKeys() const override
+ std::vector<std::string> GetKeys() const override
{
- std::vector<TString> result;
+ std::vector<std::string> result;
result.reserve(KeyToChild_.size());
for (const auto& [key, child] : KeyToChild_) {
result.push_back(key);
@@ -208,13 +208,13 @@ public:
return result;
}
- INodePtr FindChild(const TString& key) const override
+ INodePtr FindChild(const std::string& key) const override
{
auto it = KeyToChild_.find(key);
return it == KeyToChild_.end() ? nullptr : it->second;
}
- bool AddChild(const TString& key, const INodePtr& child) override
+ bool AddChild(const std::string& key, const INodePtr& child) override
{
YT_ASSERT(child);
ValidateYTreeKey(key);
@@ -228,11 +228,12 @@ public:
}
}
- bool RemoveChild(const TString& key) override
+ bool RemoveChild(const std::string& key) override
{
auto it = KeyToChild_.find(TString(key));
- if (it == KeyToChild_.end())
+ if (it == KeyToChild_.end()) {
return false;
+ }
auto child = it->second;
child->SetParent(nullptr);
@@ -279,7 +280,7 @@ public:
YT_VERIFY(ChildToKey_.emplace(newChild, key).second);
}
- std::optional<TString> FindChildKey(const IConstNodePtr& child) override
+ std::optional<std::string> FindChildKey(const IConstNodePtr& child) override
{
YT_ASSERT(child);
diff --git a/yt/yt/core/ytree/node-inl.h b/yt/yt/core/ytree/node-inl.h
index e62889f41e3..3698f36cab8 100644
--- a/yt/yt/core/ytree/node-inl.h
+++ b/yt/yt/core/ytree/node-inl.h
@@ -23,20 +23,20 @@ T INode::GetValue() const
////////////////////////////////////////////////////////////////////////////////
template <class T>
-T IMapNode::GetChildValueOrThrow(const TString& key) const
+T IMapNode::GetChildValueOrThrow(const std::string& key) const
{
return GetChildOrThrow(key)->GetValue<T>();
}
template <class T>
-T IMapNode::GetChildValueOrDefault(const TString& key, const T& defaultValue) const
+T IMapNode::GetChildValueOrDefault(const std::string& key, const T& defaultValue) const
{
auto child = FindChild(key);
return child ? child->GetValue<T>() : defaultValue;
}
template <class T>
-std::optional<T> IMapNode::FindChildValue(const TString& key) const
+std::optional<T> IMapNode::FindChildValue(const std::string& key) const
{
auto child = FindChild(key);
return child ? std::make_optional(child->GetValue<T>()) : std::nullopt;
diff --git a/yt/yt/core/ytree/node.cpp b/yt/yt/core/ytree/node.cpp
index dbfcb31ac9a..423df3900a0 100644
--- a/yt/yt/core/ytree/node.cpp
+++ b/yt/yt/core/ytree/node.cpp
@@ -13,7 +13,7 @@ using namespace NYson;
////////////////////////////////////////////////////////////////////////////////
-INodePtr IMapNode::GetChildOrThrow(const TString& key) const
+INodePtr IMapNode::GetChildOrThrow(const std::string& key) const
{
auto child = FindChild(key);
if (!child) {
@@ -22,7 +22,7 @@ INodePtr IMapNode::GetChildOrThrow(const TString& key) const
return child;
}
-TString IMapNode::GetChildKeyOrThrow(const IConstNodePtr& child)
+std::string IMapNode::GetChildKeyOrThrow(const IConstNodePtr& child)
{
auto optionalKey = FindChildKey(child);
if (!optionalKey) {
diff --git a/yt/yt/core/ytree/node.h b/yt/yt/core/ytree/node.h
index 9baac8e99aa..ccceb3e0b23 100644
--- a/yt/yt/core/ytree/node.h
+++ b/yt/yt/core/ytree/node.h
@@ -159,7 +159,7 @@ DEFINE_REFCOUNTED_TYPE(ICompositeNode)
////////////////////////////////////////////////////////////////////////////////
-//! A map node, which keeps a dictionary mapping strings (TString) to child nodes.
+//! A map node, which maps keys (std::string) to child nodes.
struct IMapNode
: public virtual ICompositeNode
{
@@ -169,20 +169,20 @@ struct IMapNode
/*!
* Map items are returned in unspecified order.
*/
- virtual std::vector<std::pair<TString, INodePtr>> GetChildren() const = 0;
+ virtual std::vector<std::pair<std::string, INodePtr>> GetChildren() const = 0;
//! Returns map keys.
/*!
* Keys are returned in unspecified order.
*/
- virtual std::vector<TString> GetKeys() const = 0;
+ virtual std::vector<std::string> GetKeys() const = 0;
//! Gets a child by its key.
/*!
* \param key A key.
* \return A child with the given #key or null if no child with the given #key exists.
*/
- virtual INodePtr FindChild(const TString& key) const = 0;
+ virtual INodePtr FindChild(const std::string& key) const = 0;
//! Adds a new child with a given key.
/*!
@@ -193,48 +193,48 @@ struct IMapNode
* \note
* #child must be a root.
*/
- virtual bool AddChild(const TString& key, const INodePtr& child) = 0;
+ virtual bool AddChild(const std::string& key, const INodePtr& child) = 0;
//! Removes a child by its key.
/*!
* \param key A key.
* \return True iff there was a child with the given key.
*/
- virtual bool RemoveChild(const TString& key) = 0;
+ virtual bool RemoveChild(const std::string& key) = 0;
//! Similar to #FindChild but throws if no child is found.
- INodePtr GetChildOrThrow(const TString& key) const;
+ INodePtr GetChildOrThrow(const std::string& key) const;
//! Returns the key for a given child.
/*!
* \param child A possible child.
* \return Child's key or null if the node is not a child.
*/
- virtual std::optional<TString> FindChildKey(const IConstNodePtr& child) = 0;
+ virtual std::optional<std::string> FindChildKey(const IConstNodePtr& child) = 0;
//! Returns the key for a given child or throws if the node is not a child.
/*!
* \param child A possible child.
* \return Child's key.
*/
- TString GetChildKeyOrThrow(const IConstNodePtr& child);
+ std::string GetChildKeyOrThrow(const IConstNodePtr& child);
// Extension methods.
//! Converts the value of the child with #key to a given type.
//! Throws if no child with #key exists.
template <class T>
- T GetChildValueOrThrow(const TString& key) const;
+ T GetChildValueOrThrow(const std::string& key) const;
//! Converts the value of the child with #key to a given type.
//! Returns #defaultValue if no child with #key exists.
template <class T>
- T GetChildValueOrDefault(const TString& key, const T& defaultValue) const;
+ T GetChildValueOrDefault(const std::string& key, const T& defaultValue) const;
//! Converts the value of the child with #key to a given type.
//! Returns null if no child with #key exists.
template <class T>
- std::optional<T> FindChildValue(const TString& key) const;
+ std::optional<T> FindChildValue(const std::string& key) const;
};
DEFINE_REFCOUNTED_TYPE(IMapNode)
diff --git a/yt/yt/core/ytree/serialize-inl.h b/yt/yt/core/ytree/serialize-inl.h
index 82dcdac2b07..fe1ce789e65 100644
--- a/yt/yt/core/ytree/serialize-inl.h
+++ b/yt/yt/core/ytree/serialize-inl.h
@@ -91,7 +91,7 @@ struct TMapKeyHelper<T, true>
consumer->OnKeyedItem(FormatEnum(value));
}
- static void Deserialize(T& value, const TString& key)
+ static void Deserialize(T& value, const std::string& key)
{
value = ParseEnum<T>(key);
}
@@ -105,7 +105,7 @@ struct TMapKeyHelper<T, false>
consumer->OnKeyedItem(ToString(value));
}
- static void Deserialize(T& value, const TString& key)
+ static void Deserialize(T& value, const std::string& key)
{
value = FromString<T>(key);
}
@@ -114,12 +114,12 @@ struct TMapKeyHelper<T, false>
template <>
struct TMapKeyHelper<TGuid, false>
{
- static void Serialize(const TGuid& value, NYson::IYsonConsumer* consumer)
+ static void Serialize(TGuid value, NYson::IYsonConsumer* consumer)
{
consumer->OnKeyedItem(ToString(value));
}
- static void Deserialize(TGuid& value, const TString& key)
+ static void Deserialize(TGuid& value, const std::string& key)
{
value = TGuid::FromString(key);
}
diff --git a/yt/yt/core/ytree/tree_visitor.cpp b/yt/yt/core/ytree/tree_visitor.cpp
index 9e97f432863..d6e927bab48 100644
--- a/yt/yt/core/ytree/tree_visitor.cpp
+++ b/yt/yt/core/ytree/tree_visitor.cpp
@@ -131,11 +131,10 @@ private:
Consumer->OnBeginMap();
auto children = node->GetChildren();
if (Stable_) {
- using TPair = std::pair<TString, INodePtr>;
std::sort(
children.begin(),
children.end(),
- [] (const TPair& lhs, const TPair& rhs) {
+ [] (const auto& lhs, const auto& rhs) {
return lhs.first < rhs.first;
});
}
diff --git a/yt/yt/core/ytree/unittests/ytree_ut.cpp b/yt/yt/core/ytree/unittests/ytree_ut.cpp
index 11857d65ef4..c1caf87b862 100644
--- a/yt/yt/core/ytree/unittests/ytree_ut.cpp
+++ b/yt/yt/core/ytree/unittests/ytree_ut.cpp
@@ -101,7 +101,7 @@ TEST(TYTreeTest, TestMultisetAttributesByPath)
SyncYPathMultisetAttributes(node, "/@a", attributes3);
auto attribute = ConvertToNode(node->Attributes().GetYson("a"))->AsMap();
- EXPECT_EQ(attribute->GetKeys(), std::vector<TString>({"b", "c"}));
+ EXPECT_EQ(attribute->GetKeys(), std::vector<std::string>({"b", "c"}));
}
TEST(TYTreeTest, TestGetWithAttributes)
diff --git a/yt/yt/library/formats/protobuf.cpp b/yt/yt/library/formats/protobuf.cpp
index f50840cd70c..3da3f04b48b 100644
--- a/yt/yt/library/formats/protobuf.cpp
+++ b/yt/yt/library/formats/protobuf.cpp
@@ -183,10 +183,12 @@ static TEnumerationDescription CreateEnumerationMap(
const auto& valueNode = enumValue.second;
switch (valueNode->GetType()) {
case ENodeType::Uint64:
- result.Add(name, valueNode->GetValue<ui64>());
+ // TODO(babenko): migrate to std::string
+ result.Add(TString(name), valueNode->GetValue<ui64>());
break;
case ENodeType::Int64:
- result.Add(name, valueNode->GetValue<i64>());
+ // TODO(babenko): migrate to std::string
+ result.Add(TString(name), valueNode->GetValue<i64>());
break;
default:
THROW_ERROR_EXCEPTION("Invalid specification of %Qv enumeration: expected type \"int64\" or \"uint64\", actual type %Qlv",
@@ -1003,13 +1005,15 @@ void TProtobufFormatDescriptionBase<TType>::InitFromProtobufSchema(
{
if (config->Enumerations) {
const auto& enumerationConfigMap = config->Enumerations;
- for (const auto& [name, field] : enumerationConfigMap->GetChildren()) {
+ for (const auto& [name_, field] : enumerationConfigMap->GetChildren()) {
+ // TODO(babenko): migrate to std::string
+ auto name = TString(name_);
if (field->GetType() != ENodeType::Map) {
THROW_ERROR_EXCEPTION(R"(Invalid enumeration specification type: expected "map", found %Qlv)",
field->GetType());
}
const auto& enumerationConfig = field->AsMap();
- EnumerationDescriptionMap_.emplace(name, CreateEnumerationMap(name, enumerationConfig));
+ EnumerationDescriptionMap_.emplace(name, CreateEnumerationMap(TimestampColumnName, enumerationConfig));
}
}