Skip to content

Commit 8dad5b9

Browse files
committed
KIKIMR-20635: pg types in TQueryPlan
1 parent fdcdd6f commit 8dad5b9

File tree

6 files changed

+55
-13
lines changed

6 files changed

+55
-13
lines changed

ydb/core/kqp/opt/kqp_query_plan.cpp

+16-10
Original file line numberDiff line numberDiff line change
@@ -515,17 +515,23 @@ class TxPlanSerializer {
515515
}
516516

517517
TString DescribeValue(const NKikimr::NClient::TValue& value) {
518-
auto str = value.GetDataText();
519-
switch (value.GetType().GetData().GetScheme()) {
520-
case NScheme::NTypeIds::Utf8:
521-
case NScheme::NTypeIds::Json:
522-
case NScheme::NTypeIds::String:
523-
case NScheme::NTypeIds::String4k:
524-
case NScheme::NTypeIds::String2m:
525-
return "«" + str + "»";
526-
default:
527-
return str;
518+
if (value.GetType().GetKind() == NKikimrMiniKQL::ETypeKind::Data) {
519+
auto str = value.GetDataText();
520+
switch (value.GetType().GetData().GetScheme()) {
521+
case NScheme::NTypeIds::Utf8:
522+
case NScheme::NTypeIds::Json:
523+
case NScheme::NTypeIds::String:
524+
case NScheme::NTypeIds::String4k:
525+
case NScheme::NTypeIds::String2m:
526+
return "«" + str + "»";
527+
default:
528+
return str;
529+
}
530+
}
531+
if (value.GetType().GetKind() == NKikimrMiniKQL::ETypeKind::Pg) {
532+
return value.GetPgText();
528533
}
534+
Y_ENSURE(false, TStringBuilder() << "unexpected NKikimrMiniKQL::ETypeKind: " << ETypeKind_Name(value.GetType().GetKind()));
529535
}
530536

531537
void Visit(const TKqpReadRangesSourceSettings& sourceSettings, TQueryPlanNode& planNode) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <ydb/library/yql/parser/pg_wrapper/interface/type_desc.h>
2+
#include <ydb/public/lib/value/value.h>
3+
4+
namespace NKikimr {
5+
namespace NClient {
6+
7+
TString TValue::GetPgText() const {
8+
Y_ASSERT(Type.GetKind() == NKikimrMiniKQL::ETypeKind::Pg);
9+
if (Value.HasNullFlagValue()) {
10+
return TString("null");
11+
}
12+
if (Value.HasText()) {
13+
return Value.GetText();
14+
}
15+
auto pgType = Type.GetPg();
16+
auto convertResult = NPg::PgNativeTextFromNativeBinary(Value.GetBytes(), NPg::TypeDescFromPgTypeId(pgType.Getoid()));
17+
Y_ENSURE(!convertResult.Error, convertResult.Error);
18+
return convertResult.Str;
19+
}
20+
21+
}
22+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
LIBRARY()
2+
3+
SRCS(
4+
kqp_query_plan_value.cpp
5+
)
6+
7+
PEERDIR(
8+
ydb/library/yql/parser/pg_wrapper/interface
9+
ydb/public/lib/value
10+
)
11+
12+
END()

ydb/core/kqp/opt/ya.make

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ PEERDIR(
2121
ydb/core/kqp/opt/logical
2222
ydb/core/kqp/opt/peephole
2323
ydb/core/kqp/opt/physical
24+
ydb/core/kqp/opt/query_plan_value
2425
ydb/library/yql/dq/common
2526
ydb/library/yql/dq/opt
2627
ydb/library/yql/dq/type_ann

ydb/core/kqp/ut/opt/kqp_not_null_ut.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,6 @@ Y_UNIT_TEST_SUITE(KqpNotNullColumns) {
16531653
}
16541654
}
16551655

1656-
#if 0
16571656
// TODO: fix TxPlanSerializer with PG keys
16581657
Y_UNIT_TEST(SecondaryIndexWithNotNullDataColumnPg) {
16591658
auto settings = TKikimrSettings()
@@ -1759,7 +1758,6 @@ Y_UNIT_TEST_SUITE(KqpNotNullColumns) {
17591758
result.GetIssues().ToString());
17601759
}
17611760
}
1762-
#endif
17631761

17641762
Y_UNIT_TEST_TWIN(JoinBothTablesWithNotNullPk, StreamLookup) {
17651763
NKikimrConfig::TAppConfig appConfig;

ydb/public/lib/value/value.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class TValue {
6161
// for examples see cpp_ut.cpp
6262
static TValue Create(const NKikimrMiniKQL::TValue& value, const NKikimrMiniKQL::TType& type);
6363
static TValue Create(const NKikimrMiniKQL::TResult& result);
64-
64+
6565
// check for value existence (in optional)
6666
bool HaveValue() const;
6767
bool IsNull() const;
@@ -89,6 +89,9 @@ class TValue {
8989
NScheme::TTypeId GetDataType() const;
9090
// gets text representation of simple 'Data' types
9191
TString GetDataText() const;
92+
// gets text representation of simple 'Pg' types
93+
// You need to add ydb/core/kqp/opt/query_plan_value to PEERDIRs in order to use this function
94+
TString GetPgText() const;
9295
// returns text representation of value's type
9396
template <typename Format> TString GetTypeText(const Format& format = Format()) const;
9497
// returns text representation of value itself

0 commit comments

Comments
 (0)