aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvvvv <vvvv@yandex-team.ru>2022-03-10 16:47:52 +0300
committervvvv <vvvv@yandex-team.ru>2022-03-10 16:47:52 +0300
commit768a64922dc5107b247dca506f2009af346828cf (patch)
treee07cb284efeadddf3223ac4646fbda62527f9826
parent907359550105266054869b15bf9dc66291af2d75 (diff)
downloadydb-768a64922dc5107b247dca506f2009af346828cf.tar.gz
YQL-13710 FormatType/ParseType
ref:b58d748845a56cfa823c25108c0e0eb1f476b617
-rw-r--r--ydb/library/yql/ast/yql_type_string.cpp41
-rw-r--r--ydb/library/yql/ast/yql_type_string_ut.cpp4
-rw-r--r--ydb/library/yql/parser/pg_catalog/catalog.cpp10
-rw-r--r--ydb/library/yql/parser/pg_catalog/catalog.h1
4 files changed, 53 insertions, 3 deletions
diff --git a/ydb/library/yql/ast/yql_type_string.cpp b/ydb/library/yql/ast/yql_type_string.cpp
index a674697191c..898e19c80b5 100644
--- a/ydb/library/yql/ast/yql_type_string.cpp
+++ b/ydb/library/yql/ast/yql_type_string.cpp
@@ -2,6 +2,7 @@
#include "yql_expr.h"
#include "yql_ast_escaping.h"
+#include <ydb/library/yql/parser/pg_catalog/catalog.h>
#include <library/cpp/containers/stack_vector/stack_vec.h>
#include <util/string/cast.h>
@@ -181,6 +182,7 @@ public:
private:
TAstNode* ParseType() {
+ bool isPgType = false;
TAstNode* type = nullptr;
switch (Token) {
@@ -305,11 +307,33 @@ private:
if (Identifier.empty()) {
return AddError("Expected type");
}
- return AddError(TString("Unknown type: '") + Identifier + "\'");
+
+ auto id = Identifier;
+ if (id.SkipPrefix("pg")) {
+ if (NPg::HasType(id)) {
+ type = MakePgType(id);
+ isPgType = true;
+ GetNextToken();
+ }
+ } else if (id.SkipPrefix("_pg")) {
+ if (NPg::HasType(id) && !id.StartsWith('_')) {
+ type = MakePgType(TString("_") + id);
+ isPgType = true;
+ GetNextToken();
+ }
+ }
+
+ if (!type) {
+ return AddError(TString("Unknown type: '") + Identifier + "\'");
+ }
}
if (type) {
while (Token == '?') {
+ if (isPgType) {
+ return AddError(TString("PG type can't be wrapped into Optional type"));
+ }
+
type = MakeOptionalType(type);
GetNextToken();
}
@@ -1012,6 +1036,14 @@ private:
return MakeList(items, Y_ARRAY_SIZE(items));
}
+ TAstNode* MakePgType(TStringBuf type) {
+ TAstNode* items[] = {
+ MakeLiteralAtom(TStringBuf("PgType")),
+ MakeQuotedAtom(type),
+ };
+ return MakeList(items, Y_ARRAY_SIZE(items));
+ }
+
TAstNode* MakeDecimalType(TStringBuf precision, TStringBuf scale) {
TAstNode* items[] = {
MakeLiteralAtom(TStringBuf("DataType")),
@@ -1179,7 +1211,12 @@ private:
}
void Visit(const TPgExprType& type) final {
- Out_ << "pg" << type.GetName();
+ TStringBuf name = type.GetName();
+ if (!name.SkipPrefix("_")) {
+ Out_ << "pg" << name;
+ } else {
+ Out_ << "_pg" << name;
+ }
}
void Visit(const TWorldExprType& type) final {
diff --git a/ydb/library/yql/ast/yql_type_string_ut.cpp b/ydb/library/yql/ast/yql_type_string_ut.cpp
index 2f22c42258a..1ef629067f8 100644
--- a/ydb/library/yql/ast/yql_type_string_ut.cpp
+++ b/ydb/library/yql/ast/yql_type_string_ut.cpp
@@ -666,4 +666,8 @@ Y_UNIT_TEST_SUITE(TTypeString)
TestFormat("((Tagged (Data String) \"a\\t\\n\\x01b\"))", "Tagged<String,'a\\t\\n\\x01b'>");
}
+ Y_UNIT_TEST(FormatPg) {
+ TestFormat("((Pg int4))", "pgint4");
+ TestFormat("((Pg _int4))", "_pgint4");
+ }
}
diff --git a/ydb/library/yql/parser/pg_catalog/catalog.cpp b/ydb/library/yql/parser/pg_catalog/catalog.cpp
index cb25ab0fc5d..a11f2ab2d31 100644
--- a/ydb/library/yql/parser/pg_catalog/catalog.cpp
+++ b/ydb/library/yql/parser/pg_catalog/catalog.cpp
@@ -287,7 +287,10 @@ public:
Types[LastType.TypeId] = LastType;
if (LastType.ArrayTypeId) {
- Types[LastType.ArrayTypeId] = LastType;
+ auto arrayType = LastType;
+ arrayType.Name = "_" + arrayType.Name;
+ arrayType.TypeId = LastType.ArrayTypeId;
+ Types[LastType.ArrayTypeId] = arrayType;
}
LazyInfos[LastType.TypeId] = LastLazyTypeInfo;
@@ -603,6 +606,11 @@ const TProcDesc& LookupProc(ui32 procId) {
return *procPtr;
}
+bool HasType(const TStringBuf& name) {
+ const auto& catalog = TCatalog::Instance();
+ return catalog.TypeByName.contains(name);
+}
+
const TTypeDesc& LookupType(const TString& name) {
const auto& catalog = TCatalog::Instance();
auto typeIdPtr = catalog.TypeByName.FindPtr(name);
diff --git a/ydb/library/yql/parser/pg_catalog/catalog.h b/ydb/library/yql/parser/pg_catalog/catalog.h
index e67c916ecdb..a2c86a439e0 100644
--- a/ydb/library/yql/parser/pg_catalog/catalog.h
+++ b/ydb/library/yql/parser/pg_catalog/catalog.h
@@ -62,6 +62,7 @@ const TProcDesc& LookupProc(const TString& name, const TVector<ui32>& argTypeIds
const TProcDesc& LookupProc(ui32 procId, const TVector<ui32>& argTypeIds);
const TProcDesc& LookupProc(ui32 procId);
+bool HasType(const TStringBuf& name);
const TTypeDesc& LookupType(const TString& name);
const TTypeDesc& LookupType(ui32 typeId);