Skip to content

Commit

Permalink
Embed short blobs in TCell, fix empty string (#13194)
Browse files Browse the repository at this point in the history
  • Loading branch information
zverevgeny authored Jan 9, 2025
1 parent bc52487 commit d68c1c1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ydb/core/kqp/runtime/kqp_write_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,14 @@ class TRowBuilder {
? NYql::NUdf::TStringRef(cellInfo.PgBinaryValue)
: cellInfo.Value.AsStringRef();

char* initialPtr = dataPtr;
std::memcpy(initialPtr, ref.Data(), ref.Size());
dataPtr += ref.Size();
return TCell(initialPtr, ref.Size());
if (TCell::CanInline(ref.Size())) {
return TCell(ref.Data(), ref.Size());
} else {
char* initialPtr = dataPtr;
std::memcpy(initialPtr, ref.Data(), ref.Size());
dataPtr += ref.Size();
return TCell(initialPtr, ref.Size());
}
}

size_t GetCellSize(const TCellInfo& cellInfo) const {
Expand All @@ -301,7 +305,8 @@ class TRowBuilder {
if (cellInfo.Type.GetTypeId() == NScheme::NTypeIds::Pg) {
return cellInfo.PgBinaryValue.size();
}
return cellInfo.Value.AsStringRef().Size();
const auto s = cellInfo.Value.AsStringRef().Size();
return TCell::CanInline(s) ? 0 : s;
}

TCharVectorPtr Allocate(size_t size) {
Expand Down
38 changes: 38 additions & 0 deletions ydb/core/kqp/ut/olap/kqp_olap_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3122,6 +3122,44 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
)", FormatResultSetYson(resultSet));
}
}

Y_UNIT_TEST(InsertEmptyString) {
NKikimrConfig::TAppConfig appConfig;
appConfig.MutableColumnShardConfig()->SetAllowNullableColumnsInPK(true);
auto settings = TKikimrSettings().SetAppConfig(appConfig).SetWithSampleTables(false);
TTestHelper testHelper(settings);

TVector<TTestHelper::TColumnSchema> schema = {
TTestHelper::TColumnSchema().SetName("id").SetType(NScheme::NTypeIds::Int64).SetNullable(false),
TTestHelper::TColumnSchema().SetName("value").SetType(NScheme::NTypeIds::String).SetNullable(false),
};
TTestHelper::TColumnTable testTable;
testTable.SetName("/Root/ttt").SetPrimaryKey({ "id", }).SetSharding({ "id" }).SetSchema(schema);
testHelper.CreateTable(testTable);
auto client = testHelper.GetKikimr().GetQueryClient();
const auto result = client
.ExecuteQuery(
R"(
INSERT INTO `/Root/ttt` (id, value) VALUES
(347, '')
)",
NYdb::NQuery::TTxControl::BeginTx().CommitTx())
.GetValueSync();
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
{
const auto resultSelect = client
.ExecuteQuery(
"SELECT * FROM `/Root/ttt`",
NYdb::NQuery::TTxControl::BeginTx().CommitTx())
.GetValueSync();
UNIT_ASSERT_C(resultSelect.IsSuccess(), resultSelect.GetIssues().ToString());
const auto resultSets = resultSelect.GetResultSets();
UNIT_ASSERT_VALUES_EQUAL(resultSets.size(), 1);
const auto resultSet = resultSets[0];
UNIT_ASSERT_VALUES_EQUAL(resultSet.RowsCount(), 1);
}
}

}

}

0 comments on commit d68c1c1

Please sign in to comment.