Skip to content

Commit 6d464f5

Browse files
authored
Exposed extensions via pg_extension table (#8062)
1 parent 058f023 commit 6d464f5

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

ydb/library/yql/core/pg_ext/yql_pg_ext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void PgExtensionsFromProto(const NYql::NProto::TPgExtensions& proto,
1616
desc.LibraryPath = e.GetLibraryPath();
1717
desc.TypesOnly = e.GetTypesOnly();
1818
desc.LibraryMD5 = e.GetLibraryMD5();
19+
desc.Version = e.GetVersion();
1920
extensions.emplace_back(desc);
2021
}
2122
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ struct TExtensionDesc {
395395
TString LibraryPath; // file path
396396
bool TypesOnly = false; // Can't be loaded if true
397397
TString LibraryMD5; // optional
398+
TString Version; // version of extension
398399
};
399400

400401
class IExtensionSqlBuilder {

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,17 @@ class TPgTableContent : public TMutableComputationNode<TPgTableContent> {
542542
};
543543

544544
ApplyFillers(AllPgLanguageFillers, Y_ARRAY_SIZE(AllPgLanguageFillers), PgLanguageFillers_);
545+
} else if (Table_ == "pg_extension") {
546+
static const std::pair<const char*, TPgExtensionFiller> AllPgExtensionFillers[] = {
547+
{"oid", [](ui32 oid,const NPg::TExtensionDesc& desc) { return ScalarDatumToPod(ObjectIdGetDatum(oid)); }},
548+
{"extname", [](ui32,const NPg::TExtensionDesc& desc) { return PointerDatumToPod((Datum)MakeFixedString(desc.Name, NAMEDATALEN)); }},
549+
{"extowner", [](ui32,const NPg::TExtensionDesc&) { return ScalarDatumToPod(ObjectIdGetDatum(1)); }},
550+
{"extnamespace", [](ui32,const NPg::TExtensionDesc&) { return ScalarDatumToPod(ObjectIdGetDatum(PG_CATALOG_NAMESPACE)); }},
551+
{"extversion", [](ui32,const NPg::TExtensionDesc& desc) { return PointerDatumToPod((Datum)MakeVar(desc.Version)); }},
552+
{"extrelocatable", [](ui32,const NPg::TExtensionDesc&) { return ScalarDatumToPod(BoolGetDatum(false)); }},
553+
};
554+
555+
ApplyFillers(AllPgExtensionFillers, Y_ARRAY_SIZE(AllPgExtensionFillers), PgExtensionFillers_);
545556
}
546557
} else {
547558
if (Table_ == "tables") {
@@ -927,6 +938,19 @@ class TPgTableContent : public TMutableComputationNode<TPgTableContent> {
927938
}
928939
}
929940

941+
sysFiller.Fill(items);
942+
rows.emplace_back(row);
943+
});
944+
} else if (Table_ == "pg_extension") {
945+
NPg::EnumExtensions([&](ui32 oid, const NPg::TExtensionDesc& desc) {
946+
NUdf::TUnboxedValue* items;
947+
auto row = compCtx.HolderFactory.CreateDirectArrayHolder(PgExtensionFillers_.size(), items);
948+
for (ui32 i = 0; i < PgExtensionFillers_.size(); ++i) {
949+
if (PgExtensionFillers_[i]) {
950+
items[i] = PgExtensionFillers_[i](oid, desc);
951+
}
952+
}
953+
930954
sysFiller.Fill(items);
931955
rows.emplace_back(row);
932956
});
@@ -1026,6 +1050,9 @@ class TPgTableContent : public TMutableComputationNode<TPgTableContent> {
10261050

10271051
using TPgOperFiller = NUdf::TUnboxedValuePod(*)(const NPg::TOperDesc&);
10281052
TVector<TPgOperFiller> PgOperFillers_;
1053+
1054+
using TPgExtensionFiller = NUdf::TUnboxedValuePod(*)(ui32,const NPg::TExtensionDesc&);
1055+
TVector<TPgExtensionFiller> PgExtensionFillers_;
10291056
};
10301057

10311058
class TFunctionCallInfo {

ydb/library/yql/protos/pg_ext.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ message TPgExtension {
88
optional string LibraryPath = 4;
99
optional bool TypesOnly = 5;
1010
optional string LibraryMD5 = 6;
11+
optional string Version = 7;
1112
}
1213

1314
message TPgExtensions {

ydb/library/yql/tools/yqlrun/pg_ext.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ Extension {
44
SqlPath: "../../../../../yql/pg_ext/postgis/libs/postgis/postgis/postgis.sql"
55
SqlPath: "../../../../../yql/pg_ext/postgis/libs/postgis/spatial_ref_sys.sql"
66
LibraryPath: "../../../../../yql/pg_ext/postgis/libs/postgis/libpostgis.so"
7+
Version: "3.4.3dev"
78
}
89

0 commit comments

Comments
 (0)