@@ -29,23 +29,32 @@ std::set<ui32> ISnapshotSchema::GetPkColumnsIds() const {
29
29
30
30
TConclusion<std::shared_ptr<NArrow::TGeneralContainer>> ISnapshotSchema::NormalizeBatch (
31
31
const ISnapshotSchema& dataSchema, const std::shared_ptr<NArrow::TGeneralContainer>& batch, const std::set<ui32>& restoreColumnIds) const {
32
+ AFL_VERIFY (dataSchema.GetSnapshot () <= GetSnapshot ());
32
33
if (dataSchema.GetSnapshot () == GetSnapshot ()) {
33
- return batch;
34
+ if (batch->GetColumnsCount () == GetColumnsCount ()) {
35
+ return batch;
36
+ }
34
37
}
35
- AFL_VERIFY (dataSchema.GetSnapshot () < GetSnapshot ());
36
38
const std::shared_ptr<arrow::Schema>& resultArrowSchema = GetSchema ();
37
39
38
- std::shared_ptr<NArrow::TGeneralContainer> result = std::make_shared<NArrow::TGeneralContainer>(batch->GetRecordsCountVerified ());
40
+ std::shared_ptr<NArrow::TGeneralContainer> result = std::make_shared<NArrow::TGeneralContainer>(batch->GetRecordsCount ());
39
41
for (size_t i = 0 ; i < resultArrowSchema->fields ().size (); ++i) {
40
42
auto & resultField = resultArrowSchema->fields ()[i];
41
43
auto columnId = GetIndexInfo ().GetColumnId (resultField->name ());
42
44
auto oldField = dataSchema.GetFieldByColumnIdOptional (columnId);
43
45
if (oldField) {
44
- auto conclusion = result->AddField (resultField, batch->GetAccessorByNameVerified (oldField->name ()));
45
- if (conclusion.IsFail ()) {
46
- return conclusion;
46
+ auto fAccessor = batch->GetAccessorByNameOptional (oldField->name ());
47
+ if (fAccessor ) {
48
+ auto conclusion = result->AddField (resultField, fAccessor );
49
+ if (conclusion.IsFail ()) {
50
+ return conclusion;
51
+ }
52
+ continue ;
47
53
}
48
- } else if (restoreColumnIds.contains (columnId)) {
54
+ }
55
+ if (restoreColumnIds.contains (columnId)) {
56
+ AFL_VERIFY (!!GetExternalDefaultValueVerified (columnId) || GetIndexInfo ().IsNullableVerified (columnId))(" column_name" ,
57
+ GetIndexInfo ().GetColumnName (columnId, false ))(" id" , columnId);
49
58
result->AddField (resultField,
50
59
NArrow::TThreadSimpleArraysCache::Get (resultField->type (), GetExternalDefaultValueVerified (columnId), batch->num_rows ()))
51
60
.Validate ();
@@ -107,8 +116,9 @@ TConclusion<std::shared_ptr<arrow::RecordBatch>> ISnapshotSchema::PrepareForModi
107
116
Y_DEBUG_ABORT_UNLESS (NArrow::IsSortedAndUnique (batch, GetIndexInfo ().GetPrimaryKey ()));
108
117
109
118
switch (mType ) {
119
+ case NEvWrite::EModificationType::Replace:
110
120
case NEvWrite::EModificationType::Upsert: {
111
- AFL_VERIFY (batch->num_columns () <= dstSchema->num_fields ());
121
+ AFL_VERIFY (batch->num_columns () <= dstSchema->num_fields ());
112
122
if (batch->num_columns () < dstSchema->num_fields ()) {
113
123
for (auto && f : dstSchema->fields ()) {
114
124
if (GetIndexInfo ().IsNullableVerified (f->name ())) {
@@ -125,7 +135,6 @@ TConclusion<std::shared_ptr<arrow::RecordBatch>> ISnapshotSchema::PrepareForModi
125
135
return batch;
126
136
}
127
137
case NEvWrite::EModificationType::Delete:
128
- case NEvWrite::EModificationType::Replace:
129
138
case NEvWrite::EModificationType::Insert:
130
139
case NEvWrite::EModificationType::Update:
131
140
return batch;
0 commit comments