Skip to content

Commit d0dc4a9

Browse files
authored
Support PG types in CellMaker (#9856)
1 parent 7b66648 commit d0dc4a9

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

ydb/core/io_formats/cell_maker/cell_maker.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ bool MakeCell(TCell& cell, const NJson::TJsonValue& value, const NScheme::TTypeI
393393
return TCellMaker<TMaybe<TString>, TStringBuf>::Make(cell, value.GetStringSafe(), pool, err, &DyNumberToStringBuf);
394394
case NScheme::NTypeIds::Decimal:
395395
return TCellMaker<NYql::NDecimal::TInt128, std::pair<ui64, ui64>>::Make(cell, value.GetStringSafe(), pool, err, &Int128ToPair);
396+
case NScheme::NTypeIds::Pg:
397+
if (auto result = NPg::PgNativeBinaryFromNativeText(value.GetStringSafe(), typeInfo.GetPgTypeDesc()); result.Error) {
398+
err = *result.Error;
399+
return false;
400+
} else {
401+
return TCellMaker<NPg::TConvertResult, TStringBuf>::MakeDirect(cell, result, pool, err, &PgToStringBuf);
402+
}
396403
case NScheme::NTypeIds::Uuid:
397404
return TCellMaker<TUuidHolder, TStringBuf>::Make(cell, value.GetStringSafe(), pool, err, &UuidToStringBuf);
398405
default:

ydb/core/tx/replication/service/table_writer_ut.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ Y_UNIT_TEST_SUITE(LocalTableWriter) {
3939
}
4040

4141
Y_UNIT_TEST(SupportedTypes) {
42-
TEnv env(TFeatureFlags().SetEnableTableDatetime64(true));
42+
TEnv env(TFeatureFlags()
43+
.SetEnableTableDatetime64(true)
44+
.SetEnableTablePgTypes(true)
45+
.SetEnablePgSyntax(true));
4346
env.GetRuntime().SetLogPriority(NKikimrServices::REPLICATION_SERVICE, NLog::PRI_DEBUG);
4447

4548
env.CreateTable("/Root", *MakeTableDescription(TTestTableDescription{
@@ -70,6 +73,13 @@ Y_UNIT_TEST_SUITE(LocalTableWriter) {
7073
{.Name = "datetime64_value", .Type = "Datetime64"},
7174
{.Name = "timestamp64_value", .Type = "Timestamp64"},
7275
{.Name = "interval64_value", .Type = "Interval64"},
76+
{.Name = "pgint2_value", .Type = "pgint2"},
77+
{.Name = "pgint4_value", .Type = "pgint4"},
78+
{.Name = "pgint8_value", .Type = "pgint8"},
79+
{.Name = "pgfloat4_value", .Type = "pgfloat4"},
80+
{.Name = "pgfloat8_value", .Type = "pgfloat8"},
81+
{.Name = "pgbytea_value", .Type = "pgbytea"},
82+
{.Name = "pgtext_value", .Type = "pgtext"},
7383
},
7484
}));
7585

@@ -101,6 +111,13 @@ Y_UNIT_TEST_SUITE(LocalTableWriter) {
101111
TRecord(21, R"({"key":[21], "update":{"datetime64_value":1597235696}})"),
102112
TRecord(22, R"({"key":[22], "update":{"timestamp64_value":1597235696123456}})"),
103113
TRecord(23, R"({"key":[23], "update":{"interval64_value":-300500}})"),
114+
TRecord(24, R"({"key":[24], "update":{"pgint2_value":"-42"}})"),
115+
TRecord(25, R"({"key":[25], "update":{"pgint4_value":"-420"}})"),
116+
TRecord(26, R"({"key":[26], "update":{"pgint8_value":"-4200"}})"),
117+
TRecord(27, R"({"key":[27], "update":{"pgfloat4_value":"3.1415"}})"),
118+
TRecord(28, R"({"key":[28], "update":{"pgfloat8_value":"2.718"}})"),
119+
TRecord(29, R"({"key":[29], "update":{"pgbytea_value":"\\x6c6f72656d2022697073756d22"}})"),
120+
TRecord(30, R"({"key":[30], "update":{"pgtext_value":"lorem \"ipsum\""}})"),
104121
}));
105122
}
106123
}

ydb/core/tx/replication/ut_helpers/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ LIBRARY()
33
PEERDIR(
44
ydb/core/base
55
ydb/core/protos
6-
ydb/core/testlib/default
6+
ydb/core/testlib/pg
77
ydb/core/tx/replication/ydb_proxy
88
ydb/public/sdk/cpp/client/ydb_topic
99
library/cpp/testing/unittest

0 commit comments

Comments
 (0)