@@ -1868,7 +1868,10 @@ struct TCatalog : public IExtensionDDLBuilder {
1868
1868
Conversions = ParseConversions (conversionData, ProcByName);
1869
1869
Languages = ParseLanguages (languagesData);
1870
1870
1871
- if (auto exportDir = GetEnv (" YQL_EXPORT_PG_FUNCTIONS_DIR" )) {
1871
+ if (GetEnv (" YQL_ALLOW_ALL_PG_FUNCTIONS" )) {
1872
+ AllowAllFunctions = true ;
1873
+ } else if (auto exportDir = GetEnv (" YQL_EXPORT_PG_FUNCTIONS_DIR" )) {
1874
+ AllowAllFunctions = true ;
1872
1875
ExportFile.ConstructInPlace (MakeTempName (exportDir.c_str (), " procs" ), CreateAlways | RdWr);
1873
1876
for (const auto & a : Aggregations) {
1874
1877
const auto & desc = a.second ;
@@ -1943,6 +1946,67 @@ struct TCatalog : public IExtensionDDLBuilder {
1943
1946
ProcByName[newDesc.Name ].push_back (newDesc.ProcId );
1944
1947
}
1945
1948
1949
+ void PrepareType (ui32 extensionIndex, const TString& name) final {
1950
+ Y_ENSURE (extensionIndex);
1951
+ Y_ENSURE (!TypeByName.contains (name));
1952
+ TTypeDesc newDesc;
1953
+ newDesc.Name = name;
1954
+ newDesc.TypeId = 16000 + Types.size ();
1955
+ newDesc.ExtensionIndex = extensionIndex;
1956
+ newDesc.ArrayTypeId = newDesc.TypeId + 1 ;
1957
+ newDesc.Category = ' U' ;
1958
+ Types[newDesc.TypeId ] = newDesc;
1959
+ TypeByName[newDesc.Name ] = newDesc.TypeId ;
1960
+ TTypeDesc newArrayDesc = newDesc;
1961
+ newArrayDesc.TypeId += 1 ;
1962
+ newArrayDesc.Name = " _" + newArrayDesc.Name ;
1963
+ newArrayDesc.ElementTypeId = newDesc.TypeId ;
1964
+ newArrayDesc.ArrayTypeId = newArrayDesc.TypeId ;
1965
+ newArrayDesc.PassByValue = false ;
1966
+ newArrayDesc.TypeLen = -1 ;
1967
+ newArrayDesc.SendFuncId = (*ProcByName.FindPtr (" array_send" ))[0 ];
1968
+ newArrayDesc.ReceiveFuncId = (*ProcByName.FindPtr (" array_recv" ))[0 ];
1969
+ newArrayDesc.InFuncId = (*ProcByName.FindPtr (" array_in" ))[0 ];
1970
+ newArrayDesc.OutFuncId = (*ProcByName.FindPtr (" array_out" ))[0 ];
1971
+ newArrayDesc.Category = ' A' ;
1972
+ Types[newArrayDesc.TypeId ] = newArrayDesc;
1973
+ TypeByName[newArrayDesc.Name ] = newArrayDesc.TypeId ;
1974
+ }
1975
+
1976
+ void UpdateType (const TTypeDesc& desc) final {
1977
+ auto byIdPtr = Types.FindPtr (desc.TypeId );
1978
+ Y_ENSURE (byIdPtr);
1979
+ Y_ENSURE (byIdPtr->Name == desc.Name );
1980
+ Y_ENSURE (byIdPtr->ArrayTypeId == desc.ArrayTypeId );
1981
+ Y_ENSURE (byIdPtr->TypeId == desc.TypeId );
1982
+ Y_ENSURE (byIdPtr->ExtensionIndex == desc.ExtensionIndex );
1983
+ if (desc.InFuncId ) {
1984
+ AllowedProcs.insert (Procs.FindPtr (desc.InFuncId )->Name );
1985
+ }
1986
+
1987
+ if (desc.OutFuncId ) {
1988
+ AllowedProcs.insert (Procs.FindPtr (desc.OutFuncId )->Name );
1989
+ }
1990
+
1991
+ if (desc.SendFuncId ) {
1992
+ AllowedProcs.insert (Procs.FindPtr (desc.SendFuncId )->Name );
1993
+ }
1994
+
1995
+ if (desc.ReceiveFuncId ) {
1996
+ AllowedProcs.insert (Procs.FindPtr (desc.ReceiveFuncId )->Name );
1997
+ }
1998
+
1999
+ if (desc.TypeModInFuncId ) {
2000
+ AllowedProcs.insert (Procs.FindPtr (desc.TypeModInFuncId )->Name );
2001
+ }
2002
+
2003
+ if (desc.TypeModOutFuncId ) {
2004
+ AllowedProcs.insert (Procs.FindPtr (desc.TypeModOutFuncId )->Name );
2005
+ }
2006
+
2007
+ *byIdPtr = desc;
2008
+ }
2009
+
1946
2010
static const TCatalog& Instance () {
1947
2011
return *Singleton<TCatalog>();
1948
2012
}
@@ -1981,6 +2045,7 @@ struct TCatalog : public IExtensionDDLBuilder {
1981
2045
THashMap<TTableInfoKey, TVector<TColumnInfo>> StaticColumns;
1982
2046
1983
2047
mutable TMaybe<TFile> ExportFile;
2048
+ bool AllowAllFunctions = false ;
1984
2049
TMutex ExportGuard;
1985
2050
1986
2051
THashSet<TString> AllowedProcs;
@@ -1998,7 +2063,7 @@ const TProcDesc& LookupProc(ui32 procId, const TVector<ui32>& argTypeIds) {
1998
2063
throw yexception () << " No such proc: " << procId;
1999
2064
}
2000
2065
2001
- if (!catalog.ExportFile && !catalog.AllowedProcs .contains (procPtr->Name )) {
2066
+ if (!catalog.AllowAllFunctions && !catalog.AllowedProcs .contains (procPtr->Name )) {
2002
2067
throw yexception () << " No access to proc: " << procPtr->Name ;
2003
2068
}
2004
2069
@@ -2022,7 +2087,7 @@ const TProcDesc& LookupProc(const TString& name, const TVector<ui32>& argTypeIds
2022
2087
for (const auto & id : *procIdPtr) {
2023
2088
const auto & d = catalog.Procs .FindPtr (id);
2024
2089
Y_ENSURE (d);
2025
- if (!catalog.ExportFile && !catalog.AllowedProcs .contains (d->Name )) {
2090
+ if (!catalog.AllowAllFunctions && !catalog.AllowedProcs .contains (d->Name )) {
2026
2091
throw yexception () << " No access to proc: " << d->Name ;
2027
2092
}
2028
2093
@@ -2045,7 +2110,7 @@ const TProcDesc& LookupProc(ui32 procId) {
2045
2110
throw yexception () << " No such proc: " << procId;
2046
2111
}
2047
2112
2048
- if (!catalog.ExportFile && !catalog.AllowedProcs .contains (procPtr->Name )) {
2113
+ if (!catalog.AllowAllFunctions && !catalog.AllowedProcs .contains (procPtr->Name )) {
2049
2114
throw yexception () << " No access to proc: " << procPtr->Name ;
2050
2115
}
2051
2116
@@ -2056,7 +2121,7 @@ const TProcDesc& LookupProc(ui32 procId) {
2056
2121
void EnumProc (std::function<void (ui32, const TProcDesc&)> f) {
2057
2122
const auto & catalog = TCatalog::Instance ();
2058
2123
for (const auto & x : catalog.Procs ) {
2059
- if (catalog.ExportFile || catalog.AllowedProcs .contains (x.second .Name )) {
2124
+ if (catalog.AllowAllFunctions || catalog.AllowedProcs .contains (x.second .Name )) {
2060
2125
f (x.first , x.second );
2061
2126
}
2062
2127
}
@@ -2673,7 +2738,7 @@ std::variant<const TProcDesc*, const TTypeDesc*> LookupProcWithCasts(const TStri
2673
2738
const auto & d = catalog.Procs .FindPtr (id);
2674
2739
Y_ENSURE (d);
2675
2740
2676
- if (!catalog.ExportFile && !catalog.AllowedProcs .contains (d->Name )) {
2741
+ if (!catalog.AllowAllFunctions && !catalog.AllowedProcs .contains (d->Name )) {
2677
2742
throw yexception () << " No access to proc: " << d->Name ;
2678
2743
}
2679
2744
@@ -3257,16 +3322,18 @@ const TTableInfo& LookupStaticTable(const TTableInfoKey& tableKey) {
3257
3322
return *tablePtr;
3258
3323
}
3259
3324
3260
- bool IsExportFunctionsEnabled () {
3325
+ bool AreAllFunctionsAllowed () {
3261
3326
const auto & catalog = TCatalog::Instance ();
3262
- return catalog.ExportFile . Defined () ;
3327
+ return catalog.AllowAllFunctions ;
3263
3328
}
3264
3329
3265
3330
void RegisterExtensions (const TVector<TExtensionDesc>& extensions, bool typesOnly,
3266
3331
IExtensionDDLParser& parser, IExtensionLoader* loader) {
3267
3332
auto & catalog = TCatalog::MutableInstance ();
3268
3333
with_lock (catalog.ExtensionsGuard ) {
3269
3334
Y_ENSURE (!catalog.ExtensionsInit );
3335
+ auto savedAllowAllFunctions = catalog.AllowAllFunctions ;
3336
+ catalog.AllowAllFunctions = true ;
3270
3337
for (ui32 i = 0 ; i < extensions.size (); ++i) {
3271
3338
auto e = extensions[i];
3272
3339
e.TypesOnly = e.TypesOnly && typesOnly;
@@ -3284,12 +3351,13 @@ void RegisterExtensions(const TVector<TExtensionDesc>& extensions, bool typesOnl
3284
3351
3285
3352
catalog.Extensions .push_back (e);
3286
3353
TString sql = TFileInput (e.DDLPath ).ReadAll ();;
3287
- parser.Parse (sql, catalog);
3354
+ parser.Parse (i + 1 , sql, catalog);
3288
3355
if (loader && !e.TypesOnly ) {
3289
3356
loader->Load (i + 1 , e.Name , e.LibraryPath );
3290
3357
}
3291
3358
}
3292
3359
3360
+ catalog.AllowAllFunctions = savedAllowAllFunctions;
3293
3361
catalog.ExtensionsInit = true ;
3294
3362
}
3295
3363
}
0 commit comments