diff options
author | fedor-miron <fedor-miron@yandex-team.com> | 2023-06-16 18:10:03 +0300 |
---|---|---|
committer | fedor-miron <fedor-miron@yandex-team.com> | 2023-06-16 18:10:03 +0300 |
commit | 06f9c4f449aed9cd2eb3996de068b794fa046fc5 (patch) | |
tree | 74821fa26942a48c78eccd51f2ece2d035a2d6b6 | |
parent | 96575f782f7c9e4f910523f40f68d5275558cb0d (diff) | |
download | ydb-06f9c4f449aed9cd2eb3996de068b794fa046fc5.tar.gz |
YQL-16097: add support for pg default values in parser
-rw-r--r-- | ydb/library/yql/sql/pg/pg_sql.cpp | 29 | ||||
-rw-r--r-- | ydb/library/yql/sql/pg/pg_sql_ut.cpp | 19 |
2 files changed, 38 insertions, 10 deletions
diff --git a/ydb/library/yql/sql/pg/pg_sql.cpp b/ydb/library/yql/sql/pg/pg_sql.cpp index 1b3e9010db..05b8a5955f 100644 --- a/ydb/library/yql/sql/pg/pg_sql.cpp +++ b/ydb/library/yql/sql/pg/pg_sql.cpp @@ -910,11 +910,6 @@ public: [[nodiscard]] TAstNode* ParseInsertStmt(const InsertStmt* value) { - if (!value->selectStmt) { - AddError("InsertStmt: expected Select"); - return nullptr; - } - if (value->onConflictClause) { AddError("InsertStmt: not supported onConflictClause"); return nullptr; @@ -952,16 +947,15 @@ public: } } - auto select = ParseSelectStmt(CAST_NODE(SelectStmt, value->selectStmt), true, targetColumns); + const auto select = (value->selectStmt) + ? ParseSelectStmt(CAST_NODE(SelectStmt, value->selectStmt), true, targetColumns) + : L(A("Void")); if (!select) { return nullptr; } - auto insertMode = (ProviderToInsertModeMap.contains(Provider)) - ? ProviderToInsertModeMap.at(Provider) - : "append"; + const auto writeOptions = BuildWriteOptions(value); - auto writeOptions = QL(QL(QA("mode"), QA(insertMode))); Statements.push_back(L( A("let"), A("world"), @@ -1225,6 +1219,21 @@ private: return QVL(options.data(), options.size()); } + TAstNode* BuildWriteOptions(const InsertStmt* value) { + std::vector<TAstNode*> options; + + const auto insertMode = (ProviderToInsertModeMap.contains(Provider)) + ? ProviderToInsertModeMap.at(Provider) + : "append"; + options.push_back(QL(QA("mode"), QA(insertMode))); + + if (!value->selectStmt) { + options.push_back(QL(QA("default_values"))); + } + + return QVL(options.data(), options.size()); + } + public: [[nodiscard]] TAstNode* ParseCreateStmt(const CreateStmt* value) { diff --git a/ydb/library/yql/sql/pg/pg_sql_ut.cpp b/ydb/library/yql/sql/pg/pg_sql_ut.cpp index 87841b071a..4aca0741c8 100644 --- a/ydb/library/yql/sql/pg/pg_sql_ut.cpp +++ b/ydb/library/yql/sql/pg/pg_sql_ut.cpp @@ -72,6 +72,25 @@ Y_UNIT_TEST_SUITE(PgSqlParsingOnly) { res.Root->PrintTo(Cerr); } + Y_UNIT_TEST(InsertStmt_DefaultValues) { + auto res = PgSqlToYql("INSERT INTO plato.Input DEFAULT VALUES"); + UNIT_ASSERT(res.Root); + + const NYql::TAstNode* writeNode = nullptr; + VisitAstNodes(*res.Root, [&writeNode] (const NYql::TAstNode& node) { + const bool isWriteNode = node.IsList() && node.GetChildrenCount() > 0 + && node.GetChild(0)->IsAtom() && node.GetChild(0)->GetContent() == "Write!"; + if (isWriteNode) { + writeNode = &node; + } + }); + + UNIT_ASSERT(writeNode); + UNIT_ASSERT(writeNode->GetChildrenCount() > 5); + const auto optionsQListNode = writeNode->GetChild(5); + UNIT_ASSERT(optionsQListNode->ToString().Contains("'default_values")); + } + Y_UNIT_TEST(DeleteStmt) { auto res = PgSqlToYql("DELETE FROM plato.Input"); UNIT_ASSERT(res.Root); |