Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions ydb/core/kqp/runtime/kqp_write_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,6 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub

void Handle(TEvBufferWrite::TPtr& ev) {
Counters->ForwardActorWritesLatencyHistogram->Collect((TInstant::Now() - ev->Get()->SendTime).MicroSeconds());

TWriteToken token;
if (!ev->Get()->Token) {
AFL_ENSURE(ev->Get()->Settings);
Expand Down Expand Up @@ -2967,6 +2966,12 @@ class TKqpForwardWriteActor : public TActorBootstrapped<TKqpForwardWriteActor>,

void Handle(TEvBufferWriteResult::TPtr& result) {
CA_LOG_D("TKqpForwardWriteActor recieve EvBufferWriteResult from " << BufferActorId);

WriteToken = result->Get()->Token;
OnFlushed();
}

void OnFlushed() {
InFlight = false;

EgressStats.Bytes += DataSize;
Expand All @@ -2975,8 +2980,6 @@ class TKqpForwardWriteActor : public TActorBootstrapped<TKqpForwardWriteActor>,
EgressStats.Resume();

Counters->ForwardActorWritesSizeHistogram->Collect(DataSize);

WriteToken = result->Get()->Token;
DataSize = 0;

if (Closed) {
Expand Down Expand Up @@ -3032,6 +3035,12 @@ class TKqpForwardWriteActor : public TActorBootstrapped<TKqpForwardWriteActor>,

ev->SendTime = TInstant::Now();

if (ev->Data->IsEmpty() && ev->Close && WriteToken.IsEmpty()) {
// Nothing was written
OnFlushed();
return;
}

CA_LOG_D("Send data=" << DataSize << ", closed=" << Closed << ", bufferActorId=" << BufferActorId);
AFL_ENSURE(Send(BufferActorId, ev.release()));
}
Expand Down
54 changes: 54 additions & 0 deletions ydb/core/kqp/ut/query/kqp_query_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2580,6 +2580,60 @@ Y_UNIT_TEST_SUITE(KqpQuery) {
}
}

Y_UNIT_TEST_TWIN(UpdateThenDelete, UseSink) {
NKikimrConfig::TAppConfig appConfig;
appConfig.MutableTableServiceConfig()->SetEnableOltpSink(UseSink);
auto settings = TKikimrSettings()
.SetAppConfig(appConfig)
.SetWithSampleTables(true);

TKikimrRunner kikimr(settings);
auto client = kikimr.GetTableClient();

{
const TString query = R"(
DECLARE $data AS List<Struct<
Key: String,
Value: String
>>;

UPSERT INTO KeyValue2 SELECT * FROM AS_TABLE($data);

DELETE FROM KeyValue2 ON SELECT * FROM KeyValue2 AS a LEFT ONLY JOIN AS_TABLE($data) AS b USING (Key);
)";

TTypeBuilder builder;
builder
.BeginStruct()
.AddMember("Key", TTypeBuilder().Primitive(NYdb::EPrimitiveType::String).Build())
.AddMember("Value", TTypeBuilder().Primitive(NYdb::EPrimitiveType::String).Build())
.EndStruct();

auto params = client.GetParamsBuilder()
.AddParam("$data")
.EmptyList(builder.Build())
.Build()
.Build();

auto session = client.CreateSession().GetValueSync().GetSession();
auto result = session.ExecuteDataQuery(query, NYdb::NTable::TTxControl::BeginTx().CommitTx(), std::move(params)).ExtractValueSync();
UNIT_ASSERT_C(result.GetStatus() == NYdb::EStatus::SUCCESS, result.GetIssues().ToString());

}
{
const TString query = R"(
SELECT * FROM KeyValue2;
)";

auto session = client.CreateSession().GetValueSync().GetSession();
auto result = session.ExecuteDataQuery(query, NYdb::NTable::TTxControl::BeginTx().CommitTx()).ExtractValueSync();
UNIT_ASSERT_C(result.GetStatus() == NYdb::EStatus::SUCCESS, result.GetIssues().ToString());

Cerr << FormatResultSetYson(result.GetResultSet(0)) << Endl;
UNIT_ASSERT_VALUES_EQUAL(0, result.GetResultSet(0).RowsCount());
}
}

}

} // namespace NKqp
Expand Down
Loading