aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvvvv <vvvv@ydb.tech>2023-12-08 14:02:49 +0300
committervvvv <vvvv@ydb.tech>2023-12-08 15:44:00 +0300
commit9a5a56cfbd85bc517d9979ae246b447298d8f9b4 (patch)
treee308dc4998d3856680b2f59f99579bc120edc629
parente1fd0f7bb4712ff4be116d4b16c2bac076cd1318 (diff)
downloadydb-mai.tar.gz
YQL-17264 [pg][yt] fix drop table, commit, rollbackmai
-rw-r--r--ydb/library/yql/providers/yt/provider/yql_yt_key.cpp7
-rw-r--r--ydb/library/yql/providers/yt/provider/yql_yt_key.h2
-rw-r--r--ydb/library/yql/sql/pg/pg_sql.cpp22
-rw-r--r--ydb/library/yql/tests/postgresql/cases/create_table.out14
-rw-r--r--ydb/library/yql/tests/postgresql/cases/create_table.sql14
-rw-r--r--ydb/library/yql/tests/sql/dq_file/part4/canondata/result.json22
-rw-r--r--ydb/library/yql/tests/sql/sql2yql/canondata/result.json7
-rw-r--r--ydb/library/yql/tests/sql/suites/pg/drop_table.cfg1
-rw-r--r--ydb/library/yql/tests/sql/suites/pg/drop_table.sql17
-rw-r--r--ydb/library/yql/tests/sql/yt_native_file/part4/canondata/result.json15
10 files changed, 89 insertions, 32 deletions
diff --git a/ydb/library/yql/providers/yt/provider/yql_yt_key.cpp b/ydb/library/yql/providers/yt/provider/yql_yt_key.cpp
index ab78d45824..522aa4f117 100644
--- a/ydb/library/yql/providers/yt/provider/yql_yt_key.cpp
+++ b/ydb/library/yql/providers/yt/provider/yql_yt_key.cpp
@@ -29,7 +29,7 @@ THashSet<TStringBuf> KEY_CALLABLES = {
}
-bool TYtKey::Parse(const TExprNode& key, TExprContext& ctx) {
+bool TYtKey::Parse(const TExprNode& key, TExprContext& ctx, bool isOutput) {
using namespace NNodes;
if (!key.IsCallable(EXT_KEY_CALLABLES)) {
ctx.AddError(TIssue(ctx.GetPosition(key.Pos()), TStringBuf("Expected key")));
@@ -123,6 +123,9 @@ bool TYtKey::Parse(const TExprNode& key, TExprContext& ctx) {
ctx.AddError(TIssue(ctx.GetPosition(key.Pos()), "Too many tags"));
return false;
}
+ if (isOutput) {
+ Type = EType::Table;
+ }
} else {
ctx.AddError(TIssue(ctx.GetPosition(key.Child(0)->Pos()), TString("Unexpected tag: ") + tagName));
return false;
@@ -267,7 +270,7 @@ bool TYtOutputKey::Parse(const TExprNode& keyNode, TExprContext& ctx) {
if (!keyNode.IsCallable(KEY_CALLABLES)) {
return true;
}
- if (!TYtKey::Parse(keyNode, ctx)) {
+ if (!TYtKey::Parse(keyNode, ctx, true)) {
return false;
}
diff --git a/ydb/library/yql/providers/yt/provider/yql_yt_key.h b/ydb/library/yql/providers/yt/provider/yql_yt_key.h
index f1381900d7..5fbd1838e7 100644
--- a/ydb/library/yql/providers/yt/provider/yql_yt_key.h
+++ b/ydb/library/yql/providers/yt/provider/yql_yt_key.h
@@ -114,7 +114,7 @@ public:
return WalkFolderImplArgs;
}
- bool Parse(const TExprNode& key, TExprContext& ctx);
+ bool Parse(const TExprNode& key, TExprContext& ctx, bool isOutput = false);
private:
EType Type = EType::Undefined;
diff --git a/ydb/library/yql/sql/pg/pg_sql.cpp b/ydb/library/yql/sql/pg/pg_sql.cpp
index ea46e5435b..a8cfb97160 100644
--- a/ydb/library/yql/sql/pg/pg_sql.cpp
+++ b/ydb/library/yql/sql/pg/pg_sql.cpp
@@ -411,7 +411,7 @@ public:
case T_VariableShowStmt:
return ParseVariableShowStmt(CAST_NODE(VariableShowStmt, node)) != nullptr;
case T_TransactionStmt:
- return true;
+ return ParseTransactionStmt(CAST_NODE(TransactionStmt, node));
case T_IndexStmt:
return ParseIndexStmt(CAST_NODE(IndexStmt, node)) != nullptr;
default:
@@ -2249,6 +2249,26 @@ public:
}
[[nodiscard]]
+ bool ParseTransactionStmt(const TransactionStmt* value) {
+ switch (value->kind) {
+ case TRANS_STMT_BEGIN: [[fallthrough]] ;
+ case TRANS_STMT_START:
+ return true;
+ case TRANS_STMT_COMMIT:
+ Statements.push_back(L(A("let"), A("world"), L(A("CommitAll!"),
+ A("world"))));
+ return true;
+ case TRANS_STMT_ROLLBACK:
+ Statements.push_back(L(A("let"), A("world"), L(A("CommitAll!"),
+ A("world"), QL(QL(QA("mode"), QA("rollback"))))));
+ return true;
+ default:
+ AddError(TStringBuilder() << "TransactionStmt: kind is not supported: " << (int)value->kind);
+ return false;
+ }
+ }
+
+ [[nodiscard]]
TAstNode* ParseIndexStmt(const IndexStmt* value) {
if (value->unique) {
AddError("unique index creation is not supported yet");
diff --git a/ydb/library/yql/tests/postgresql/cases/create_table.out b/ydb/library/yql/tests/postgresql/cases/create_table.out
index 40c55dc27c..20f58a07f9 100644
--- a/ydb/library/yql/tests/postgresql/cases/create_table.out
+++ b/ydb/library/yql/tests/postgresql/cases/create_table.out
@@ -178,20 +178,6 @@ LINE 1: CREATE TABLE withoid() WITH OIDS;
-- but explicitly not adding oids is still supported
CREATE TEMP TABLE withoutoid() WITHOUT OIDS;
DROP TABLE withoutoid;
--- Verify that subtransaction rollback restores rd_createSubid.
-BEGIN;
-CREATE TABLE remember_create_subid (c int);
-SAVEPOINT q;
-DROP TABLE remember_create_subid;
-ROLLBACK TO q;
-COMMIT;
--- Verify that subtransaction rollback restores rd_firstRelfilenodeSubid.
-CREATE TABLE remember_node_subid (c int);
-BEGIN;
-SAVEPOINT q;
-DROP TABLE remember_node_subid;
-ROLLBACK TO q;
-COMMIT;
-- syntax does not allow empty list of values for list partitions
CREATE TABLE fail_part PARTITION OF list_parted FOR VALUES IN ();
ERROR: syntax error at or near ")"
diff --git a/ydb/library/yql/tests/postgresql/cases/create_table.sql b/ydb/library/yql/tests/postgresql/cases/create_table.sql
index 2f597f9645..0e783812a3 100644
--- a/ydb/library/yql/tests/postgresql/cases/create_table.sql
+++ b/ydb/library/yql/tests/postgresql/cases/create_table.sql
@@ -175,20 +175,6 @@ CREATE TABLE withoid() WITH OIDS;
-- but explicitly not adding oids is still supported
CREATE TEMP TABLE withoutoid() WITHOUT OIDS;
DROP TABLE withoutoid;
--- Verify that subtransaction rollback restores rd_createSubid.
-BEGIN;
-CREATE TABLE remember_create_subid (c int);
-SAVEPOINT q;
-DROP TABLE remember_create_subid;
-ROLLBACK TO q;
-COMMIT;
--- Verify that subtransaction rollback restores rd_firstRelfilenodeSubid.
-CREATE TABLE remember_node_subid (c int);
-BEGIN;
-SAVEPOINT q;
-DROP TABLE remember_node_subid;
-ROLLBACK TO q;
-COMMIT;
-- syntax does not allow empty list of values for list partitions
CREATE TABLE fail_part PARTITION OF list_parted FOR VALUES IN ();
-- check if compatible with the specified parent
diff --git a/ydb/library/yql/tests/sql/dq_file/part4/canondata/result.json b/ydb/library/yql/tests/sql/dq_file/part4/canondata/result.json
index c3ac485c08..2aa4d051ee 100644
--- a/ydb/library/yql/tests/sql/dq_file/part4/canondata/result.json
+++ b/ydb/library/yql/tests/sql/dq_file/part4/canondata/result.json
@@ -3972,6 +3972,28 @@
"uri": "file://test.test_params-no_optional_param-default.txt-Results_/extracted"
}
],
+ "test.test[pg-drop_table--Analyze]": [
+ {
+ "checksum": "5ba98022094d906a6acb7cf1b61f14ed",
+ "size": 7494,
+ "uri": "https://{canondata_backend}/1130705/9726e618a91dba7201c15a2e45d93b6d8fd96178/resource.tar.gz#test.test_pg-drop_table--Analyze_/plan.txt"
+ }
+ ],
+ "test.test[pg-drop_table--Debug]": [
+ {
+ "checksum": "74ce4b840fa1896ab2f080d1c57efd9a",
+ "size": 2243,
+ "uri": "https://{canondata_backend}/1130705/9726e618a91dba7201c15a2e45d93b6d8fd96178/resource.tar.gz#test.test_pg-drop_table--Debug_/opt.yql_patched"
+ }
+ ],
+ "test.test[pg-drop_table--Plan]": [
+ {
+ "checksum": "5ba98022094d906a6acb7cf1b61f14ed",
+ "size": 7494,
+ "uri": "https://{canondata_backend}/1130705/9726e618a91dba7201c15a2e45d93b6d8fd96178/resource.tar.gz#test.test_pg-drop_table--Plan_/plan.txt"
+ }
+ ],
+ "test.test[pg-drop_table--Results]": [],
"test.test[pg-in_sorted-default.txt-Analyze]": [
{
"checksum": "b4dd508a329723c74293d80f0278c705",
diff --git a/ydb/library/yql/tests/sql/sql2yql/canondata/result.json b/ydb/library/yql/tests/sql/sql2yql/canondata/result.json
index 4d9f624192..603a9e77b1 100644
--- a/ydb/library/yql/tests/sql/sql2yql/canondata/result.json
+++ b/ydb/library/yql/tests/sql/sql2yql/canondata/result.json
@@ -10730,6 +10730,13 @@
"uri": "https://{canondata_backend}/1599023/af9c2f81df0601cf266a0926b5ce73b6101b9115/resource.tar.gz#test_sql2yql.test_pg-distinct_on_single_projection_order_expr_/sql.yql"
}
],
+ "test_sql2yql.test[pg-drop_table]": [
+ {
+ "checksum": "a17122997a6bf872af77c286174322eb",
+ "size": 1072,
+ "uri": "https://{canondata_backend}/1773845/51dddb62bab338531c7d40a97ff817188ae84088/resource.tar.gz#test_sql2yql.test_pg-drop_table_/sql.yql"
+ }
+ ],
"test_sql2yql.test[pg-equals_where_over_cross2]": [
{
"checksum": "d841f0531fcd35f49398d967ddc8968f",
diff --git a/ydb/library/yql/tests/sql/suites/pg/drop_table.cfg b/ydb/library/yql/tests/sql/suites/pg/drop_table.cfg
new file mode 100644
index 0000000000..9b85bd0ae8
--- /dev/null
+++ b/ydb/library/yql/tests/sql/suites/pg/drop_table.cfg
@@ -0,0 +1 @@
+out Output output.txt
diff --git a/ydb/library/yql/tests/sql/suites/pg/drop_table.sql b/ydb/library/yql/tests/sql/suites/pg/drop_table.sql
new file mode 100644
index 0000000000..7a3549cd75
--- /dev/null
+++ b/ydb/library/yql/tests/sql/suites/pg/drop_table.sql
@@ -0,0 +1,17 @@
+--!syntax_pg
+
+insert into plato."Output"
+SELECT 1;
+
+commit;
+
+drop table plato."Output";
+
+commit;
+
+insert into plato."Output"
+SELECT 'foo';
+
+commit;
+
+drop table plato."Output";
diff --git a/ydb/library/yql/tests/sql/yt_native_file/part4/canondata/result.json b/ydb/library/yql/tests/sql/yt_native_file/part4/canondata/result.json
index 828d54cf26..f5449215fc 100644
--- a/ydb/library/yql/tests/sql/yt_native_file/part4/canondata/result.json
+++ b/ydb/library/yql/tests/sql/yt_native_file/part4/canondata/result.json
@@ -3451,6 +3451,21 @@
"uri": "file://test.test_params-no_optional_param-default.txt-Results_/extracted"
}
],
+ "test.test[pg-drop_table--Debug]": [
+ {
+ "checksum": "ca9540ca7a9b99aac52ae5d266daa9b7",
+ "size": 2181,
+ "uri": "https://{canondata_backend}/1942525/e3a940019ce30db1abd11733965d1a08d079b0b0/resource.tar.gz#test.test_pg-drop_table--Debug_/opt.yql"
+ }
+ ],
+ "test.test[pg-drop_table--Plan]": [
+ {
+ "checksum": "ba9681deb327593f55fb446c8635c0f3",
+ "size": 7494,
+ "uri": "https://{canondata_backend}/1942525/e3a940019ce30db1abd11733965d1a08d079b0b0/resource.tar.gz#test.test_pg-drop_table--Plan_/plan.txt"
+ }
+ ],
+ "test.test[pg-drop_table--Results]": [],
"test.test[pg-in_sorted-default.txt-Debug]": [
{
"checksum": "c8d67b6c2624cf5a0c3a52aec9da61ac",