Skip to content

KIKIMR-20635: pg types in TQueryPlan #853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions ydb/core/kqp/opt/kqp_query_plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,17 +515,23 @@ class TxPlanSerializer {
}

TString DescribeValue(const NKikimr::NClient::TValue& value) {
auto str = value.GetDataText();
switch (value.GetType().GetData().GetScheme()) {
case NScheme::NTypeIds::Utf8:
case NScheme::NTypeIds::Json:
case NScheme::NTypeIds::String:
case NScheme::NTypeIds::String4k:
case NScheme::NTypeIds::String2m:
return "«" + str + "»";
default:
return str;
if (value.GetType().GetKind() == NKikimrMiniKQL::ETypeKind::Data) {
auto str = value.GetDataText();
switch (value.GetType().GetData().GetScheme()) {
case NScheme::NTypeIds::Utf8:
case NScheme::NTypeIds::Json:
case NScheme::NTypeIds::String:
case NScheme::NTypeIds::String4k:
case NScheme::NTypeIds::String2m:
return "«" + str + "»";
default:
return str;
}
}
if (value.GetType().GetKind() == NKikimrMiniKQL::ETypeKind::Pg) {
return value.GetPgText();
}
Y_ENSURE(false, TStringBuilder() << "unexpected NKikimrMiniKQL::ETypeKind: " << ETypeKind_Name(value.GetType().GetKind()));
}

void Visit(const TKqpReadRangesSourceSettings& sourceSettings, TQueryPlanNode& planNode) {
Expand Down
22 changes: 22 additions & 0 deletions ydb/core/kqp/opt/query_plan_value/kqp_query_plan_value.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <ydb/library/yql/parser/pg_wrapper/interface/type_desc.h>
#include <ydb/public/lib/value/value.h>

namespace NKikimr {
namespace NClient {

TString TValue::GetPgText() const {
Y_ASSERT(Type.GetKind() == NKikimrMiniKQL::ETypeKind::Pg);
if (Value.HasNullFlagValue()) {
return TString("null");
}
if (Value.HasText()) {
return Value.GetText();
}
auto pgType = Type.GetPg();
auto convertResult = NPg::PgNativeTextFromNativeBinary(Value.GetBytes(), NPg::TypeDescFromPgTypeId(pgType.Getoid()));
Y_ENSURE(!convertResult.Error, convertResult.Error);
return convertResult.Str;
}

}
}
12 changes: 12 additions & 0 deletions ydb/core/kqp/opt/query_plan_value/ya.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
LIBRARY()

SRCS(
kqp_query_plan_value.cpp
)

PEERDIR(
ydb/library/yql/parser/pg_wrapper/interface
ydb/public/lib/value
)

END()
1 change: 1 addition & 0 deletions ydb/core/kqp/opt/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PEERDIR(
ydb/core/kqp/opt/logical
ydb/core/kqp/opt/peephole
ydb/core/kqp/opt/physical
ydb/core/kqp/opt/query_plan_value
ydb/library/yql/dq/common
ydb/library/yql/dq/opt
ydb/library/yql/dq/type_ann
Expand Down
2 changes: 0 additions & 2 deletions ydb/core/kqp/ut/opt/kqp_not_null_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,6 @@ Y_UNIT_TEST_SUITE(KqpNotNullColumns) {
}
}

#if 0
// TODO: fix TxPlanSerializer with PG keys
Y_UNIT_TEST(SecondaryIndexWithNotNullDataColumnPg) {
auto settings = TKikimrSettings()
Expand Down Expand Up @@ -1759,7 +1758,6 @@ Y_UNIT_TEST_SUITE(KqpNotNullColumns) {
result.GetIssues().ToString());
}
}
#endif

Y_UNIT_TEST_TWIN(JoinBothTablesWithNotNullPk, StreamLookup) {
NKikimrConfig::TAppConfig appConfig;
Expand Down
3 changes: 3 additions & 0 deletions ydb/public/lib/value/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class TValue {
NScheme::TTypeId GetDataType() const;
// gets text representation of simple 'Data' types
TString GetDataText() const;
// gets text representation of simple 'Pg' types
// You need to add ydb/core/kqp/opt/query_plan_value to PEERDIRs in order to use this function
TString GetPgText() const;
// returns text representation of value's type
template <typename Format> TString GetTypeText(const Format& format = Format()) const;
// returns text representation of value itself
Expand Down