aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Nikolaev <ivannik@ydb.tech>2024-10-16 13:26:53 +0300
committerGitHub <noreply@github.com>2024-10-16 13:26:53 +0300
commit030f81861133ea64d781c4f811986919d703253e (patch)
tree60a696ebe4fdf0e695cdceb93739035ec05c3255
parenta4966da74df936e6b2f4c8583a1e6a814a0871df (diff)
downloadydb-030f81861133ea64d781c4f811986919d703253e.tar.gz
DbgPrintValue for Pg types (reapply #4847 reverted in #4894) (#10458)
-rw-r--r--ydb/core/scheme/scheme_tablecell.cpp9
-rw-r--r--ydb/core/scheme/ut_pg/scheme_tablecell_pg_ut.cpp70
-rw-r--r--ydb/core/scheme/ut_pg/ya.make31
-rw-r--r--ydb/core/scheme/ya.make1
4 files changed, 109 insertions, 2 deletions
diff --git a/ydb/core/scheme/scheme_tablecell.cpp b/ydb/core/scheme/scheme_tablecell.cpp
index f045e5d3ab..53448bd16c 100644
--- a/ydb/core/scheme/scheme_tablecell.cpp
+++ b/ydb/core/scheme/scheme_tablecell.cpp
@@ -468,9 +468,14 @@ void DbgPrintValue(TString &res, const TCell &r, NScheme::TTypeInfo typeInfo) {
case NScheme::NTypeIds::Decimal:
res += typeInfo.GetDecimalType().CellValueToString(r.AsValue<std::pair<ui64, i64>>());
break;
- case NScheme::NTypeIds::Pg:
- // TODO: support pg types
+ case NScheme::NTypeIds::Pg: {
+ auto convert = NPg::PgNativeTextFromNativeBinary(r.AsBuf(), typeInfo.GetPgTypeDesc());
+ if (!convert.Error)
+ res += convert.Str;
+ else
+ res += *convert.Error;
break;
+ }
default:
res += EscapeC(r.Data(), r.Size());
}
diff --git a/ydb/core/scheme/ut_pg/scheme_tablecell_pg_ut.cpp b/ydb/core/scheme/ut_pg/scheme_tablecell_pg_ut.cpp
new file mode 100644
index 0000000000..80439f8af2
--- /dev/null
+++ b/ydb/core/scheme/ut_pg/scheme_tablecell_pg_ut.cpp
@@ -0,0 +1,70 @@
+#include <library/cpp/testing/unittest/registar.h>
+
+#include <ydb/core/scheme/scheme_tablecell.h>
+#include <ydb/core/scheme/scheme_type_registry.h>
+
+extern "C" {
+#include "postgres.h"
+#include "catalog/pg_type_d.h"
+}
+
+namespace NKikimr {
+namespace NTable {
+
+Y_UNIT_TEST_SUITE(PgTest) {
+
+ 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(NPg::TypeDescFromPgTypeId(INT8OID));
+ auto desc = pgTypeInfo.GetPgTypeDesc();
+ 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 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(NPg::TypeDescFromPgTypeId(TEXTOID));
+ auto desc = pgTypeInfo.GetPgTypeDesc();
+ 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());
+
+ TString printRes = DbgPrintCell(pgCell, pgTypeInfo, typeRegistry);
+ UNIT_ASSERT_STRINGS_EQUAL(printRes, TStringBuilder() << "pgtext : " << strVal);
+ }
+ }
+}
+
+}
+}
diff --git a/ydb/core/scheme/ut_pg/ya.make b/ydb/core/scheme/ut_pg/ya.make
new file mode 100644
index 0000000000..8f7dcbae1c
--- /dev/null
+++ b/ydb/core/scheme/ut_pg/ya.make
@@ -0,0 +1,31 @@
+UNITTEST_FOR(ydb/core/scheme)
+
+FORK_SUBTESTS()
+
+SRCS(
+ scheme_tablecell_pg_ut.cpp
+)
+
+PEERDIR(
+ ydb/core/scheme
+ ydb/library/yql/public/udf/service/exception_policy
+ ydb/library/yql/parser/pg_wrapper
+)
+
+ADDINCL(
+ ydb/library/yql/parser/pg_wrapper/postgresql/src/include
+)
+
+IF (OS_WINDOWS)
+CFLAGS(
+ "-D__thread=__declspec(thread)"
+ -Dfstat=microsoft_native_fstat
+ -Dstat=microsoft_native_stat
+)
+ENDIF()
+
+NO_COMPILER_WARNINGS()
+
+YQL_LAST_ABI_VERSION()
+
+END()
diff --git a/ydb/core/scheme/ya.make b/ydb/core/scheme/ya.make
index 2b2edaa3b9..fb7e804beb 100644
--- a/ydb/core/scheme/ya.make
+++ b/ydb/core/scheme/ya.make
@@ -30,4 +30,5 @@ END()
RECURSE_FOR_TESTS(
ut
+ ut_pg
)