aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-12-02 11:02:47 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-12-02 11:13:04 +0300
commit86b4fd25df0fbd034316632a76de130eea8f05eb (patch)
tree3dcf51b8a9f9c0abeece6836c215630101c5872e
parent862a269ad6191fa7590f00e58cfca2340184e625 (diff)
downloadydb-86b4fd25df0fbd034316632a76de130eea8f05eb.tar.gz
Intermediate changes
commit_hash:dc321fcfde009c14588e2727210c9ac8b9c06129
-rw-r--r--yt/yt/core/ytree/polymorphic_yson_struct-inl.h40
-rw-r--r--yt/yt/core/ytree/polymorphic_yson_struct.h8
2 files changed, 46 insertions, 2 deletions
diff --git a/yt/yt/core/ytree/polymorphic_yson_struct-inl.h b/yt/yt/core/ytree/polymorphic_yson_struct-inl.h
index de5b3ab7ef..d0a4f2b6a8 100644
--- a/yt/yt/core/ytree/polymorphic_yson_struct-inl.h
+++ b/yt/yt/core/ytree/polymorphic_yson_struct-inl.h
@@ -4,6 +4,8 @@
#include "polymorphic_yson_struct.h"
#endif
+#include <yt/yt/core/misc/error.h>
+
namespace NYT::NYTree {
////////////////////////////////////////////////////////////////////////////////
@@ -50,7 +52,8 @@ TPolymorphicYsonStruct<TMapping>::TPolymorphicYsonStruct(TKey key)
template <CPolymorphicEnumMapping TMapping>
TPolymorphicYsonStruct<TMapping>::TPolymorphicYsonStruct(TKey key, TIntrusivePtr<TBase> ptr) noexcept
- : Storage_(std::move(ptr))
+ : Storage_(ptr)
+ , SerializedStorage_(ConvertToNode(ptr))
, HeldType_(key)
{
YT_VERIFY(Storage_);
@@ -71,7 +74,8 @@ void TPolymorphicYsonStruct<TMapping>::Load(
// conversion smth? FillMap wont work since we
// do not know the value_type of a map we would
// parse (unless we want to slice which we don't).
- IMapNodePtr map = TTraits::AsNode(source)->AsMap();
+ SerializedStorage_ = TTraits::AsNode(source);
+ IMapNodePtr map = SerializedStorage_->AsMap();
if (!map || map->GetChildCount() == 0) {
// Empty struct.
@@ -154,6 +158,38 @@ const typename TPolymorphicYsonStruct<TMapping>::TBase* TPolymorphicYsonStruct<T
return Storage_.Get();
}
+template <CPolymorphicEnumMapping TMapping>
+void TPolymorphicYsonStruct<TMapping>::MergeWith(const TPolymorphicYsonStruct& other)
+{
+ if (!Storage_) {
+ *this = other;
+ return;
+ }
+
+ THROW_ERROR_EXCEPTION_UNLESS(
+ GetCurrentType() == other.GetCurrentType(),
+ "Can't merge polymorphic yson structs with different types stored (ThisType: %v, OtherType: %v)",
+ GetCurrentType(),
+ other.GetCurrentType());
+
+ SerializedStorage_ = PatchNode(SerializedStorage_, other.SerializedStorage_);
+
+ // NB(arkady-e1ppa): Since if there ever was a recursiveUnrecognizedStrategy, it would be kept
+ // in storage, so it is okay to supply nullopt.
+ Load(
+ SerializedStorage_,
+ /*postprocess*/ true,
+ /*setDefaults*/ true,
+ /*path*/ "",
+ /*recursiveUnrecognizedStrategy*/ std::nullopt);
+}
+
+template <CPolymorphicEnumMapping TMapping>
+TPolymorphicYsonStruct<TMapping>::operator bool() const
+{
+ return Storage_.operator bool();
+}
+
////////////////////////////////////////////////////////////////////////////////
template <CPolymorphicEnumMapping TMapping>
diff --git a/yt/yt/core/ytree/polymorphic_yson_struct.h b/yt/yt/core/ytree/polymorphic_yson_struct.h
index 64566fce4a..3c89ee758b 100644
--- a/yt/yt/core/ytree/polymorphic_yson_struct.h
+++ b/yt/yt/core/ytree/polymorphic_yson_struct.h
@@ -170,8 +170,16 @@ public:
TBase* operator->();
const TBase* operator->() const;
+ void MergeWith(const TPolymorphicYsonStruct& other);
+
+ explicit operator bool() const;
+
private:
TIntrusivePtr<TBase> Storage_;
+ // TODO(arkady-e1ppa): This is a hotfix so that we don't have to bring
+ // "IsSet" logic for yson structs to 24.2. Write a "better" solution for trunk
+ // later.
+ INodePtr SerializedStorage_;
TKey HeldType_;
void PrepareInstance(INodePtr& node);