diff options
author | fedor-miron <fedor-miron@yandex-team.com> | 2023-05-30 12:53:25 +0300 |
---|---|---|
committer | fedor-miron <fedor-miron@yandex-team.com> | 2023-05-30 12:53:25 +0300 |
commit | 1ec4b6e4f22d1d72a94d51e2b68760f70bed233f (patch) | |
tree | 6617d34b1cf1d87ce1b02f6bf0e465d9ea6b4045 | |
parent | ee7ff2e71e98d56e4c9aba1279a9490f635418d3 (diff) | |
download | ydb-1ec4b6e4f22d1d72a94d51e2b68760f70bed233f.tar.gz |
YQL-16019: alias serial column types to int
-rw-r--r-- | ydb/library/yql/sql/pg/pg_sql.cpp | 22 | ||||
-rw-r--r-- | ydb/library/yql/sql/pg/pg_sql_ut.cpp | 15 |
2 files changed, 35 insertions, 2 deletions
diff --git a/ydb/library/yql/sql/pg/pg_sql.cpp b/ydb/library/yql/sql/pg/pg_sql.cpp index fd07fc51139..37cc446f313 100644 --- a/ydb/library/yql/sql/pg/pg_sql.cpp +++ b/ydb/library/yql/sql/pg/pg_sql.cpp @@ -1,3 +1,4 @@ +#include "util/charset/utf8.h" #include "utils.h" #include <ydb/library/yql/sql/settings/partitioning.h> #include <ydb/library/yql/parser/pg_wrapper/interface/parser.h> @@ -1104,6 +1105,22 @@ private: return inserted; } + const TString& FindColumnTypeAlias(const TString& colType) { + const static std::unordered_map<TString, TString> aliasMap { + {"smallserial", "int2"}, + {"serial2", "int2"}, + {"serial", "int4"}, + {"serial4", "int4"}, + {"bigserial", "int8"}, + {"serial8", "int8"}, + }; + const auto aliasIt = aliasMap.find(ToLowerUTF8(colType)); + if (aliasIt == aliasMap.end()) { + return colType; + } + return aliasIt->second; + } + bool AddColumn(TCreateTableCtx& ctx, const ColumnDef* node) { auto success = true; @@ -1143,9 +1160,10 @@ private: return success; // for now we pass just the last part of the type name - auto colType = StrVal( ListNodeNth(node->typeName->names, + auto colTypeVal = StrVal( ListNodeNth(node->typeName->names, ListLength(node->typeName->names) - 1)); - + const auto colType = FindColumnTypeAlias(colTypeVal); + ctx.Columns.push_back( QL(QA(node->colname), L(A("PgType"), QA(colType))) ); diff --git a/ydb/library/yql/sql/pg/pg_sql_ut.cpp b/ydb/library/yql/sql/pg/pg_sql_ut.cpp index 4966050d182..c851ddf1fc0 100644 --- a/ydb/library/yql/sql/pg/pg_sql_ut.cpp +++ b/ydb/library/yql/sql/pg/pg_sql_ut.cpp @@ -185,4 +185,19 @@ Y_UNIT_TEST_SUITE(PgSqlParsingOnly) { auto issue = *(res.Issues.begin()); UNIT_ASSERT(issue.GetMessage().find("PK column does not belong to table") != TString::npos); } + + Y_UNIT_TEST(CreateTableStmt_AliasSerialToIntType) { + auto res = PgSqlToYql("CREATE TABLE t (a SerIAL)"); + UNIT_ASSERT(res.Root); + + TString program = R"( + ( + (let world (Configure! world (DataSource 'config) 'OrderedColumns)) + (let world (Write! world (DataSink '"kikimr" '"") (Key '('tablescheme (String '"t"))) (Void) '('('mode 'create) '('columns '('('a (PgType 'int4))))))) + (let world (CommitAll! world)) + (return world)) + )"; + const auto expectedAst = NYql::ParseAst(program); + UNIT_ASSERT_STRINGS_EQUAL(res.Root->ToString(), expectedAst.Root->ToString()); + } } |