Skip to content

More funcs for psql/pgadmin #6784

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 3 commits into from
Jul 17, 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
2 changes: 1 addition & 1 deletion ydb/core/kqp/ut/pg/pg_catalog_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ Y_UNIT_TEST_SUITE(PgCatalog) {
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
UNIT_ASSERT_C(!result.GetResultSets().empty(), "no result sets");
CompareYson(
Sprintf("[[\"%u\"]]", experimentalPg ? 208 : 205),
Sprintf("[[\"%u\"]]", experimentalPg ? 214 : 211),
FormatResultSetYson(result.GetResultSet(0)));
}
}
Expand Down
14 changes: 14 additions & 0 deletions ydb/library/yql/parser/pg_catalog/safe_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@
"pg_total_relation_size",
"row_to_json",
"version",

"set_config",//pgadmin
"pg_is_in_recovery",//pgadmin
"pg_is_wal_replay_paused",//pgadmin
"has_database_privilege",//pgadmin
"pg_backend_pid",//pgadmin
"has_schema_privilege",//pgadmin

"pg_encoding_to_char",//psql
"pg_function_is_visible",//psql
"pg_get_function_result",//psql
"pg_get_function_arguments",//psql
"pg_table_is_visible",//psql

38 changes: 37 additions & 1 deletion ydb/library/yql/parser/pg_wrapper/comp_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class TPgTableContent : public TMutableComputationNode<TPgTableContent> {
{"rolname", [](ui32 index) {
return PointerDatumToPod((Datum)MakeFixedString(index == 1 ? "postgres" : *PGGetGUCSetting("ydb_user"), NAMEDATALEN));
}},
{"oid", [](ui32) { return ScalarDatumToPod(ObjectIdGetDatum(1)); }},
{"oid", [](ui32 index) { return ScalarDatumToPod(ObjectIdGetDatum(index)); }},
{"rolbypassrls", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
{"rolsuper", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
{"rolinherit", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
Expand All @@ -453,6 +453,26 @@ class TPgTableContent : public TMutableComputationNode<TPgTableContent> {
};

ApplyFillers(AllPgRolesFillers, Y_ARRAY_SIZE(AllPgRolesFillers), PgRolesFillers_);
} else if (Table_ == "pg_user") {
static const std::pair<const char*, TPgUserFiller> AllPgUserFillers[] = {
{"usename", [](ui32 index) {
return PointerDatumToPod((Datum)MakeFixedString(index == 1 ? "postgres" : *PGGetGUCSetting("ydb_user"), NAMEDATALEN));
}},
{"usesysid", [](ui32 index) { return ScalarDatumToPod(ObjectIdGetDatum(index)); }},
{"usecreatedb", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
{"usesuper", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
{"userepl", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
{"usebypassrls", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
{"passwd", [](ui32) { return NUdf::TUnboxedValuePod(); }},
{"valuntil", [](ui32) { return NUdf::TUnboxedValuePod(); }},
{"useconfig", [](ui32) { return PointerDatumToPod(MakeArrayOfText({
"search_path=public",
"default_transaction_isolation=serializable",
"standard_conforming_strings=on",
})); }},
};

ApplyFillers(AllPgUserFillers, Y_ARRAY_SIZE(AllPgUserFillers), PgUserFillers_);
} else if (Table_ == "pg_stat_database") {
static const std::pair<const char*, TPgDatabaseStatFiller> AllPgDatabaseStatFillers[] = {
{"datid", [](ui32 index) { return ScalarDatumToPod(ObjectIdGetDatum(index ? 3 : 0)); }},
Expand Down Expand Up @@ -801,6 +821,20 @@ class TPgTableContent : public TMutableComputationNode<TPgTableContent> {
}
}

sysFiller.Fill(items);
rows.emplace_back(row);
}
} else if (Table_ == "pg_user") {
ui32 tableSize = PGGetGUCSetting("ydb_user") ? 2 : 1;
for (ui32 index = 1; index <= tableSize; ++index) {
NUdf::TUnboxedValue* items;
auto row = compCtx.HolderFactory.CreateDirectArrayHolder(PgUserFillers_.size(), items);
for (ui32 i = 0; i < PgUserFillers_.size(); ++i) {
if (PgUserFillers_[i]) {
items[i] = PgUserFillers_[i](index);
}
}

sysFiller.Fill(items);
rows.emplace_back(row);
}
Expand Down Expand Up @@ -956,6 +990,8 @@ class TPgTableContent : public TMutableComputationNode<TPgTableContent> {
TVector<TPgAmFiller> PgAmFillers_;
using TPgRolesFiller = NUdf::TUnboxedValuePod(*)(ui32 index);
TVector<TPgRolesFiller> PgRolesFillers_;
using TPgUserFiller = NUdf::TUnboxedValuePod(*)(ui32 index);
TVector<TPgUserFiller> PgUserFillers_;
using TPgDatabaseStatFiller = NUdf::TUnboxedValuePod(*)(ui32 index);
TVector<TPgDatabaseStatFiller> PgDatabaseStatFillers_;

Expand Down
6 changes: 4 additions & 2 deletions ydb/library/yql/sql/pg/pg_sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3505,8 +3505,10 @@ class TConverter : public IPGParseEvents {
);
case SVFOP_CURRENT_USER:
case SVFOP_CURRENT_ROLE:
case SVFOP_USER:
return L(A("PgConst"), QA("postgres"), L(A("PgType"), QA("name")));
case SVFOP_USER: {
auto user = Settings.GUCSettings->Get("ydb_user");
return L(A("PgConst"), user ? QAX(TString(*user)) : QA("postgres"), L(A("PgType"), QA("name")));
}
case SVFOP_CURRENT_CATALOG: {
std::optional<TString> database;
if (Settings.GUCSettings) {
Expand Down
Loading