Skip to content

Commit d68c1c1

Browse files
authored
Embed short blobs in TCell, fix empty string (#13194)
1 parent bc52487 commit d68c1c1

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

ydb/core/kqp/runtime/kqp_write_table.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,14 @@ class TRowBuilder {
278278
? NYql::NUdf::TStringRef(cellInfo.PgBinaryValue)
279279
: cellInfo.Value.AsStringRef();
280280

281-
char* initialPtr = dataPtr;
282-
std::memcpy(initialPtr, ref.Data(), ref.Size());
283-
dataPtr += ref.Size();
284-
return TCell(initialPtr, ref.Size());
281+
if (TCell::CanInline(ref.Size())) {
282+
return TCell(ref.Data(), ref.Size());
283+
} else {
284+
char* initialPtr = dataPtr;
285+
std::memcpy(initialPtr, ref.Data(), ref.Size());
286+
dataPtr += ref.Size();
287+
return TCell(initialPtr, ref.Size());
288+
}
285289
}
286290

287291
size_t GetCellSize(const TCellInfo& cellInfo) const {
@@ -301,7 +305,8 @@ class TRowBuilder {
301305
if (cellInfo.Type.GetTypeId() == NScheme::NTypeIds::Pg) {
302306
return cellInfo.PgBinaryValue.size();
303307
}
304-
return cellInfo.Value.AsStringRef().Size();
308+
const auto s = cellInfo.Value.AsStringRef().Size();
309+
return TCell::CanInline(s) ? 0 : s;
305310
}
306311

307312
TCharVectorPtr Allocate(size_t size) {

ydb/core/kqp/ut/olap/kqp_olap_ut.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,6 +3122,44 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
31223122
)", FormatResultSetYson(resultSet));
31233123
}
31243124
}
3125+
3126+
Y_UNIT_TEST(InsertEmptyString) {
3127+
NKikimrConfig::TAppConfig appConfig;
3128+
appConfig.MutableColumnShardConfig()->SetAllowNullableColumnsInPK(true);
3129+
auto settings = TKikimrSettings().SetAppConfig(appConfig).SetWithSampleTables(false);
3130+
TTestHelper testHelper(settings);
3131+
3132+
TVector<TTestHelper::TColumnSchema> schema = {
3133+
TTestHelper::TColumnSchema().SetName("id").SetType(NScheme::NTypeIds::Int64).SetNullable(false),
3134+
TTestHelper::TColumnSchema().SetName("value").SetType(NScheme::NTypeIds::String).SetNullable(false),
3135+
};
3136+
TTestHelper::TColumnTable testTable;
3137+
testTable.SetName("/Root/ttt").SetPrimaryKey({ "id", }).SetSharding({ "id" }).SetSchema(schema);
3138+
testHelper.CreateTable(testTable);
3139+
auto client = testHelper.GetKikimr().GetQueryClient();
3140+
const auto result = client
3141+
.ExecuteQuery(
3142+
R"(
3143+
INSERT INTO `/Root/ttt` (id, value) VALUES
3144+
(347, '')
3145+
)",
3146+
NYdb::NQuery::TTxControl::BeginTx().CommitTx())
3147+
.GetValueSync();
3148+
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
3149+
{
3150+
const auto resultSelect = client
3151+
.ExecuteQuery(
3152+
"SELECT * FROM `/Root/ttt`",
3153+
NYdb::NQuery::TTxControl::BeginTx().CommitTx())
3154+
.GetValueSync();
3155+
UNIT_ASSERT_C(resultSelect.IsSuccess(), resultSelect.GetIssues().ToString());
3156+
const auto resultSets = resultSelect.GetResultSets();
3157+
UNIT_ASSERT_VALUES_EQUAL(resultSets.size(), 1);
3158+
const auto resultSet = resultSets[0];
3159+
UNIT_ASSERT_VALUES_EQUAL(resultSet.RowsCount(), 1);
3160+
}
3161+
}
3162+
31253163
}
31263164

31273165
}

0 commit comments

Comments
 (0)