aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfedor-miron <fedor-miron@yandex-team.com>2023-06-13 16:09:14 +0300
committerfedor-miron <fedor-miron@yandex-team.com>2023-06-13 16:09:14 +0300
commite7c406e11b2e35f1ace37147754f76041f396c14 (patch)
tree570829435a590035a833872eb03a2f102b509182
parent601fdb1766899a5709c688c4dca97f39a4c7c012 (diff)
downloadydb-e7c406e11b2e35f1ace37147754f76041f396c14.tar.gz
add support pg temp table in parser
-rw-r--r--ydb/library/yql/sql/pg/pg_sql.cpp34
-rw-r--r--ydb/library/yql/sql/pg/pg_sql_ut.cpp16
2 files changed, 33 insertions, 17 deletions
diff --git a/ydb/library/yql/sql/pg/pg_sql.cpp b/ydb/library/yql/sql/pg/pg_sql.cpp
index 738a9856de..9ad7aa7b22 100644
--- a/ydb/library/yql/sql/pg/pg_sql.cpp
+++ b/ydb/library/yql/sql/pg/pg_sql.cpp
@@ -1056,6 +1056,7 @@ private:
std::vector<TAstNode*> PrimaryKey;
std::vector<TAstNode*> NotNullColumns;
std::unordered_set<TString> NotNullColSet;
+ bool isTemporary;
};
bool CheckConstraintSupported(const Constraint* pk) {
@@ -1223,6 +1224,9 @@ private:
if (!ctx.NotNullColumns.empty()) {
options.push_back(QL(QA("notnull"), QVL(ctx.NotNullColumns.data(), ctx.NotNullColumns.size())));
}
+ if (ctx.isTemporary) {
+ options.push_back(QL(QA("temporary")));
+ }
return QVL(options.data(), options.size());
}
@@ -1278,30 +1282,26 @@ public:
success = false;
}
- { auto relPersistence = static_cast<NPg::ERelPersistence>(value->relation->relpersistence);
- if (relPersistence != NPg::ERelPersistence::Permanent) {
- switch (relPersistence) {
- case NPg::ERelPersistence::Temp:
- AddError("CREATE TEMP TABLE not supported");
- break;
+ TCreateTableCtx ctx {};
- case NPg::ERelPersistence::Unlogged:
- AddError("UNLOGGED tables not supported");
- break;
-
- default:
- Y_UNREACHABLE();
- }
- success = false;
- }}
+ const auto relPersistence = static_cast<NPg::ERelPersistence>(value->relation->relpersistence);
+ switch (relPersistence) {
+ case NPg::ERelPersistence::Temp:
+ ctx.isTemporary = true;
+ break;
+ case NPg::ERelPersistence::Unlogged:
+ AddError("UNLOGGED tables not supported");
+ success = false;
+ break;
+ case NPg::ERelPersistence::Permanent:
+ break;
+ }
auto [sink, key] = ParseWriteRangeVar(value->relation, true);
if (!sink || !key)
success = false;
- TCreateTableCtx ctx;
-
for (ui32 i = 0; i < ListLength(value->tableElts); ++i) {
auto rawNode = ListNodeNth(value->tableElts, i);
diff --git a/ydb/library/yql/sql/pg/pg_sql_ut.cpp b/ydb/library/yql/sql/pg/pg_sql_ut.cpp
index f4ccd41490..87841b071a 100644
--- a/ydb/library/yql/sql/pg/pg_sql_ut.cpp
+++ b/ydb/library/yql/sql/pg/pg_sql_ut.cpp
@@ -217,6 +217,22 @@ Y_UNIT_TEST_SUITE(PgSqlParsingOnly) {
const auto expectedAst = NYql::ParseAst(program);
UNIT_ASSERT_STRINGS_EQUAL(res.Root->ToString(), expectedAst.Root->ToString());
}
+
+ Y_UNIT_TEST(CreateTableStmt_Temp) {
+ auto res = PgSqlToYql("create temp table t ()");
+ 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 '()) '('temporary))))
+ (let world (CommitAll! world))
+ (return world)
+ )
+ )";
+ const auto expectedAst = NYql::ParseAst(program);
+ UNIT_ASSERT_STRINGS_EQUAL(res.Root->ToString(), expectedAst.Root->ToString());
+ }
Y_UNIT_TEST(VariableShowStmt) {
auto res = PgSqlToYql("Show server_version_num");