aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordanilalexeev <danilalexeev@yandex-team.com>2023-12-05 00:30:52 +0300
committerdanilalexeev <danilalexeev@yandex-team.com>2023-12-05 07:59:23 +0300
commit4288daba4990d7137ae55f2767eecc98c38ee7a6 (patch)
tree80bfde45a868f5b5cbd970454e84caf344cc6a08
parentd287ea81ce0e08a8db8839a7d764c7178c1086c6 (diff)
downloadydb-4288daba4990d7137ae55f2767eecc98c38ee7a6.tar.gz
YT-20350: Sequoia Set command
-rw-r--r--yt/yt/client/object_client/helpers.cpp1
-rw-r--r--yt/yt/core/misc/collection_helpers-inl.h7
-rw-r--r--yt/yt/core/misc/collection_helpers.h4
-rw-r--r--yt/yt/core/ytree/ypath_detail.cpp68
-rw-r--r--yt/yt/core/ytree/ypath_detail.h19
5 files changed, 46 insertions, 53 deletions
diff --git a/yt/yt/client/object_client/helpers.cpp b/yt/yt/client/object_client/helpers.cpp
index 902cdc2906..773fe000ac 100644
--- a/yt/yt/client/object_client/helpers.cpp
+++ b/yt/yt/client/object_client/helpers.cpp
@@ -20,7 +20,6 @@ bool IsScalarType(EObjectType type)
type == EObjectType::Int64Node ||
type == EObjectType::Uint64Node ||
type == EObjectType::DoubleNode ||
- type == EObjectType::ListNode ||
type == EObjectType::BooleanNode;
}
diff --git a/yt/yt/core/misc/collection_helpers-inl.h b/yt/yt/core/misc/collection_helpers-inl.h
index fa4ccc6b73..0b50ba117a 100644
--- a/yt/yt/core/misc/collection_helpers-inl.h
+++ b/yt/yt/core/misc/collection_helpers-inl.h
@@ -350,13 +350,6 @@ const T& VectorAtOr(const std::vector<T>& vector, ssize_t index, const T& defaul
return index < static_cast<ssize_t>(vector.size()) ? vector[index] : defaultValue;
}
-template <class T>
-bool CheckIfValuesUnique(std::vector<T> vector)
-{
- std::sort(vector.begin(), vector.end());
- return std::unique(vector.begin(), vector.end()) == vector.end();
-}
-
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
diff --git a/yt/yt/core/misc/collection_helpers.h b/yt/yt/core/misc/collection_helpers.h
index 50dad94db7..9719a5da6c 100644
--- a/yt/yt/core/misc/collection_helpers.h
+++ b/yt/yt/core/misc/collection_helpers.h
@@ -154,10 +154,6 @@ void AssignVectorAt(std::vector<T>& vector, ssize_t index, T&& value, const T& d
template <class T>
const T& VectorAtOr(const std::vector<T>& vector, ssize_t index, const T& defaultValue = T());
-//! Checks if values stored in vector are unique.
-template <class T>
-bool CheckIfValuesUnique(std::vector<T> vector);
-
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
diff --git a/yt/yt/core/ytree/ypath_detail.cpp b/yt/yt/core/ytree/ypath_detail.cpp
index 55103fee73..644bf1632a 100644
--- a/yt/yt/core/ytree/ypath_detail.cpp
+++ b/yt/yt/core/ytree/ypath_detail.cpp
@@ -1281,7 +1281,7 @@ const THashSet<TString>& TOpaqueAttributeKeysCache::GetOpaqueAttributeKeys(
////////////////////////////////////////////////////////////////////////////////
class TNodeSetterBase
- : public NYson::TForwardingYsonConsumer
+ : public TTypedConsumer
{
public:
void Commit();
@@ -1290,20 +1290,6 @@ protected:
TNodeSetterBase(INode* node, ITreeBuilder* builder);
~TNodeSetterBase();
- void ThrowInvalidType(ENodeType actualType);
- virtual ENodeType GetExpectedType() = 0;
-
- void OnMyStringScalar(TStringBuf value) override;
- void OnMyInt64Scalar(i64 value) override;
- void OnMyUint64Scalar(ui64 value) override;
- void OnMyDoubleScalar(double value) override;
- void OnMyBooleanScalar(bool value) override;
- void OnMyEntity() override;
-
- void OnMyBeginList() override;
-
- void OnMyBeginMap() override;
-
void OnMyBeginAttributes() override;
void OnMyEndAttributes() override;
@@ -1409,9 +1395,6 @@ public:
private:
IMapNode* const Map_;
- TString ItemKey_;
-
-
ENodeType GetExpectedType() override
{
return ENodeType::Map;
@@ -1424,15 +1407,15 @@ private:
void OnMyKeyedItem(TStringBuf key) override
{
- ItemKey_ = key;
+ YT_VERIFY(TreeBuilder_);
+
TreeBuilder_->BeginTree();
- Forward(TreeBuilder_, std::bind(&TNodeSetter::OnForwardingFinished, this));
+ Forward(TreeBuilder_, std::bind(&TNodeSetter::OnForwardingFinished, this, TString(key)));
}
- void OnForwardingFinished()
+ void OnForwardingFinished(TString itemKey)
{
- YT_VERIFY(Map_->AddChild(ItemKey_, TreeBuilder_->EndTree()));
- ItemKey_.clear();
+ YT_VERIFY(Map_->AddChild(itemKey, TreeBuilder_->EndTree()));
}
void OnMyEndMap() override
@@ -1469,6 +1452,8 @@ private:
void OnMyListItem() override
{
+ YT_VERIFY(TreeBuilder_);
+
TreeBuilder_->BeginTree();
Forward(TreeBuilder_, [this] {
List_->AddChild(TreeBuilder_->EndTree());
@@ -1537,61 +1522,63 @@ private:
////////////////////////////////////////////////////////////////////////////////
-TNodeSetterBase::TNodeSetterBase(INode* node, ITreeBuilder* builder)
- : Node_(node)
- , TreeBuilder_(builder)
- , NodeFactory_(node->CreateFactory())
-{ }
-
-TNodeSetterBase::~TNodeSetterBase() = default;
-
-void TNodeSetterBase::ThrowInvalidType(ENodeType actualType)
+void TTypedConsumer::ThrowInvalidType(ENodeType actualType)
{
THROW_ERROR_EXCEPTION("Cannot update %Qlv node with %Qlv value; types must match",
GetExpectedType(),
actualType);
}
-void TNodeSetterBase::OnMyStringScalar(TStringBuf /*exists*/)
+void TTypedConsumer::OnMyStringScalar(TStringBuf /*exists*/)
{
ThrowInvalidType(ENodeType::String);
}
-void TNodeSetterBase::OnMyInt64Scalar(i64 /*exists*/)
+void TTypedConsumer::OnMyInt64Scalar(i64 /*exists*/)
{
ThrowInvalidType(ENodeType::Int64);
}
-void TNodeSetterBase::OnMyUint64Scalar(ui64 /*exists*/)
+void TTypedConsumer::OnMyUint64Scalar(ui64 /*exists*/)
{
ThrowInvalidType(ENodeType::Uint64);
}
-void TNodeSetterBase::OnMyDoubleScalar(double /*exists*/)
+void TTypedConsumer::OnMyDoubleScalar(double /*exists*/)
{
ThrowInvalidType(ENodeType::Double);
}
-void TNodeSetterBase::OnMyBooleanScalar(bool /*exists*/)
+void TTypedConsumer::OnMyBooleanScalar(bool /*exists*/)
{
ThrowInvalidType(ENodeType::Boolean);
}
-void TNodeSetterBase::OnMyEntity()
+void TTypedConsumer::OnMyEntity()
{
ThrowInvalidType(ENodeType::Entity);
}
-void TNodeSetterBase::OnMyBeginList()
+void TTypedConsumer::OnMyBeginList()
{
ThrowInvalidType(ENodeType::List);
}
-void TNodeSetterBase::OnMyBeginMap()
+void TTypedConsumer::OnMyBeginMap()
{
ThrowInvalidType(ENodeType::Map);
}
+////////////////////////////////////////////////////////////////////////////////
+
+TNodeSetterBase::TNodeSetterBase(INode* node, ITreeBuilder* builder)
+ : Node_(node)
+ , TreeBuilder_(builder)
+ , NodeFactory_(node->CreateFactory())
+{ }
+
+TNodeSetterBase::~TNodeSetterBase() = default;
+
void TNodeSetterBase::OnMyBeginAttributes()
{
AttributesSetter_.reset(new TAttributesSetter(Node_->MutableAttributes()));
@@ -1616,7 +1603,6 @@ void SetNodeFromProducer(
ITreeBuilder* builder)
{
YT_VERIFY(node);
- YT_VERIFY(builder);
switch (node->GetType()) {
#define XX(type) \
diff --git a/yt/yt/core/ytree/ypath_detail.h b/yt/yt/core/ytree/ypath_detail.h
index 2cb43648d6..e52b8cd929 100644
--- a/yt/yt/core/ytree/ypath_detail.h
+++ b/yt/yt/core/ytree/ypath_detail.h
@@ -368,6 +368,25 @@ private:
////////////////////////////////////////////////////////////////////////////////
+class TTypedConsumer
+ : public NYson::TForwardingYsonConsumer
+{
+protected:
+ void ThrowInvalidType(ENodeType actualType);
+ virtual ENodeType GetExpectedType() = 0;
+
+ void OnMyStringScalar(TStringBuf value) override;
+ void OnMyInt64Scalar(i64 value) override;
+ void OnMyUint64Scalar(ui64 value) override;
+ void OnMyDoubleScalar(double value) override;
+ void OnMyBooleanScalar(bool value) override;
+ void OnMyEntity() override;
+
+ void OnMyBeginList() override;
+
+ void OnMyBeginMap() override;
+};
+
void SetNodeFromProducer(
const INodePtr& node,
const NYson::TYsonProducer& producer,