Skip to content

Commit 1e12440

Browse files
authored
More funcs for psql/pgadmin (#6784)
1 parent 73261ff commit 1e12440

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

ydb/core/kqp/ut/pg/pg_catalog_ut.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ Y_UNIT_TEST_SUITE(PgCatalog) {
459459
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
460460
UNIT_ASSERT_C(!result.GetResultSets().empty(), "no result sets");
461461
CompareYson(
462-
Sprintf("[[\"%u\"]]", experimentalPg ? 208 : 205),
462+
Sprintf("[[\"%u\"]]", experimentalPg ? 214 : 211),
463463
FormatResultSetYson(result.GetResultSet(0)));
464464
}
465465
}

ydb/library/yql/parser/pg_catalog/safe_procs.h

+14
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,17 @@
44
"pg_total_relation_size",
55
"row_to_json",
66
"version",
7+
8+
"set_config",//pgadmin
9+
"pg_is_in_recovery",//pgadmin
10+
"pg_is_wal_replay_paused",//pgadmin
11+
"has_database_privilege",//pgadmin
12+
"pg_backend_pid",//pgadmin
13+
"has_schema_privilege",//pgadmin
14+
15+
"pg_encoding_to_char",//psql
16+
"pg_function_is_visible",//psql
17+
"pg_get_function_result",//psql
18+
"pg_get_function_arguments",//psql
19+
"pg_table_is_visible",//psql
20+

ydb/library/yql/parser/pg_wrapper/comp_factory.cpp

+37-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ class TPgTableContent : public TMutableComputationNode<TPgTableContent> {
435435
{"rolname", [](ui32 index) {
436436
return PointerDatumToPod((Datum)MakeFixedString(index == 1 ? "postgres" : *PGGetGUCSetting("ydb_user"), NAMEDATALEN));
437437
}},
438-
{"oid", [](ui32) { return ScalarDatumToPod(ObjectIdGetDatum(1)); }},
438+
{"oid", [](ui32 index) { return ScalarDatumToPod(ObjectIdGetDatum(index)); }},
439439
{"rolbypassrls", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
440440
{"rolsuper", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
441441
{"rolinherit", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
@@ -453,6 +453,26 @@ class TPgTableContent : public TMutableComputationNode<TPgTableContent> {
453453
};
454454

455455
ApplyFillers(AllPgRolesFillers, Y_ARRAY_SIZE(AllPgRolesFillers), PgRolesFillers_);
456+
} else if (Table_ == "pg_user") {
457+
static const std::pair<const char*, TPgUserFiller> AllPgUserFillers[] = {
458+
{"usename", [](ui32 index) {
459+
return PointerDatumToPod((Datum)MakeFixedString(index == 1 ? "postgres" : *PGGetGUCSetting("ydb_user"), NAMEDATALEN));
460+
}},
461+
{"usesysid", [](ui32 index) { return ScalarDatumToPod(ObjectIdGetDatum(index)); }},
462+
{"usecreatedb", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
463+
{"usesuper", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
464+
{"userepl", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
465+
{"usebypassrls", [](ui32) { return ScalarDatumToPod(BoolGetDatum(true)); }},
466+
{"passwd", [](ui32) { return NUdf::TUnboxedValuePod(); }},
467+
{"valuntil", [](ui32) { return NUdf::TUnboxedValuePod(); }},
468+
{"useconfig", [](ui32) { return PointerDatumToPod(MakeArrayOfText({
469+
"search_path=public",
470+
"default_transaction_isolation=serializable",
471+
"standard_conforming_strings=on",
472+
})); }},
473+
};
474+
475+
ApplyFillers(AllPgUserFillers, Y_ARRAY_SIZE(AllPgUserFillers), PgUserFillers_);
456476
} else if (Table_ == "pg_stat_database") {
457477
static const std::pair<const char*, TPgDatabaseStatFiller> AllPgDatabaseStatFillers[] = {
458478
{"datid", [](ui32 index) { return ScalarDatumToPod(ObjectIdGetDatum(index ? 3 : 0)); }},
@@ -801,6 +821,20 @@ class TPgTableContent : public TMutableComputationNode<TPgTableContent> {
801821
}
802822
}
803823

824+
sysFiller.Fill(items);
825+
rows.emplace_back(row);
826+
}
827+
} else if (Table_ == "pg_user") {
828+
ui32 tableSize = PGGetGUCSetting("ydb_user") ? 2 : 1;
829+
for (ui32 index = 1; index <= tableSize; ++index) {
830+
NUdf::TUnboxedValue* items;
831+
auto row = compCtx.HolderFactory.CreateDirectArrayHolder(PgUserFillers_.size(), items);
832+
for (ui32 i = 0; i < PgUserFillers_.size(); ++i) {
833+
if (PgUserFillers_[i]) {
834+
items[i] = PgUserFillers_[i](index);
835+
}
836+
}
837+
804838
sysFiller.Fill(items);
805839
rows.emplace_back(row);
806840
}
@@ -956,6 +990,8 @@ class TPgTableContent : public TMutableComputationNode<TPgTableContent> {
956990
TVector<TPgAmFiller> PgAmFillers_;
957991
using TPgRolesFiller = NUdf::TUnboxedValuePod(*)(ui32 index);
958992
TVector<TPgRolesFiller> PgRolesFillers_;
993+
using TPgUserFiller = NUdf::TUnboxedValuePod(*)(ui32 index);
994+
TVector<TPgUserFiller> PgUserFillers_;
959995
using TPgDatabaseStatFiller = NUdf::TUnboxedValuePod(*)(ui32 index);
960996
TVector<TPgDatabaseStatFiller> PgDatabaseStatFillers_;
961997

ydb/library/yql/sql/pg/pg_sql.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -3505,8 +3505,10 @@ class TConverter : public IPGParseEvents {
35053505
);
35063506
case SVFOP_CURRENT_USER:
35073507
case SVFOP_CURRENT_ROLE:
3508-
case SVFOP_USER:
3509-
return L(A("PgConst"), QA("postgres"), L(A("PgType"), QA("name")));
3508+
case SVFOP_USER: {
3509+
auto user = Settings.GUCSettings->Get("ydb_user");
3510+
return L(A("PgConst"), user ? QAX(TString(*user)) : QA("postgres"), L(A("PgType"), QA("name")));
3511+
}
35103512
case SVFOP_CURRENT_CATALOG: {
35113513
std::optional<TString> database;
35123514
if (Settings.GUCSettings) {

0 commit comments

Comments
 (0)