Skip to content

Commit 07355d0

Browse files
committed
datashard: add NULL value check to TValidatedWriteTxOperation::ParseOperation
Fixes #21475
1 parent 1f6c060 commit 07355d0

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

ydb/core/tx/datashard/datashard_ut_write.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ Y_UNIT_TEST_SUITE(DataShardWrite) {
557557
Y_UNIT_TEST(WriteImmediateBadRequest) {
558558
auto [runtime, server, sender] = TestCreateServer();
559559

560-
auto opts = TShardedTableOptions().Columns({{"key", "Utf8", true, false}});
560+
auto opts = TShardedTableOptions().Columns({{"key", "Utf8", true, true}});
561561
auto [shards, tableId] = CreateShardedTable(server, sender, "/Root", "table-1", opts);
562562
const ui64 shard = shards[0];
563563

@@ -595,6 +595,19 @@ Y_UNIT_TEST_SUITE(DataShardWrite) {
595595
UNIT_ASSERT_VALUES_EQUAL(writeResult.GetIssues().size(), 1);
596596
UNIT_ASSERT(writeResult.GetIssues(0).message().Contains("OPERATION_UNSPECIFIED operation is not supported now"));
597597
}
598+
599+
Cout << "========= Send immediate write with NULL value for NOT NULL column=========\n";
600+
{
601+
TSerializedCellMatrix matrix({TCell{}}, 1, 1);
602+
603+
auto evWrite = std::make_unique<NKikimr::NEvents::TDataEvents::TEvWrite>(100, NKikimrDataEvents::TEvWrite::MODE_IMMEDIATE);
604+
ui64 payloadIndex = NKikimr::NEvWrite::TPayloadWriter<NKikimr::NEvents::TDataEvents::TEvWrite>(*evWrite).AddDataToPayload(matrix.ReleaseBuffer());
605+
evWrite->AddOperation(NKikimrDataEvents::TEvWrite::TOperation::OPERATION_UPSERT, tableId, {1}, payloadIndex, NKikimrDataEvents::FORMAT_CELLVEC);
606+
607+
const auto writeResult = Write(runtime, sender, shard, std::move(evWrite), NKikimrDataEvents::TEvWriteResult::STATUS_BAD_REQUEST);
608+
UNIT_ASSERT_VALUES_EQUAL(writeResult.GetIssues().size(), 1);
609+
UNIT_ASSERT(writeResult.GetIssues(0).message().Contains("NULL value for NON NULL column"));
610+
}
598611
}
599612

600613
Y_UNIT_TEST(WriteImmediateSeveralOperations) {

ydb/core/tx/datashard/datashard_write_operation.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,20 @@ std::tuple<NKikimrTxDataShard::TError::EKind, TString> TValidatedWriteTxOperatio
146146
return {NKikimrTxDataShard::TError::SCHEME_ERROR, TStringBuilder() << "Key column schema at position " << i};
147147
}
148148

149-
for (ui32 columnTag : ColumnIds) {
149+
for (ui16 colIdx = 0; colIdx < ColumnIds.size(); ++colIdx) {
150+
ui32 columnTag = ColumnIds[colIdx];
150151
auto* col = tableInfo.Columns.FindPtr(columnTag);
151152
if (!col)
152153
return {NKikimrTxDataShard::TError::SCHEME_ERROR, TStringBuilder() << "Missing column with id " << columnTag};
154+
155+
if (col->NotNull) {
156+
for (ui32 rowIdx = 0; rowIdx < Matrix.GetRowCount(); ++rowIdx) {
157+
const TCell& cell = Matrix.GetCell(rowIdx, colIdx);
158+
if (cell.IsNull()) {
159+
return {NKikimrTxDataShard::TError::BAD_ARGUMENT, TStringBuilder() << "NULL value for NON NULL column " << columnTag};
160+
}
161+
}
162+
}
153163
}
154164

155165
for (ui32 rowIdx = 0; rowIdx < Matrix.GetRowCount(); ++rowIdx)

0 commit comments

Comments
 (0)