MCPcopy Create free account
hub / github.com/apache/cloudberry / LookupExtProtocolFunction

Function LookupExtProtocolFunction

src/backend/catalog/pg_extprotocol.c:276–336  ·  view source on GitHub ↗

* Finds an external protocol by passed in protocol name. * Errors if no such protocol exist, or if no function to * execute this protocol exists (for read or write separately). * * Returns the protocol function to use. */

Source from the content-addressed store, hash-verified

274 * Returns the protocol function to use.
275 */
276Oid
277LookupExtProtocolFunction(const char *prot_name,
278 ExtPtcFuncType prot_type,
279 bool error)
280{
281 Relation rel;
282 Oid funcOid = InvalidOid;
283 ScanKeyData skey;
284 SysScanDesc scan;
285 HeapTuple tup;
286 Form_pg_extprotocol extprot;
287
288 rel = table_open(ExtprotocolRelationId, AccessShareLock);
289
290 /*
291 * Check the pg_extprotocol relation to be certain the protocol
292 * is there.
293 */
294 ScanKeyInit(&skey,
295 Anum_pg_extprotocol_ptcname,
296 BTEqualStrategyNumber, F_NAMEEQ,
297 CStringGetDatum(prot_name));
298 scan = systable_beginscan(rel, ExtprotocolPtcnameIndexId, true,
299 NULL, 1, &skey);
300 tup = systable_getnext(scan);
301
302 if (!HeapTupleIsValid(tup))
303 ereport(ERROR,
304 (errcode(ERRCODE_UNDEFINED_OBJECT),
305 errmsg("protocol \"%s\" does not exist",
306 prot_name)));
307
308 extprot = (Form_pg_extprotocol) GETSTRUCT(tup);
309
310 switch (prot_type)
311 {
312 case EXTPTC_FUNC_READER:
313 funcOid = extprot->ptcreadfn;
314 break;
315 case EXTPTC_FUNC_WRITER:
316 funcOid = extprot->ptcwritefn;
317 break;
318 case EXTPTC_FUNC_VALIDATOR:
319 funcOid = extprot->ptcvalidatorfn;
320 break;
321 default:
322 elog(ERROR, "internal error in pg_extprotocol:func_type_to_attnum");
323 break;
324 }
325 systable_endscan(scan);
326 table_close(rel, AccessShareLock);
327
328 if (!OidIsValid(funcOid) && error)
329 ereport(ERROR,
330 (errcode(ERRCODE_UNDEFINED_OBJECT),
331 errmsg("protocol '%s' has no %s function defined",
332 prot_name, func_type_to_name(prot_type))));
333

Callers 2

transformLocationUrisFunction · 0.85
url_custom_fopenFunction · 0.85

Calls 10

table_openFunction · 0.85
ScanKeyInitFunction · 0.85
CStringGetDatumFunction · 0.85
systable_beginscanFunction · 0.85
systable_getnextFunction · 0.85
systable_endscanFunction · 0.85
table_closeFunction · 0.85
func_type_to_nameFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected