@@ -977,4 +977,124 @@ class TIndexChunkLoadContext {
977977 }
978978};
979979
980- }
980+ class TInsertTableRecordLoadContext {
981+ private:
982+ NColumnShard::Schema::EInsertTableIds RecType;
983+ ui64 PlanStep;
984+ ui64 WriteTxId;
985+ ui64 PathId;
986+ YDB_ACCESSOR_DEF (TString, DedupId);
987+ ui64 SchemaVersion;
988+ TString BlobIdString;
989+ std::optional<NOlap::TUnifiedBlobId> BlobId;
990+ TString MetadataString;
991+ std::optional<NKikimrTxColumnShard::TLogicalMetadata> Metadata;
992+ std::optional<ui64> RangeOffset;
993+ std::optional<ui64> RangeSize;
994+
995+ void Prepare (const IBlobGroupSelector* dsGroupSelector) {
996+ AFL_VERIFY (!PreparedFlag);
997+ PreparedFlag = true ;
998+ TString error;
999+ NOlap::TUnifiedBlobId blobId = NOlap::TUnifiedBlobId::ParseFromString (BlobIdString, dsGroupSelector, error);
1000+ Y_ABORT_UNLESS (blobId.IsValid (), " Failied to parse blob id: %s" , error.c_str ());
1001+ BlobId = blobId;
1002+
1003+ NKikimrTxColumnShard::TLogicalMetadata meta;
1004+ AFL_VERIFY (MetadataString);
1005+ Y_ABORT_UNLESS (meta.ParseFromString (MetadataString));
1006+ Metadata = std::move (meta);
1007+ AFL_VERIFY (!!RangeOffset == !!RangeSize);
1008+ }
1009+
1010+ bool PreparedFlag = false ;
1011+ bool ParsedFlag = false ;
1012+
1013+ public:
1014+ TInsertWriteId GetInsertWriteId () const {
1015+ AFL_VERIFY (ParsedFlag);
1016+ AFL_VERIFY (RecType != NColumnShard::Schema::EInsertTableIds::Committed);
1017+ return (TInsertWriteId)WriteTxId;
1018+ }
1019+
1020+ NColumnShard::Schema::EInsertTableIds GetRecType () const {
1021+ AFL_VERIFY (ParsedFlag);
1022+ return RecType;
1023+ }
1024+
1025+ ui64 GetPlanStep () const {
1026+ AFL_VERIFY (ParsedFlag);
1027+ return PlanStep;
1028+ }
1029+
1030+ void Remove (NIceDb::TNiceDb& db) {
1031+ AFL_VERIFY (ParsedFlag);
1032+ db.Table <NColumnShard::Schema::InsertTable>().Key ((ui8)RecType, PlanStep, WriteTxId, PathId, DedupId).Delete ();
1033+ }
1034+
1035+ void Upsert (NIceDb::TNiceDb& db) {
1036+ AFL_VERIFY (ParsedFlag);
1037+ using namespace NColumnShard ;
1038+ if (RangeOffset) {
1039+ db.Table <Schema::InsertTable>()
1040+ .Key ((ui8)RecType, PlanStep, WriteTxId, PathId, DedupId)
1041+ .Update (NIceDb::TUpdate<Schema::InsertTable::BlobId>(BlobIdString),
1042+ NIceDb::TUpdate<Schema::InsertTable::BlobRangeOffset>(*RangeOffset),
1043+ NIceDb::TUpdate<Schema::InsertTable::BlobRangeSize>(*RangeSize), NIceDb::TUpdate<Schema::InsertTable::Meta>(MetadataString),
1044+ NIceDb::TUpdate<Schema::InsertTable::SchemaVersion>(SchemaVersion));
1045+ } else {
1046+ db.Table <Schema::InsertTable>()
1047+ .Key ((ui8)RecType, PlanStep, WriteTxId, PathId, DedupId)
1048+ .Update (NIceDb::TUpdate<Schema::InsertTable::BlobId>(BlobIdString), NIceDb::TUpdate<Schema::InsertTable::Meta>(MetadataString),
1049+ NIceDb::TUpdate<Schema::InsertTable::SchemaVersion>(SchemaVersion));
1050+ }
1051+ }
1052+
1053+ template <class TRowset >
1054+ void ParseFromDatabase (TRowset& rowset) {
1055+ AFL_VERIFY (!ParsedFlag)(" problem" , " duplication parsing" );
1056+ ParsedFlag = true ;
1057+ using namespace NColumnShard ;
1058+ RecType = (Schema::EInsertTableIds)rowset.template GetValue <Schema::InsertTable::Committed>();
1059+ PlanStep = rowset.template GetValue <Schema::InsertTable::PlanStep>();
1060+ WriteTxId = rowset.template GetValueOrDefault <Schema::InsertTable::WriteTxId>();
1061+ AFL_VERIFY (WriteTxId);
1062+
1063+ PathId = rowset.template GetValue <Schema::InsertTable::PathId>();
1064+ DedupId = rowset.template GetValue <Schema::InsertTable::DedupId>();
1065+ SchemaVersion =
1066+ rowset.template HaveValue <Schema::InsertTable::SchemaVersion>() ? rowset.template GetValue <Schema::InsertTable::SchemaVersion>() : 0 ;
1067+ BlobIdString = rowset.template GetValue <Schema::InsertTable::BlobId>();
1068+ MetadataString = rowset.template GetValue <Schema::InsertTable::Meta>();
1069+ if (rowset.template HaveValue <Schema::InsertTable::BlobRangeOffset>()) {
1070+ RangeOffset = rowset.template GetValue <Schema::InsertTable::BlobRangeOffset>();
1071+ }
1072+ if (rowset.template HaveValue <Schema::InsertTable::BlobRangeSize>()) {
1073+ RangeSize = rowset.template GetValue <Schema::InsertTable::BlobRangeSize>();
1074+ }
1075+ }
1076+
1077+ NOlap::TCommittedData BuildCommitted (const IBlobGroupSelector* dsGroupSelector) {
1078+ Prepare (dsGroupSelector);
1079+ using namespace NColumnShard ;
1080+ AFL_VERIFY (RecType == Schema::EInsertTableIds::Committed);
1081+ auto userData = std::make_shared<NOlap::TUserData>(PathId,
1082+ NOlap::TBlobRange (*BlobId, RangeOffset.value_or (0 ), RangeSize.value_or (BlobId->BlobSize ())), *Metadata, SchemaVersion, std::nullopt );
1083+ AFL_VERIFY (!!DedupId);
1084+ AFL_VERIFY (PlanStep);
1085+ return NOlap::TCommittedData (userData, PlanStep, WriteTxId, DedupId);
1086+ }
1087+
1088+ NOlap::TInsertedData BuildInsertedOrAborted (const IBlobGroupSelector* dsGroupSelector) {
1089+ Prepare (dsGroupSelector);
1090+ using namespace NColumnShard ;
1091+ AFL_VERIFY (RecType != Schema::EInsertTableIds::Committed);
1092+ auto userData = std::make_shared<NOlap::TUserData>(PathId,
1093+ NOlap::TBlobRange (*BlobId, RangeOffset.value_or (0 ), RangeSize.value_or (BlobId->BlobSize ())), *Metadata, SchemaVersion, std::nullopt );
1094+ AFL_VERIFY (!DedupId);
1095+ AFL_VERIFY (!PlanStep);
1096+ return NOlap::TInsertedData ((TInsertWriteId)WriteTxId, userData);
1097+ }
1098+ };
1099+
1100+ } // namespace NKikimr::NOlap
0 commit comments