Skip to content

Commit

Permalink
fixed pg_get_userbyid function (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitstn authored Feb 14, 2024
1 parent 1350fb4 commit 575378d
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 0 deletions.
50 changes: 50 additions & 0 deletions ydb/library/yql/parser/pg_wrapper/syscache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern "C" {
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "catalog/pg_type_d.h"
#include "catalog/pg_authid.h"
#include "access/htup_details.h"
}

Expand Down Expand Up @@ -63,6 +64,7 @@ struct TSysCache {
InitializeProcs();
InitializeTypes();
InitializeDatabase();
InitializeAuthId();
Arena.Release();
}

Expand Down Expand Up @@ -267,6 +269,54 @@ struct TSysCache {
map->emplace(key, h);
}
}

void InitializeAuthId() {
auto& map = Maps[AUTHOID] = std::make_unique<TSysCacheHashMap>(0, OidHasher1, OidEquals1);
TupleDesc tupleDesc = CreateTemplateTupleDesc(Natts_pg_authid);
FillAttr(tupleDesc, Anum_pg_authid_oid, OIDOID);
FillAttr(tupleDesc, Anum_pg_authid_rolname, NAMEOID);
FillAttr(tupleDesc, Anum_pg_authid_rolsuper, BOOLOID);
FillAttr(tupleDesc, Anum_pg_authid_rolinherit, BOOLOID);
FillAttr(tupleDesc, Anum_pg_authid_rolcreaterole, BOOLOID);
FillAttr(tupleDesc, Anum_pg_authid_rolcreatedb, BOOLOID);
FillAttr(tupleDesc, Anum_pg_authid_rolcanlogin, BOOLOID);
FillAttr(tupleDesc, Anum_pg_authid_rolreplication, BOOLOID);
FillAttr(tupleDesc, Anum_pg_authid_rolbypassrls, BOOLOID);
FillAttr(tupleDesc, Anum_pg_authid_rolconnlimit, INT4OID);
FillAttr(tupleDesc, Anum_pg_authid_rolpassword, TEXTOID);
FillAttr(tupleDesc, Anum_pg_authid_rolvaliduntil, TIMESTAMPTZOID);
auto key = THeapTupleKey(1, 0, 0, 0);

const char* rolname = "postgres";
const ui32 oid = 1;
Datum values[Natts_pg_authid];
bool nulls[Natts_pg_authid];
Zero(values);
std::fill_n(nulls, Natts_pg_authid, true);
FillDatum(Natts_pg_authid, values, nulls, Anum_pg_authid_oid, (Datum)oid);
FillDatum(Natts_pg_authid, values, nulls, Anum_pg_authid_rolname, (Datum)MakeFixedString(rolname, NAMEDATALEN));
FillDatum(Natts_pg_authid, values, nulls, Anum_pg_authid_rolsuper, BoolGetDatum(true));
FillDatum(Natts_pg_authid, values, nulls, Anum_pg_authid_rolinherit, BoolGetDatum(true));
FillDatum(Natts_pg_authid, values, nulls, Anum_pg_authid_rolcreaterole, BoolGetDatum(true));
FillDatum(Natts_pg_authid, values, nulls, Anum_pg_authid_rolcreatedb, BoolGetDatum(true));
FillDatum(Natts_pg_authid, values, nulls, Anum_pg_authid_rolcanlogin, BoolGetDatum(true));
FillDatum(Natts_pg_authid, values, nulls, Anum_pg_authid_rolreplication, BoolGetDatum(true));
FillDatum(Natts_pg_authid, values, nulls, Anum_pg_authid_rolbypassrls, BoolGetDatum(true));
FillDatum(Natts_pg_authid, values, nulls, Anum_pg_authid_rolconnlimit, Int32GetDatum(-1));
HeapTuple h = heap_form_tuple(tupleDesc, values, nulls);
auto row = (Form_pg_authid) GETSTRUCT(h);
Y_ENSURE(row->oid == oid);
Y_ENSURE(strcmp(NameStr(row->rolname), rolname) == 0);
Y_ENSURE(row->rolsuper);
Y_ENSURE(row->rolinherit);
Y_ENSURE(row->rolcreaterole);
Y_ENSURE(row->rolcreatedb);
Y_ENSURE(row->rolcanlogin);
Y_ENSURE(row->rolreplication);
Y_ENSURE(row->rolbypassrls);
Y_ENSURE(row->rolconnlimit == -1);
map->emplace(key, h);
}
};

}
Expand Down
22 changes: 22 additions & 0 deletions ydb/library/yql/tests/sql/dq_file/part5/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -2518,6 +2518,28 @@
}
],
"test.test[pg-tpch-q04-default.txt-Results]": [],
"test.test[pg_catalog-pg_get_userbyid-default.txt-Analyze]": [
{
"checksum": "c1f2d837c3623c81dd596a9877913fb8",
"size": 948,
"uri": "https://{canondata_backend}/1942525/71aa87e8531eaa616ea40214f4172330acf1be1c/resource.tar.gz#test.test_pg_catalog-pg_get_userbyid-default.txt-Analyze_/plan.txt"
}
],
"test.test[pg_catalog-pg_get_userbyid-default.txt-Debug]": [
{
"checksum": "eb190e413329d39ffbf2c4e6f827efce",
"size": 770,
"uri": "https://{canondata_backend}/1942525/71aa87e8531eaa616ea40214f4172330acf1be1c/resource.tar.gz#test.test_pg_catalog-pg_get_userbyid-default.txt-Debug_/opt.yql_patched"
}
],
"test.test[pg_catalog-pg_get_userbyid-default.txt-Plan]": [
{
"checksum": "c1f2d837c3623c81dd596a9877913fb8",
"size": 948,
"uri": "https://{canondata_backend}/1942525/71aa87e8531eaa616ea40214f4172330acf1be1c/resource.tar.gz#test.test_pg_catalog-pg_get_userbyid-default.txt-Plan_/plan.txt"
}
],
"test.test[pg_catalog-pg_get_userbyid-default.txt-Results]": [],
"test.test[pragma-file-default.txt-Analyze]": [
{
"checksum": "68782d7083169e0f53eb8f34e03cbbd4",
Expand Down
14 changes: 14 additions & 0 deletions ydb/library/yql/tests/sql/hybrid_file/part8/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -2407,6 +2407,20 @@
"uri": "https://{canondata_backend}/1923547/94f377eaa1d93890e1345ac4940cc6fa07bddd4f/resource.tar.gz#test.test_pg_catalog-pg_database-default.txt-Plan_/plan.txt"
}
],
"test.test[pg_catalog-pg_get_userbyid-default.txt-Debug]": [
{
"checksum": "09d14a7b7818dcaa23fbaaaf858be25e",
"size": 769,
"uri": "https://{canondata_backend}/1784826/664a8fd8dece5fbba1057a5f4bdc597c2c7b2e59/resource.tar.gz#test.test_pg_catalog-pg_get_userbyid-default.txt-Debug_/opt.yql_patched"
}
],
"test.test[pg_catalog-pg_get_userbyid-default.txt-Plan]": [
{
"checksum": "c1f2d837c3623c81dd596a9877913fb8",
"size": 948,
"uri": "https://{canondata_backend}/1784826/664a8fd8dece5fbba1057a5f4bdc597c2c7b2e59/resource.tar.gz#test.test_pg_catalog-pg_get_userbyid-default.txt-Plan_/plan.txt"
}
],
"test.test[pg_catalog-pg_timezone_abbrevs-default.txt-Debug]": [
{
"checksum": "941506f7f5f9f12223dbc2b0b0a2b94e",
Expand Down
7 changes: 7 additions & 0 deletions ydb/library/yql/tests/sql/sql2yql/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -13341,6 +13341,13 @@
"uri": "https://{canondata_backend}/1871002/aa5733774deffaee951006652c15a43754548f46/resource.tar.gz#test_sql2yql.test_pg_catalog-pg_description_pg_syntax_/sql.yql"
}
],
"test_sql2yql.test[pg_catalog-pg_get_userbyid]": [
{
"checksum": "7a48194bd2884f51ddd8c9ef1eea6b31",
"size": 797,
"uri": "https://{canondata_backend}/1880306/d434ed6028e0bff191bc4880f401a36e428f16a2/resource.tar.gz#test_sql2yql.test_pg_catalog-pg_get_userbyid_/sql.yql"
}
],
"test_sql2yql.test[pg_catalog-pg_inherits]": [
{
"checksum": "9e2b5f69bd2bc691faba1a97058d4358",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--!syntax_pg
select pg_get_userbyid(datdba) from pg_catalog.pg_database where datname = 'postgres'

Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,27 @@
"uri": "https://{canondata_backend}/1871002/505298b8553889a63710feb42e89279b206c3fb9/resource.tar.gz#test.test_pg-tpch-q04-default.txt-Results_/results.txt"
}
],
"test.test[pg_catalog-pg_get_userbyid-default.txt-Debug]": [
{
"checksum": "6ffcffb3d90a68445dc0ad7a2e2afa6f",
"size": 714,
"uri": "https://{canondata_backend}/1936842/e96f04cce8659030571e528019b2cca417350dee/resource.tar.gz#test.test_pg_catalog-pg_get_userbyid-default.txt-Debug_/opt.yql"
}
],
"test.test[pg_catalog-pg_get_userbyid-default.txt-Plan]": [
{
"checksum": "c1f2d837c3623c81dd596a9877913fb8",
"size": 948,
"uri": "https://{canondata_backend}/1936842/e96f04cce8659030571e528019b2cca417350dee/resource.tar.gz#test.test_pg_catalog-pg_get_userbyid-default.txt-Plan_/plan.txt"
}
],
"test.test[pg_catalog-pg_get_userbyid-default.txt-Results]": [
{
"checksum": "aa6447f2d475400b4feb2f1cab4a5a31",
"size": 677,
"uri": "https://{canondata_backend}/1936842/e96f04cce8659030571e528019b2cca417350dee/resource.tar.gz#test.test_pg_catalog-pg_get_userbyid-default.txt-Results_/results.txt"
}
],
"test.test[pragma-file-default.txt-Debug]": [
{
"checksum": "a10a5f8f497053c06dd6147b47a08a5f",
Expand Down

0 comments on commit 575378d

Please sign in to comment.