aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniil Cherednik <dcherednik@ydb.tech>2024-12-13 11:09:10 +0100
committerGitHub <noreply@github.com>2024-12-13 11:09:10 +0100
commit4b3df28e3fb33f5cb8f0dd3a60bfc8ec6d399dcb (patch)
tree732ba4bad524f88827f76ac9e8b715bf2e2099f4
parentbe585b61d649a49fd32e91d9ceeee7e893068a60 (diff)
downloadydb-4b3df28e3fb33f5cb8f0dd3a60bfc8ec6d399dcb.tar.gz
Fix incorrect Uuid serialization for CDC. (#12587)
TCell stores uuid as binary data therefore it can contains \0 byte.
-rw-r--r--ydb/core/tx/datashard/change_record_cdc_serializer.cpp11
-rw-r--r--ydb/core/tx/datashard/datashard_ut_change_collector.cpp6
-rw-r--r--ydb/public/lib/idx_test/idx_test_data_provider.cpp3
-rw-r--r--ydb/tests/functional/replication/main.cpp12
4 files changed, 22 insertions, 10 deletions
diff --git a/ydb/core/tx/datashard/change_record_cdc_serializer.cpp b/ydb/core/tx/datashard/change_record_cdc_serializer.cpp
index e3bc248489..162b3f922b 100644
--- a/ydb/core/tx/datashard/change_record_cdc_serializer.cpp
+++ b/ydb/core/tx/datashard/change_record_cdc_serializer.cpp
@@ -124,6 +124,15 @@ protected:
return result;
}
+ static NJson::TJsonValue UuidToJson(const TCell& cell) {
+ TStringStream ss;
+ ui16 dw[8];
+ Y_ABORT_UNLESS(cell.Size() == 16);
+ cell.CopyDataInto((char*)dw);
+ NUuid::UuidToString(dw, ss);
+ return NJson::TJsonValue(ss.Str());
+ }
+
static NJson::TJsonValue ToJson(const TCell& cell, NScheme::TTypeInfo type) {
if (cell.IsNull()) {
return NJson::TJsonValue(NJson::JSON_NULL);
@@ -185,7 +194,7 @@ protected:
case NScheme::NTypeIds::Pg:
return NJson::TJsonValue(PgToString(cell.AsBuf(), type));
case NScheme::NTypeIds::Uuid:
- return NJson::TJsonValue(NUuid::UuidBytesToString(cell.Data()));
+ return UuidToJson(cell);
default:
Y_ABORT("Unexpected type");
}
diff --git a/ydb/core/tx/datashard/datashard_ut_change_collector.cpp b/ydb/core/tx/datashard/datashard_ut_change_collector.cpp
index bd3e27d9c3..4b1c6cdcef 100644
--- a/ydb/core/tx/datashard/datashard_ut_change_collector.cpp
+++ b/ydb/core/tx/datashard/datashard_ut_change_collector.cpp
@@ -276,7 +276,7 @@ private:
inserter(name, cell.AsValue<ui32>());
} else if constexpr (std::is_same_v<T, TUuidHolder>) {
TStringStream ss;
- NUuid::UuidBytesToString(cell.Data(), ss);
+ NUuid::UuidBytesToString(TString(cell.Data(), cell.Size()), ss);
inserter(name, TUuidHolder(ss.Str()));
}
}
@@ -854,8 +854,8 @@ Y_UNIT_TEST_SUITE(CdcStreamChangeCollector) {
}
Y_UNIT_TEST(InsertSingleUuidRow) {
- Run<TUuidHolder>("/Root/path", UuidTable(), KeysOnly(), "INSERT INTO `/Root/path` (key, value) VALUES (Uuid(\"65df1ec1-a97d-47b2-ae56-3c023da6ee8c\"), 10);", {
- {"keys_stream", {TStructRecordBase<TUuidHolder>(NTable::ERowOp::Upsert, {{"key", TUuidHolder("65df1ec1-a97d-47b2-ae56-3c023da6ee8c")}})}},
+ Run<TUuidHolder>("/Root/path", UuidTable(), KeysOnly(), "INSERT INTO `/Root/path` (key, value) VALUES (Uuid(\"65df1ec1-0000-47b2-ae56-3c023da6ee8c\"), 10);", {
+ {"keys_stream", {TStructRecordBase<TUuidHolder>(NTable::ERowOp::Upsert, {{"key", TUuidHolder("65df1ec1-0000-47b2-ae56-3c023da6ee8c")}})}},
});
}
diff --git a/ydb/public/lib/idx_test/idx_test_data_provider.cpp b/ydb/public/lib/idx_test/idx_test_data_provider.cpp
index fafb5be1a3..bd0319d89c 100644
--- a/ydb/public/lib/idx_test/idx_test_data_provider.cpp
+++ b/ydb/public/lib/idx_test/idx_test_data_provider.cpp
@@ -63,6 +63,9 @@ NYdb::TValue CreateOptionalValue(const TColumn& column, const TRandomValueProvid
value.OptionalJson(TString(sb));
}
break;
+ case EPrimitiveType::Uuid:
+ value.OptionalUuid(TUuidValue(rvp.RandomUi64(), rvp.RandomUi64()));
+ break;
default:
Y_ABORT_UNLESS(false, "unimplemented");
}
diff --git a/ydb/tests/functional/replication/main.cpp b/ydb/tests/functional/replication/main.cpp
index da50717b7e..371ff6a9e1 100644
--- a/ydb/tests/functional/replication/main.cpp
+++ b/ydb/tests/functional/replication/main.cpp
@@ -60,9 +60,9 @@ Y_UNIT_TEST_SUITE(Replication)
{
const TString query = "UPSERT INTO ProducerUuidValue (Key,Key2,v01,v02,v03) VALUES"
"(1, "
- "CAST(\"5b99a330-04ef-4f1a-9b64-ba6d5f44ea00\" as Uuid), "
- "CAST(\"5b99a330-04ef-4f1a-9b64-ba6d5f44ea01\" as Uuid), "
- "UNWRAP(CAST(\"5b99a330-04ef-4f1a-9b64-ba6d5f44ea02\" as Uuid)), "
+ "CAST(\"00078af5-0000-0000-6c0b-040000000000\" as Uuid), "
+ "CAST(\"00078af5-0000-0000-6c0b-040000000001\" as Uuid), "
+ "UNWRAP(CAST(\"00078af5-0000-0000-6c0b-040000000002\" as Uuid)), "
"CAST(\"311111111113.222222223\" as Double) "
");";
auto res = s.ExecuteDataQuery(query, TTxControl::BeginTx().CommitTx()).GetValueSync();
@@ -90,9 +90,9 @@ Y_UNIT_TEST_SUITE(Replication)
UNIT_ASSERT_C(sessionResult.IsSuccess(), sessionResult.GetIssues().ToString());
auto s = sessionResult.GetSession();
- TUuidValue expectedKey2("5b99a330-04ef-4f1a-9b64-ba6d5f44ea00");
- TUuidValue expectedV1("5b99a330-04ef-4f1a-9b64-ba6d5f44ea01");
- TUuidValue expectedV2("5b99a330-04ef-4f1a-9b64-ba6d5f44ea02");
+ TUuidValue expectedKey2("00078af5-0000-0000-6c0b-040000000000");
+ TUuidValue expectedV1("00078af5-0000-0000-6c0b-040000000001");
+ TUuidValue expectedV2("00078af5-0000-0000-6c0b-040000000002");
double expectedV3 = 311111111113.222222223;
ui32 attempt = 10;
while (--attempt) {