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

Function transformLocationUris

src/backend/commands/exttablecmds.c:340–488  ·  view source on GitHub ↗

* Transform the URI string list into a string. While at it we validate the URI * strings. */

Source from the content-addressed store, hash-verified

338 * strings.
339 */
340static char*
341transformLocationUris(List *locs, bool isweb, bool iswritable)
342{
343 ListCell *cell;
344 StringInfoData buf;
345 UriProtocol first_protocol = URI_FILE; /* initialize to keep gcc
346 * quiet */
347 bool first_uri = true;
348
349#define FDIST_DEF_PORT 8080
350
351 initStringInfo(&buf);
352
353 /* Parser should not let this happen */
354 Assert(locs != NIL);
355
356 /*
357 * iterate through the user supplied URI list from LOCATION clause.
358 */
359 foreach(cell, locs)
360 {
361 Uri *uri;
362 char *uri_str_orig;
363 char *uri_str_final;
364 char *uri_str_escape;
365 Value *v = lfirst(cell);
366
367 /* get the current URI string from the command */
368 uri_str_orig = v->val.str;
369
370 /* parse it to its components */
371 uri = ParseExternalTableUri(uri_str_orig);
372
373 /*
374 * in here edit the uri string if needed
375 */
376
377 /*
378 * no port was specified for gpfdist, gpfdists or hdfs. add the
379 * default
380 */
381 if ((uri->protocol == URI_GPFDIST || uri->protocol == URI_GPFDISTS) && uri->port == -1)
382 {
383 char *at_hostname = (char *) uri_str_orig
384 + strlen(uri->protocol == URI_GPFDIST ? "gpfdist://" : "gpfdists://");
385 char *after_hostname = strchr(at_hostname, '/');
386 int len = after_hostname - at_hostname;
387 char *hostname = pstrdup(at_hostname);
388
389 hostname[len] = '\0';
390
391 /* add the default port number to the uri string */
392 uri_str_final = psprintf("%s%s:%d%s",
393 (uri->protocol == URI_GPFDIST ? PROTOCOL_GPFDIST : PROTOCOL_GPFDISTS),
394 hostname,
395 FDIST_DEF_PORT, after_hostname);
396
397 pfree(hostname);

Callers 1

DefineExternalRelationFunction · 0.85

Calls 14

initStringInfoFunction · 0.85
ParseExternalTableUriFunction · 0.85
psprintfFunction · 0.85
InvokeProtocolValidationFunction · 0.85
escape_uriFunction · 0.85
appendStringInfoFunction · 0.85
FreeExternalTableUriFunction · 0.85
foreachFunction · 0.50
pstrdupFunction · 0.50
pfreeFunction · 0.50
errcodeFunction · 0.50

Tested by

no test coverage detected