Skip to content

Commit

Permalink
Add PgNativeBinaryFromNativeText
Browse files Browse the repository at this point in the history
  • Loading branch information
azevaykin committed May 27, 2024
1 parent e2cc51b commit 19d3a37
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions ydb/core/scheme/ut_pg/scheme_tablecell_pg_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,56 @@ namespace NTable {

Y_UNIT_TEST_SUITE(PgTest) {

Y_UNIT_TEST(DumpCells) {
Y_UNIT_TEST(DumpIntCells) {
NScheme::TTypeRegistry typeRegistry;

i64 intVal = 55555;

{
TCell cell((const char *)&intVal, sizeof(i64));
NScheme::TTypeInfo typeInfo(NScheme::TInt64::TypeId);

TString printRes = DbgPrintCell(cell, typeInfo, typeRegistry);
UNIT_ASSERT_STRINGS_EQUAL(printRes, "Int64 : 55555");
}

{
NScheme::TTypeInfo pgTypeInfo(NScheme::NTypeIds::Pg, NPg::TypeDescFromPgTypeId(INT8OID));
auto desc = pgTypeInfo.GetTypeDesc();
auto res = NPg::PgNativeBinaryFromNativeText(Sprintf("%u", intVal), desc);
UNIT_ASSERT_C(!res.Error, *res.Error);
TString binary = res.Str;
TCell pgCell((const char*)binary.data(), binary.size());

TString printRes = DbgPrintCell(pgCell, pgTypeInfo, typeRegistry);
UNIT_ASSERT_STRINGS_EQUAL(printRes, "pgint8 : 55555");
}
}

Y_UNIT_TEST(DumpStringCells) {
NScheme::TTypeRegistry typeRegistry;

char strVal[] = "This is the value";
TCell strCell((const char*)&strVal, sizeof(strVal) - 1);

NScheme::TTypeInfo typeInfo(NScheme::TString::TypeId);
TString strRes = DbgPrintCell(strCell, typeInfo, typeRegistry);
UNIT_ASSERT_STRINGS_EQUAL(strRes, TStringBuilder() << "String : " << strVal);
{
TCell cell((const char*)&strVal, sizeof(strVal) - 1);
NScheme::TTypeInfo typeInfo(NScheme::TString::TypeId);

TString printRes = DbgPrintCell(cell, typeInfo, typeRegistry);
UNIT_ASSERT_STRINGS_EQUAL(printRes, TStringBuilder() << "String : " << strVal);
}

{
NScheme::TTypeInfo pgTypeInfo(NScheme::NTypeIds::Pg, NPg::TypeDescFromPgTypeId(TEXTOID));
auto desc = pgTypeInfo.GetTypeDesc();
auto res = NPg::PgNativeBinaryFromNativeText(strVal, desc);
UNIT_ASSERT_C(!res.Error, *res.Error);
TString binary = res.Str;
TCell pgCell((const char*)binary.data(), binary.size());

NScheme::TTypeInfo pgTypeInfo(NScheme::NTypeIds::Pg, NPg::TypeDescFromPgTypeId(TEXTOID));
TString pgStrRes = DbgPrintCell(strCell, pgTypeInfo, typeRegistry);
UNIT_ASSERT_STRINGS_EQUAL(pgStrRes, TStringBuilder() << "pgtext : " << strVal);
TString printRes = DbgPrintCell(pgCell, pgTypeInfo, typeRegistry);
UNIT_ASSERT_STRINGS_EQUAL(printRes, TStringBuilder() << "pgtext : " << strVal);
}
}
}

Expand Down

0 comments on commit 19d3a37

Please sign in to comment.