aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2025-01-13 13:40:46 +0300
committerbabenko <babenko@yandex-team.com>2025-01-13 13:59:44 +0300
commite5f98db1a19bd77a3e8647de3c5f409c919014f0 (patch)
treee07399398bf62edf3325ee33e1ea20194082745d
parent8ca2df28426b4e6aefaf5bdf4d0b307cbcea01de (diff)
downloadydb-e5f98db1a19bd77a3e8647de3c5f409c919014f0.tar.gz
YT-18571: Switch to std::string for IAttributeDictionary keys
commit_hash:cd3a465f40df6c7efa7ce27778a683ac7dcff6bf
-rw-r--r--yt/yt/client/unittests/ypath_ut.cpp1
-rw-r--r--yt/yt/core/tracing/trace_context.cpp1
-rw-r--r--yt/yt/core/yson/attribute_consumer.cpp4
-rw-r--r--yt/yt/core/yson/attribute_consumer.h6
-rw-r--r--yt/yt/core/ytree/attribute_filter-inl.h19
-rw-r--r--yt/yt/core/ytree/attribute_filter.cpp23
-rw-r--r--yt/yt/core/ytree/attribute_filter.h26
-rw-r--r--yt/yt/core/ytree/attributes-inl.h16
-rw-r--r--yt/yt/core/ytree/attributes.cpp4
-rw-r--r--yt/yt/core/ytree/attributes.h31
-rw-r--r--yt/yt/core/ytree/convert-inl.h6
-rw-r--r--yt/yt/core/ytree/helpers.cpp43
-rw-r--r--yt/yt/core/ytree/helpers.h6
-rw-r--r--yt/yt/core/ytree/unittests/attributes_ut.cpp1
-rw-r--r--yt/yt/core/ytree/ypath_detail.cpp12
-rw-r--r--yt/yt/core/ytree/ypath_detail.h8
16 files changed, 123 insertions, 84 deletions
diff --git a/yt/yt/client/unittests/ypath_ut.cpp b/yt/yt/client/unittests/ypath_ut.cpp
index bc74d5f7cc..93a3c199d1 100644
--- a/yt/yt/client/unittests/ypath_ut.cpp
+++ b/yt/yt/client/unittests/ypath_ut.cpp
@@ -19,6 +19,7 @@
#include <yt/yt/core/ytree/tree_visitor.h>
#include <yt/yt/core/ytree/ypath_client.h>
#include <yt/yt/core/ytree/ypath_service.h>
+#include <yt/yt/core/ytree/helpers.h>
#include <util/string/vector.h>
diff --git a/yt/yt/core/tracing/trace_context.cpp b/yt/yt/core/tracing/trace_context.cpp
index 8a186701d3..2544f0147a 100644
--- a/yt/yt/core/tracing/trace_context.cpp
+++ b/yt/yt/core/tracing/trace_context.cpp
@@ -10,6 +10,7 @@
#include <yt/yt/core/misc/protobuf_helpers.h>
#include <yt/yt/core/ytree/convert.h>
+#include <yt/yt/core/ytree/helpers.h>
#include <yt/yt_proto/yt/core/tracing/proto/tracing_ext.pb.h>
diff --git a/yt/yt/core/yson/attribute_consumer.cpp b/yt/yt/core/yson/attribute_consumer.cpp
index 10f30d2730..6e0c2f3ef6 100644
--- a/yt/yt/core/yson/attribute_consumer.cpp
+++ b/yt/yt/core/yson/attribute_consumer.cpp
@@ -3,6 +3,8 @@
namespace NYT::NYson {
+using namespace NYTree;
+
////////////////////////////////////////////////////////////////////////////////
TAttributeFragmentConsumer::TAttributeFragmentConsumer(IAsyncYsonConsumer* underlyingConsumer)
@@ -121,7 +123,7 @@ void TAttributeFragmentConsumer::Finish()
TAttributeValueConsumer::TAttributeValueConsumer(
IAsyncYsonConsumer* underlyingConsumer,
- TString key)
+ IAttributeDictionary::TKey key)
: UnderlyingConsumer_(underlyingConsumer)
, Key_(std::move(key))
{ }
diff --git a/yt/yt/core/yson/attribute_consumer.h b/yt/yt/core/yson/attribute_consumer.h
index 1239476c3c..4ac8a1e54a 100644
--- a/yt/yt/core/yson/attribute_consumer.h
+++ b/yt/yt/core/yson/attribute_consumer.h
@@ -3,6 +3,8 @@
#include "public.h"
#include "async_consumer.h"
+#include <yt/yt/core/ytree/attributes.h>
+
namespace NYT::NYson {
////////////////////////////////////////////////////////////////////////////////
@@ -54,7 +56,7 @@ class TAttributeValueConsumer
public:
TAttributeValueConsumer(
IAsyncYsonConsumer* underlyingConsumer,
- TString key);
+ NYTree::IAttributeDictionary::TKey key);
void OnStringScalar(TStringBuf value) override;
void OnInt64Scalar(i64 value) override;
@@ -76,7 +78,7 @@ public:
private:
IAsyncYsonConsumer* const UnderlyingConsumer_;
- const TString Key_;
+ const NYTree::IAttributeDictionary::TKey Key_;
bool Empty_ = true;
void ProduceKeyIfNeeded();
diff --git a/yt/yt/core/ytree/attribute_filter-inl.h b/yt/yt/core/ytree/attribute_filter-inl.h
new file mode 100644
index 0000000000..a319270ad1
--- /dev/null
+++ b/yt/yt/core/ytree/attribute_filter-inl.h
@@ -0,0 +1,19 @@
+#ifndef ATTRIBUTE_FILER_INL_H_
+#error "Direct inclusion of this file is not allowed, include attribute_filter.h"
+// For the sake of sane code completion.
+#include "attribute_filter.h"
+#endif
+
+namespace NYT::NYTree {
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class T>
+TAttributeFilter::TAttributeFilter(std::initializer_list<T> keys)
+ : Keys({keys.begin(), keys.end()})
+ , Universal(false)
+{ }
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT::NYTree
diff --git a/yt/yt/core/ytree/attribute_filter.cpp b/yt/yt/core/ytree/attribute_filter.cpp
index 796507ccf2..a8e72c1393 100644
--- a/yt/yt/core/ytree/attribute_filter.cpp
+++ b/yt/yt/core/ytree/attribute_filter.cpp
@@ -197,20 +197,21 @@ std::unique_ptr<IHeterogenousFilterConsumer> CreateFilteringConsumerImpl(
////////////////////////////////////////////////////////////////////////////////
-TAttributeFilter::TAttributeFilter(std::vector<TString> keys, std::vector<TYPath> paths)
+TAttributeFilter::TAttributeFilter(std::vector<IAttributeDictionary::TKey> keys, std::vector<TYPath> paths)
: Keys(std::move(keys))
, Paths(std::move(paths))
, Universal(false)
{ }
-TAttributeFilter& TAttributeFilter::operator =(std::vector<TString> keys)
-{
- Keys = std::move(keys);
- Paths = {};
- Universal = false;
+TAttributeFilter::TAttributeFilter(std::initializer_list<TString> keys)
+ : Keys({keys.begin(), keys.end()})
+ , Universal(false)
+{ }
- return *this;
-}
+TAttributeFilter::TAttributeFilter(const std::vector<TString>& keys)
+ : Keys({keys.begin(), keys.end()})
+ , Universal(false)
+{ }
TAttributeFilter::operator bool() const
{
@@ -448,12 +449,12 @@ void Deserialize(TAttributeFilter& filter, const INodePtr& node)
filter.Universal = false;
filter.Keys.clear();
if (auto keysNode = mapNode->FindChild("keys")) {
- filter.Keys = ConvertTo<std::vector<TString>>(keysNode);
+ filter.Keys = ConvertTo<std::vector<IAttributeDictionary::TKey>>(keysNode);
}
filter.Paths.clear();
if (auto pathsNode = mapNode->FindChild("paths")) {
- filter.Paths = ConvertTo<std::vector<TString>>(pathsNode);
+ filter.Paths = ConvertTo<std::vector<TYPath>>(pathsNode);
}
break;
@@ -461,7 +462,7 @@ void Deserialize(TAttributeFilter& filter, const INodePtr& node)
case ENodeType::List: {
// Compatibility mode with HTTP clients that specify attribute keys as string lists.
filter.Universal = false;
- filter.Keys = ConvertTo<std::vector<TString>>(node);
+ filter.Keys = ConvertTo<std::vector<IAttributeDictionary::TKey>>(node);
filter.Paths = {};
break;
}
diff --git a/yt/yt/core/ytree/attribute_filter.h b/yt/yt/core/ytree/attribute_filter.h
index 461d024fd3..679ca46676 100644
--- a/yt/yt/core/ytree/attribute_filter.h
+++ b/yt/yt/core/ytree/attribute_filter.h
@@ -1,13 +1,12 @@
#pragma once
#include "public.h"
+#include "attributes.h"
#include <yt/yt/core/ypath/public.h>
#include <yt/yt/core/yson/public.h>
-#include <any>
-
namespace NYT::NYTree {
////////////////////////////////////////////////////////////////////////////////
@@ -67,7 +66,7 @@ namespace NYT::NYTree {
struct TAttributeFilter
{
//! Whitelist of top-level keys to be returned.
- std::vector<TString> Keys;
+ std::vector<IAttributeDictionary::TKey> Keys;
std::vector<NYPath::TYPath> Paths;
//! If true, filter is universal, i.e. behavior depends on service's own policy;
@@ -78,10 +77,17 @@ struct TAttributeFilter
TAttributeFilter() = default;
//! Creates a non-universal filter from given keys and paths.
- //! This constructor is intentionally non-explicit so that common idiom attributeFilter = {"foo", "bar"} works.
- TAttributeFilter(std::vector<TString> keys, std::vector<NYPath::TYPath> paths = {});
+ /*implicit*/ TAttributeFilter(
+ std::vector<IAttributeDictionary::TKey> keys,
+ std::vector<NYPath::TYPath> paths = {});
+
+ //! Creates a non-universal filter from a given list of keys.
+ template <class T>
+ TAttributeFilter(std::initializer_list<T> keys);
- TAttributeFilter& operator =(std::vector<TString> keys);
+ // TODO(babenko): switch to std::string
+ TAttributeFilter(std::initializer_list<TString> keys);
+ TAttributeFilter(const std::vector<TString>& keys);
//! Returns true for non-universal filter and false otherwise.
explicit operator bool() const;
@@ -95,11 +101,11 @@ struct TAttributeFilter
void ValidateKeysOnly(TStringBuf context = "this context") const;
//! Returns true if #key appears in Keys or "/#key" appears in Paths using linear search.
- bool AdmitsKeySlow(TStringBuf key) const;
+ bool AdmitsKeySlow(IAttributeDictionary::TKeyView key) const;
// std::nullopt stands for "take the whole attribute without path filtration" (i.e. an equivalent of {""}).
using TPathFilter = std::optional<std::vector<TYPath>>;
- using TKeyToFilter = THashMap<TString, TPathFilter>;
+ using TKeyToFilter = THashMap<IAttributeDictionary::TKey, TPathFilter>;
//! Normalization procedure removes redundant keys or paths and returns a mapping of form
//! top-level key -> list of YPaths inside this top-level key (i.e. with /<key> stripped off) or
@@ -161,3 +167,7 @@ void FormatValue(
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NYTree
+
+#define ATTRIBUTE_FILER_INL_H_
+#include "attribute_filter-inl.h"
+#undef ATTRIBUTE_FILER_INL_H_
diff --git a/yt/yt/core/ytree/attributes-inl.h b/yt/yt/core/ytree/attributes-inl.h
index 2ced0193d8..fc096d59db 100644
--- a/yt/yt/core/ytree/attributes-inl.h
+++ b/yt/yt/core/ytree/attributes-inl.h
@@ -4,8 +4,6 @@
#include "attributes.h"
#endif
-// #include "attribute_consumer.h"
-// #include "serialize.h"
#include "convert.h"
#include <library/cpp/yt/error/error_attributes.h>
@@ -17,7 +15,7 @@ namespace NYT {
namespace NYTree {
template <class T>
-T IAttributeDictionary::Get(TStringBuf key) const
+T IAttributeDictionary::Get(TKeyView key) const
{
auto yson = GetYson(key);
try {
@@ -30,7 +28,7 @@ T IAttributeDictionary::Get(TStringBuf key) const
}
template <class T>
-T IAttributeDictionary::GetAndRemove(const TString& key)
+T IAttributeDictionary::GetAndRemove(TKeyView key)
{
auto result = Get<T>(key);
Remove(key);
@@ -38,13 +36,13 @@ T IAttributeDictionary::GetAndRemove(const TString& key)
}
template <class T>
-T IAttributeDictionary::Get(TStringBuf key, const T& defaultValue) const
+T IAttributeDictionary::Get(TKeyView key, const T& defaultValue) const
{
return Find<T>(key).value_or(defaultValue);
}
template <class T>
-T IAttributeDictionary::GetAndRemove(const TString& key, const T& defaultValue)
+T IAttributeDictionary::GetAndRemove(TKeyView key, const T& defaultValue)
{
auto result = Find<T>(key);
if (result) {
@@ -56,7 +54,7 @@ T IAttributeDictionary::GetAndRemove(const TString& key, const T& defaultValue)
}
template <class T>
-typename TOptionalTraits<T>::TOptional IAttributeDictionary::Find(TStringBuf key) const
+typename TOptionalTraits<T>::TOptional IAttributeDictionary::Find(TKeyView key) const
{
auto yson = FindYson(key);
if (!yson) {
@@ -72,7 +70,7 @@ typename TOptionalTraits<T>::TOptional IAttributeDictionary::Find(TStringBuf key
}
template <class T>
-typename TOptionalTraits<T>::TOptional IAttributeDictionary::FindAndRemove(const TString& key)
+typename TOptionalTraits<T>::TOptional IAttributeDictionary::FindAndRemove(TKeyView key)
{
auto result = Find<T>(key);
if (result) {
@@ -82,7 +80,7 @@ typename TOptionalTraits<T>::TOptional IAttributeDictionary::FindAndRemove(const
}
template <class T>
-void IAttributeDictionary::Set(const TString& key, const T& value)
+void IAttributeDictionary::Set(TKeyView key, const T& value)
{
auto yson = ConvertToYsonString(value, NYson::EYsonFormat::Binary);
SetYson(key, yson);
diff --git a/yt/yt/core/ytree/attributes.cpp b/yt/yt/core/ytree/attributes.cpp
index 58b88e72c8..96f69f33c8 100644
--- a/yt/yt/core/ytree/attributes.cpp
+++ b/yt/yt/core/ytree/attributes.cpp
@@ -9,7 +9,7 @@ using namespace NYson;
////////////////////////////////////////////////////////////////////////////////
-TYsonString IAttributeDictionary::GetYson(TStringBuf key) const
+TYsonString IAttributeDictionary::GetYson(TKeyView key) const
{
auto result = FindYson(key);
if (!result) {
@@ -18,7 +18,7 @@ TYsonString IAttributeDictionary::GetYson(TStringBuf key) const
return result;
}
-TYsonString IAttributeDictionary::GetYsonAndRemove(const TString& key)
+TYsonString IAttributeDictionary::GetYsonAndRemove(TKeyView key)
{
auto result = GetYson(key);
Remove(key);
diff --git a/yt/yt/core/ytree/attributes.h b/yt/yt/core/ytree/attributes.h
index 0c99076f19..15457ad4e5 100644
--- a/yt/yt/core/ytree/attributes.h
+++ b/yt/yt/core/ytree/attributes.h
@@ -13,25 +13,26 @@ namespace NYT::NYTree {
struct IAttributeDictionary
: public TRefCounted
{
- using TKey = TString;
+ using TKey = std::string;
+ using TKeyView = TStringBuf;
using TValue = NYson::TYsonString;
using TKeyValuePair = std::pair<TKey, TValue>;
//! Returns the list of all keys in the dictionary.
- virtual std::vector<TString> ListKeys() const = 0;
+ virtual std::vector<TKey> ListKeys() const = 0;
//! Returns the list of all key-value pairs in the dictionary.
virtual std::vector<TKeyValuePair> ListPairs() const = 0;
//! Returns the value of the attribute (null indicates that the attribute is not found).
- virtual NYson::TYsonString FindYson(TStringBuf key) const = 0;
+ virtual TValue FindYson(TKeyView key) const = 0;
//! Sets the value of the attribute.
- virtual void SetYson(const TString& key, const NYson::TYsonString& value) = 0;
+ virtual void SetYson(TKeyView key, const TValue& value) = 0;
//! Removes the attribute.
//! Returns |true| if the attribute was removed or |false| if there is no attribute with this key.
- virtual bool Remove(const TString& key) = 0;
+ virtual bool Remove(TKeyView key) = 0;
// Extension methods
@@ -39,44 +40,44 @@ struct IAttributeDictionary
void Clear();
//! Returns the value of the attribute (throws an exception if the attribute is not found).
- NYson::TYsonString GetYson(TStringBuf key) const;
+ TValue GetYson(TKeyView key) const;
//! Same as #GetYson but removes the value.
- NYson::TYsonString GetYsonAndRemove(const TString& key);
+ TValue GetYsonAndRemove(TKeyView key);
//! Finds the attribute and deserializes its value.
//! Throws if no such value is found.
template <class T>
- T Get(TStringBuf key) const;
+ T Get(TKeyView key) const;
//! Same as #Get but removes the value.
template <class T>
- T GetAndRemove(const TString& key);
+ T GetAndRemove(TKeyView key);
//! Finds the attribute and deserializes its value.
//! Uses default value if no such attribute is found.
template <class T>
- T Get(TStringBuf key, const T& defaultValue) const;
+ T Get(TKeyView key, const T& defaultValue) const;
//! Same as #Get but removes the value if it exists.
template <class T>
- T GetAndRemove(const TString& key, const T& defaultValue);
+ T GetAndRemove(TKeyView key, const T& defaultValue);
//! Finds the attribute and deserializes its value.
//! Returns null if no such attribute is found.
template <class T>
- typename TOptionalTraits<T>::TOptional Find(TStringBuf key) const;
+ typename TOptionalTraits<T>::TOptional Find(TKeyView key) const;
//! Same as #Find but removes the value if it exists.
template <class T>
- typename TOptionalTraits<T>::TOptional FindAndRemove(const TString& key);
+ typename TOptionalTraits<T>::TOptional FindAndRemove(TKeyView key);
//! Returns |true| iff the given key is present.
- bool Contains(TStringBuf key) const;
+ bool Contains(TKeyView key) const;
//! Sets the attribute with a serialized value.
template <class T>
- void Set(const TString& key, const T& value);
+ void Set(TKeyView key, const T& value);
//! Constructs an instance from a map node (by serializing the values).
static IAttributeDictionaryPtr FromMap(const IMapNodePtr& node);
diff --git a/yt/yt/core/ytree/convert-inl.h b/yt/yt/core/ytree/convert-inl.h
index 6d1294f646..8dd191066e 100644
--- a/yt/yt/core/ytree/convert-inl.h
+++ b/yt/yt/core/ytree/convert-inl.h
@@ -8,7 +8,6 @@
#include "default_building_consumer.h"
#include "serialize.h"
#include "tree_builder.h"
-#include "helpers.h"
#include <yt/yt/core/ypath/token.h>
@@ -158,7 +157,10 @@ INodePtr ConvertToNode(
template <class T>
IAttributeDictionaryPtr ConvertToAttributes(const T& value)
{
- auto attributes = CreateEphemeralAttributes();
+ // Forward declaration.
+ IAttributeDictionaryPtr CreateEphemeralAttributes(std::optional<int> ysonNestingLevelLimit);
+
+ auto attributes = CreateEphemeralAttributes(std::nullopt);
TAttributeConsumer consumer(attributes.Get());
Serialize(value, &consumer);
return attributes;
diff --git a/yt/yt/core/ytree/helpers.cpp b/yt/yt/core/ytree/helpers.cpp
index b90c8ebd18..a97708fd2c 100644
--- a/yt/yt/core/ytree/helpers.cpp
+++ b/yt/yt/core/ytree/helpers.cpp
@@ -5,6 +5,8 @@
#include <yt/yt/core/misc/error.h>
+#include <library/cpp/yt/memory/leaky_ref_counted_singleton.h>
+
namespace NYT::NYTree {
using namespace NYson;
@@ -55,9 +57,9 @@ public:
: NestingLevelLimit_(ysonNestingLevelLimit)
{ }
- std::vector<TString> ListKeys() const override
+ std::vector<TKey> ListKeys() const override
{
- std::vector<TString> keys;
+ std::vector<TKey> keys;
keys.reserve(Map_.size());
for (const auto& [key, value] : Map_) {
keys.push_back(key);
@@ -75,13 +77,13 @@ public:
return pairs;
}
- TYsonString FindYson(TStringBuf key) const override
+ TValue FindYson(TKeyView key) const override
{
auto it = Map_.find(key);
return it == Map_.end() ? TYsonString() : it->second;
}
- void SetYson(const TString& key, const TYsonString& value) override
+ void SetYson(TKeyView key, const TValue& value) override
{
YT_ASSERT(value.GetType() == EYsonType::Node);
if (NestingLevelLimit_) {
@@ -90,13 +92,13 @@ public:
Map_[key] = value;
}
- bool Remove(const TString& key) override
+ bool Remove(TKeyView key) override
{
return Map_.erase(key) > 0;
}
private:
- THashMap<TString, TYsonString> Map_;
+ THashMap<TKey, TYsonString, THash<std::string_view>, TEqualTo<std::string_view>> Map_;
std::optional<int> NestingLevelLimit_;
};
@@ -111,7 +113,7 @@ class TEmptyAttributeDictionary
: public IAttributeDictionary
{
public:
- std::vector<TString> ListKeys() const override
+ std::vector<TKey> ListKeys() const override
{
return {};
}
@@ -121,30 +123,29 @@ public:
return {};
}
- TYsonString FindYson(TStringBuf /*key*/) const override
+ TValue FindYson(TKeyView /*key*/) const override
{
return {};
}
- void SetYson(const TString& /*key*/, const TYsonString& /*value*/) override
+ void SetYson(TKeyView /*key*/, const TValue& /*value*/) override
{
YT_ABORT();
}
- bool Remove(const TString& /*key*/) override
+ bool Remove(TKeyView /*key*/) override
{
return false;
}
+
+private:
+ DECLARE_LEAKY_REF_COUNTED_SINGLETON_FRIEND()
+ TEmptyAttributeDictionary() = default;
};
const IAttributeDictionary& EmptyAttributes()
{
- struct TSingleton
- {
- IAttributeDictionaryPtr EmptyAttributes = New<TEmptyAttributeDictionary>();
- };
-
- return *LeakySingleton<TSingleton>()->EmptyAttributes;
+ return *LeakyRefCountedSingleton<TEmptyAttributeDictionary>();
}
////////////////////////////////////////////////////////////////////////////////
@@ -157,7 +158,7 @@ public:
: Underlying_(underlying)
{ }
- std::vector<TString> ListKeys() const override
+ std::vector<TKey> ListKeys() const override
{
auto guard = ReaderGuard(Lock_);
return Underlying_->ListKeys();
@@ -169,19 +170,19 @@ public:
return Underlying_->ListPairs();
}
- NYson::TYsonString FindYson(TStringBuf key) const override
+ TValue FindYson(TKeyView key) const override
{
auto guard = ReaderGuard(Lock_);
return Underlying_->FindYson(key);
}
- void SetYson(const TString& key, const NYson::TYsonString& value) override
+ void SetYson(TKeyView key, const TValue& value) override
{
auto guard = WriterGuard(Lock_);
Underlying_->SetYson(key, value);
}
- bool Remove(const TString& key) override
+ bool Remove(TKeyView key) override
{
auto guard = WriterGuard(Lock_);
return Underlying_->Remove(key);
@@ -300,7 +301,7 @@ void TAttributeDictionarySerializer::LoadNonNull(TStreamLoadContext& context, co
////////////////////////////////////////////////////////////////////////////////
-void ValidateYTreeKey(TStringBuf key)
+void ValidateYTreeKey(IAttributeDictionary::TKeyView key)
{
Y_UNUSED(key);
// XXX(vvvv): Disabled due to existing data with empty keys, see https://st.yandex-team.ru/YQL-2640
diff --git a/yt/yt/core/ytree/helpers.h b/yt/yt/core/ytree/helpers.h
index 2d5b4fc8ec..a51a237596 100644
--- a/yt/yt/core/ytree/helpers.h
+++ b/yt/yt/core/ytree/helpers.h
@@ -1,6 +1,7 @@
#pragma once
#include "public.h"
+#include "attributes.h"
#include <yt/yt/core/misc/serialize.h>
@@ -46,15 +47,14 @@ struct TAttributeDictionarySerializer
////////////////////////////////////////////////////////////////////////////////
-void ValidateYTreeKey(TStringBuf key);
+void ValidateYTreeKey(IAttributeDictionary::TKeyView key);
void ValidateYPathResolutionDepth(TYPathBuf path, int depth);
//! Helps implementing IAttributeDictionary::ListPairs by delegating to
//! IAttributeDictionary::ListKeys and IAttributeDictionary::FindYson for those not capable
//! of providing a custom efficient implementation.
-std::vector<std::pair<TString, NYson::TYsonString>> ListAttributesPairs(const IAttributeDictionary& attributes);
-
+std::vector<std::pair<IAttributeDictionary::TKey, NYson::TYsonString>> ListAttributesPairs(const IAttributeDictionary& attributes);
////////////////////////////////////////////////////////////////////////////////
diff --git a/yt/yt/core/ytree/unittests/attributes_ut.cpp b/yt/yt/core/ytree/unittests/attributes_ut.cpp
index b53fafdaf6..f0f4c9ff9e 100644
--- a/yt/yt/core/ytree/unittests/attributes_ut.cpp
+++ b/yt/yt/core/ytree/unittests/attributes_ut.cpp
@@ -2,6 +2,7 @@
#include <yt/yt/core/ytree/attributes.h>
#include <yt/yt/core/ytree/convert.h>
+#include <yt/yt/core/ytree/helpers.h>
#include <yt/yt/core/yson/string.h>
diff --git a/yt/yt/core/ytree/ypath_detail.cpp b/yt/yt/core/ytree/ypath_detail.cpp
index a0b5d421f6..f9f2ee05d7 100644
--- a/yt/yt/core/ytree/ypath_detail.cpp
+++ b/yt/yt/core/ytree/ypath_detail.cpp
@@ -280,9 +280,9 @@ TSupportsAttributes::TCombinedAttributeDictionary::TCombinedAttributeDictionary(
: Owner_(owner)
{ }
-std::vector<TString> TSupportsAttributes::TCombinedAttributeDictionary::ListKeys() const
+auto TSupportsAttributes::TCombinedAttributeDictionary::ListKeys() const -> std::vector<TKey>
{
- std::vector<TString> keys;
+ std::vector<TKey> keys;
auto* provider = Owner_->GetBuiltinAttributeProvider();
if (provider) {
@@ -305,7 +305,7 @@ std::vector<TString> TSupportsAttributes::TCombinedAttributeDictionary::ListKeys
return keys;
}
-std::vector<IAttributeDictionary::TKeyValuePair> TSupportsAttributes::TCombinedAttributeDictionary::ListPairs() const
+auto TSupportsAttributes::TCombinedAttributeDictionary::ListPairs() const -> std::vector<TKeyValuePair>
{
std::vector<TKeyValuePair> pairs;
@@ -334,7 +334,7 @@ std::vector<IAttributeDictionary::TKeyValuePair> TSupportsAttributes::TCombinedA
return pairs;
}
-TYsonString TSupportsAttributes::TCombinedAttributeDictionary::FindYson(TStringBuf key) const
+auto TSupportsAttributes::TCombinedAttributeDictionary::FindYson(TKeyView key) const -> TValue
{
auto* provider = Owner_->GetBuiltinAttributeProvider();
if (provider) {
@@ -354,7 +354,7 @@ TYsonString TSupportsAttributes::TCombinedAttributeDictionary::FindYson(TStringB
return customAttributes->FindYson(key);
}
-void TSupportsAttributes::TCombinedAttributeDictionary::SetYson(const TString& key, const TYsonString& value)
+void TSupportsAttributes::TCombinedAttributeDictionary::SetYson(TKeyView key, const TYsonString& value)
{
auto* provider = Owner_->GetBuiltinAttributeProvider();
if (provider) {
@@ -377,7 +377,7 @@ void TSupportsAttributes::TCombinedAttributeDictionary::SetYson(const TString& k
customAttributes->SetYson(key, value);
}
-bool TSupportsAttributes::TCombinedAttributeDictionary::Remove(const TString& key)
+bool TSupportsAttributes::TCombinedAttributeDictionary::Remove(TKeyView key)
{
auto* provider = Owner_->GetBuiltinAttributeProvider();
if (provider) {
diff --git a/yt/yt/core/ytree/ypath_detail.h b/yt/yt/core/ytree/ypath_detail.h
index 8615d5ce25..852f8bae93 100644
--- a/yt/yt/core/ytree/ypath_detail.h
+++ b/yt/yt/core/ytree/ypath_detail.h
@@ -322,11 +322,11 @@ private:
public:
explicit TCombinedAttributeDictionary(TSupportsAttributes* owner);
- std::vector<TString> ListKeys() const override;
+ std::vector<TKey> ListKeys() const override;
std::vector<TKeyValuePair> ListPairs() const override;
- NYson::TYsonString FindYson(TStringBuf key) const override;
- void SetYson(const TString& key, const NYson::TYsonString& value) override;
- bool Remove(const TString& key) override;
+ TValue FindYson(TKeyView key) const override;
+ void SetYson(TKeyView key, const TValue& value) override;
+ bool Remove(TKeyView key) override;
private:
TSupportsAttributes* const Owner_;