Skip to content

Commit 030f818

Browse files
authored
DbgPrintValue for Pg types (reapply #4847 reverted in #4894) (#10458)
1 parent a4966da commit 030f818

File tree

4 files changed

+109
-2
lines changed

4 files changed

+109
-2
lines changed

ydb/core/scheme/scheme_tablecell.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,14 @@ void DbgPrintValue(TString &res, const TCell &r, NScheme::TTypeInfo typeInfo) {
468468
case NScheme::NTypeIds::Decimal:
469469
res += typeInfo.GetDecimalType().CellValueToString(r.AsValue<std::pair<ui64, i64>>());
470470
break;
471-
case NScheme::NTypeIds::Pg:
472-
// TODO: support pg types
471+
case NScheme::NTypeIds::Pg: {
472+
auto convert = NPg::PgNativeTextFromNativeBinary(r.AsBuf(), typeInfo.GetPgTypeDesc());
473+
if (!convert.Error)
474+
res += convert.Str;
475+
else
476+
res += *convert.Error;
473477
break;
478+
}
474479
default:
475480
res += EscapeC(r.Data(), r.Size());
476481
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <library/cpp/testing/unittest/registar.h>
2+
3+
#include <ydb/core/scheme/scheme_tablecell.h>
4+
#include <ydb/core/scheme/scheme_type_registry.h>
5+
6+
extern "C" {
7+
#include "postgres.h"
8+
#include "catalog/pg_type_d.h"
9+
}
10+
11+
namespace NKikimr {
12+
namespace NTable {
13+
14+
Y_UNIT_TEST_SUITE(PgTest) {
15+
16+
Y_UNIT_TEST(DumpIntCells) {
17+
NScheme::TTypeRegistry typeRegistry;
18+
19+
i64 intVal = 55555;
20+
21+
{
22+
TCell cell((const char *)&intVal, sizeof(i64));
23+
NScheme::TTypeInfo typeInfo(NScheme::TInt64::TypeId);
24+
25+
TString printRes = DbgPrintCell(cell, typeInfo, typeRegistry);
26+
UNIT_ASSERT_STRINGS_EQUAL(printRes, "Int64 : 55555");
27+
}
28+
29+
{
30+
NScheme::TTypeInfo pgTypeInfo(NPg::TypeDescFromPgTypeId(INT8OID));
31+
auto desc = pgTypeInfo.GetPgTypeDesc();
32+
auto res = NPg::PgNativeBinaryFromNativeText(Sprintf("%u", intVal), desc);
33+
UNIT_ASSERT_C(!res.Error, *res.Error);
34+
TString binary = res.Str;
35+
TCell pgCell((const char*)binary.data(), binary.size());
36+
37+
TString printRes = DbgPrintCell(pgCell, pgTypeInfo, typeRegistry);
38+
UNIT_ASSERT_STRINGS_EQUAL(printRes, "pgint8 : 55555");
39+
}
40+
}
41+
42+
Y_UNIT_TEST(DumpStringCells) {
43+
NScheme::TTypeRegistry typeRegistry;
44+
45+
char strVal[] = "This is the value";
46+
47+
{
48+
TCell cell((const char*)&strVal, sizeof(strVal) - 1);
49+
NScheme::TTypeInfo typeInfo(NScheme::TString::TypeId);
50+
51+
TString printRes = DbgPrintCell(cell, typeInfo, typeRegistry);
52+
UNIT_ASSERT_STRINGS_EQUAL(printRes, TStringBuilder() << "String : " << strVal);
53+
}
54+
55+
{
56+
NScheme::TTypeInfo pgTypeInfo(NPg::TypeDescFromPgTypeId(TEXTOID));
57+
auto desc = pgTypeInfo.GetPgTypeDesc();
58+
auto res = NPg::PgNativeBinaryFromNativeText(strVal, desc);
59+
UNIT_ASSERT_C(!res.Error, *res.Error);
60+
TString binary = res.Str;
61+
TCell pgCell((const char*)binary.data(), binary.size());
62+
63+
TString printRes = DbgPrintCell(pgCell, pgTypeInfo, typeRegistry);
64+
UNIT_ASSERT_STRINGS_EQUAL(printRes, TStringBuilder() << "pgtext : " << strVal);
65+
}
66+
}
67+
}
68+
69+
}
70+
}

ydb/core/scheme/ut_pg/ya.make

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
UNITTEST_FOR(ydb/core/scheme)
2+
3+
FORK_SUBTESTS()
4+
5+
SRCS(
6+
scheme_tablecell_pg_ut.cpp
7+
)
8+
9+
PEERDIR(
10+
ydb/core/scheme
11+
ydb/library/yql/public/udf/service/exception_policy
12+
ydb/library/yql/parser/pg_wrapper
13+
)
14+
15+
ADDINCL(
16+
ydb/library/yql/parser/pg_wrapper/postgresql/src/include
17+
)
18+
19+
IF (OS_WINDOWS)
20+
CFLAGS(
21+
"-D__thread=__declspec(thread)"
22+
-Dfstat=microsoft_native_fstat
23+
-Dstat=microsoft_native_stat
24+
)
25+
ENDIF()
26+
27+
NO_COMPILER_WARNINGS()
28+
29+
YQL_LAST_ABI_VERSION()
30+
31+
END()

ydb/core/scheme/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ END()
3030

3131
RECURSE_FOR_TESTS(
3232
ut
33+
ut_pg
3334
)

0 commit comments

Comments
 (0)