From 68d7b4c742db3799663eb7a6d02b3d062bfe7894 Mon Sep 17 00:00:00 2001 From: Vadim Averin Date: Tue, 14 May 2024 18:01:22 +0300 Subject: [PATCH] Preserve important attributes in TRUNCATE, KEEP_META mode (#4370) --- .../yt/gateway/native/yql_yt_native.cpp | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/ydb/library/yql/providers/yt/gateway/native/yql_yt_native.cpp b/ydb/library/yql/providers/yt/gateway/native/yql_yt_native.cpp index f25e459fa0a5..f0468382da0f 100644 --- a/ydb/library/yql/providers/yt/gateway/native/yql_yt_native.cpp +++ b/ydb/library/yql/providers/yt/gateway/native/yql_yt_native.cpp @@ -2071,8 +2071,9 @@ class TYtNativeGateway : public IYtGateway { appendToSorted = attrs.HasKey("sorted_by") && !attrs["sorted_by"].AsList().empty(); } - NYT::TNode storageAttrs = NYT::TNode::CreateMap(); auto yqlAttrs = NYT::TNode::CreateMap(); + + auto storageAttrs = NYT::TNode::CreateMap(); if (appendToSorted || EYtWriteMode::RenewKeepMeta == mode) { yqlAttrs = GetUserAttributes(entry->Tx, dstPath, false); storageAttrs = entry->Tx->Get(dstPath + "/@", TGetOptions() @@ -2086,8 +2087,30 @@ class TYtNativeGateway : public IYtGateway { ); } + bool forceMerge = combineChunks; + NYT::MergeNodes(yqlAttrs, GetUserAttributes(entry->Tx, srcPaths.back(), true)); NYT::MergeNodes(yqlAttrs, YqlOpOptionsToAttrs(execCtx->Session_->OperationOptions_)); + if (EYtWriteMode::RenewKeepMeta == mode) { + auto dstAttrs = entry->Tx->Get(dstPath + "/@", TGetOptions() + .AttributeFilter(TAttributeFilter() + .AddAttribute("annotation") + .AddAttribute("expiration_time") + .AddAttribute("expiration_timeout") + .AddAttribute("tablet_cell_bundle") + .AddAttribute("enable_dynamic_store_read") + ) + ); + if (dstAttrs.AsMap().contains("tablet_cell_bundle") && dstAttrs["tablet_cell_bundle"] != "default") { + forceMerge = true; + } + dstAttrs.AsMap().erase("tablet_cell_bundle"); + if (dstAttrs.AsMap().contains("enable_dynamic_store_read")) { + forceMerge = true; + } + dstAttrs.AsMap().erase("enable_dynamic_store_read"); + NYT::MergeNodes(yqlAttrs, dstAttrs); + } NYT::TNode& rowSpecNode = yqlAttrs[YqlRowSpecAttribute]; const auto nativeYtTypeCompatibility = execCtx->Options_.Config()->NativeYtTypeCompatibility.Get(cluster).GetOrElse(NTCF_LEGACY); const bool rowSpecCompactForm = execCtx->Options_.Config()->UseYqlRowSpecCompactForm.Get().GetOrElse(DEFAULT_ROW_SPEC_COMPACT_FORM); @@ -2102,7 +2125,7 @@ class TYtNativeGateway : public IYtGateway { } }; - if (EYtWriteMode::Renew == mode) { + if (EYtWriteMode::Renew == mode || EYtWriteMode::RenewKeepMeta == mode) { const auto expirationIt = strOpts.find(EYtSettingType::Expiration); bool isTimestamp = false, isDuration = false; TInstant stamp; @@ -2139,7 +2162,6 @@ class TYtNativeGateway : public IYtGateway { } } - bool forceMerge = combineChunks; bool forceTransform = false; #define DEFINE_OPT(name, attr, transform) \