Skip to content

Support of current_schema as function #6886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions ydb/library/yql/sql/pg/pg_sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3517,20 +3517,23 @@ class TConverter : public IPGParseEvents {

return L(A("PgConst"), QA(database ? *database : "postgres"), L(A("PgType"), QA("name")));
}
case SVFOP_CURRENT_SCHEMA: {
std::optional<TString> searchPath;
if (Settings.GUCSettings) {
searchPath = Settings.GUCSettings->Get("search_path");
}

return L(A("PgConst"), QA(searchPath ? *searchPath : "public"), L(A("PgType"), QA("name")));
}
case SVFOP_CURRENT_SCHEMA:
return GetCurrentSchema();
default:
AddError(TStringBuilder() << "Usupported SQLValueFunction: " << (int)value->op);
return nullptr;
}
}

TAstNode* GetCurrentSchema() {
std::optional<TString> searchPath;
if (Settings.GUCSettings) {
searchPath = Settings.GUCSettings->Get("search_path");
}

return L(A("PgConst"), QA(searchPath ? *searchPath : "public"), L(A("PgType"), QA("name")));
}

TAstNode* ParseBooleanTest(const BooleanTest* value, const TExprSettings& settings) {
AT_LOCATION(value);

Expand Down Expand Up @@ -3997,6 +4000,10 @@ class TConverter : public IPGParseEvents {
return L(A("Null"));
}

if (name == "current_schema") {
return GetCurrentSchema();
}

// for zabbix https://github.com/ydb-platform/ydb/issues/2904
if (name == "pg_try_advisory_lock" || name == "pg_try_advisory_lock_shared" || name == "pg_advisory_unlock" || name == "pg_try_advisory_xact_lock" || name == "pg_try_advisory_xact_lock_shared"){
AddWarning(TIssuesIds::PG_COMPAT, name + " function forced to return OK without waiting and without really lock/unlock");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2258,9 +2258,9 @@
],
"test.test[pg_catalog-user-default.txt-Debug]": [
{
"checksum": "d5452a3a8b3315f78096106246b0cc4f",
"size": 734,
"uri": "https://{canondata_backend}/1031349/f9e5528e64f4bcdb4154fd10489bc2c93c9230cf/resource.tar.gz#test.test_pg_catalog-user-default.txt-Debug_/opt.yql_patched"
"checksum": "c0c4cb48beaa172880a589e79e2d9cab",
"size": 830,
"uri": "https://{canondata_backend}/1925821/2762f8f29ee80e9d69a3fae7ac21750c067803da/resource.tar.gz#test.test_pg_catalog-user-default.txt-Debug_/opt.yql_patched"
}
],
"test.test[pg_catalog-user-default.txt-Plan]": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2479,9 +2479,9 @@
],
"test.test[pg_catalog-user-default.txt-Debug]": [
{
"checksum": "ffdea96691e646c2bfa1b8d4e063f06d",
"size": 733,
"uri": "https://{canondata_backend}/1031349/45aada6c316544e03166fc51527848ab05146f50/resource.tar.gz#test.test_pg_catalog-user-default.txt-Debug_/opt.yql_patched"
"checksum": "4af800de2b7698d999d63cbeb508e93b",
"size": 829,
"uri": "https://{canondata_backend}/937458/8c856e93170e875aa0a26dc4a34de068016e4377/resource.tar.gz#test.test_pg_catalog-user-default.txt-Debug_/opt.yql_patched"
}
],
"test.test[pg_catalog-user-default.txt-Plan]": [
Expand Down
6 changes: 3 additions & 3 deletions ydb/library/yql/tests/sql/sql2yql/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -15051,9 +15051,9 @@
],
"test_sql2yql.test[pg_catalog-user]": [
{
"checksum": "b317c499b3d4e34107e1430e89576b26",
"size": 1450,
"uri": "https://{canondata_backend}/1925821/85af800a282697ba458d7b0567031a1eadd214a4/resource.tar.gz#test_sql2yql.test_pg_catalog-user_/sql.yql"
"checksum": "a7b59168ee545aec600996c65be07ab4",
"size": 1626,
"uri": "https://{canondata_backend}/1773845/dbc47337ac2531600b4ba49bf1235a6f07ff1422/resource.tar.gz#test_sql2yql.test_pg_catalog-user_/sql.yql"
}
],
"test_sql2yql.test[pragma-classic_division]": [
Expand Down
5 changes: 3 additions & 2 deletions ydb/library/yql/tests/sql/suites/pg_catalog/user.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
--!syntax_pg
select user, current_user, current_role, current_catalog, current_schema;
select user, current_user, current_role, current_catalog, current_schema, current_schema();
set search_path to "pg_catalog";
select user, current_user, current_role, current_catalog, current_schema;
select user, current_user, current_role, current_catalog, current_schema, current_schema();


Original file line number Diff line number Diff line change
Expand Up @@ -2188,9 +2188,9 @@
],
"test.test[pg_catalog-user-default.txt-Debug]": [
{
"checksum": "a3ac463405bd37eba6e90620a124fe96",
"size": 673,
"uri": "https://{canondata_backend}/1031349/e0d85027c4e39b38b460c0dbc0618a662f8a1dc3/resource.tar.gz#test.test_pg_catalog-user-default.txt-Debug_/opt.yql"
"checksum": "f3befc2c7ccd151ec1627935713e944f",
"size": 768,
"uri": "https://{canondata_backend}/1899731/8e3863ca69967a81b91196b65004961a7c52e2a5/resource.tar.gz#test.test_pg_catalog-user-default.txt-Debug_/opt.yql"
}
],
"test.test[pg_catalog-user-default.txt-Plan]": [
Expand All @@ -2202,9 +2202,9 @@
],
"test.test[pg_catalog-user-default.txt-Results]": [
{
"checksum": "231a565780cbd001099daeb95dc7ed4e",
"size": 4182,
"uri": "https://{canondata_backend}/1900335/b19e3a88f54bb49e1964c45fd96be88e34fd38d0/resource.tar.gz#test.test_pg_catalog-user-default.txt-Results_/results.txt"
"checksum": "fdb8e5ac8f1bed8efea16c30e07a0286",
"size": 4872,
"uri": "https://{canondata_backend}/1899731/8e3863ca69967a81b91196b65004961a7c52e2a5/resource.tar.gz#test.test_pg_catalog-user-default.txt-Results_/results.txt"
}
],
"test.test[produce-process_with_lambda-default.txt-Debug]": [
Expand Down
Loading