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

Function transformFormatOpts

src/backend/commands/exttablecmds.c:651–795  ·  view source on GitHub ↗

* Transform the FORMAT options List into a new List suitable for storing in * pg_foreigntable.ftoptions. */

Source from the content-addressed store, hash-verified

649 * pg_foreigntable.ftoptions.
650 */
651static List *
652transformFormatOpts(char formattype, List *formatOpts, int numcols, bool iswritable)
653{
654 List *cslist = NIL;
655 ListCell *option;
656 ParseState *pstate;
657
658 CopyFormatOptions opts;
659 memset(&opts, 0, sizeof(opts));
660
661 pstate = make_parsestate(NULL);
662 pstate->p_sourcetext = NULL;
663
664 Assert(fmttype_is_custom(formattype) ||
665 fmttype_is_text(formattype) ||
666 fmttype_is_csv(formattype));
667
668 /* Extract options from the statement node tree */
669 if (fmttype_is_text(formattype) || fmttype_is_csv(formattype))
670 {
671 foreach(option, formatOpts)
672 {
673 DefElem *defel = (DefElem *) lfirst(option);
674
675 if (strcmp(defel->defname, "delimiter") == 0 ||
676 strcmp(defel->defname, "null") == 0 ||
677 strcmp(defel->defname, "header") == 0 ||
678 strcmp(defel->defname, "quote") == 0 ||
679 strcmp(defel->defname, "escape") == 0 ||
680 strcmp(defel->defname, "force_not_null") == 0 ||
681 strcmp(defel->defname, "force_quote") == 0 ||
682 strcmp(defel->defname, "fill_missing_fields") == 0 ||
683 strcmp(defel->defname, "newline") == 0)
684 {
685 /* ok */
686 }
687 else if (strcmp(defel->defname, "formatter") == 0)
688 ereport(ERROR,
689 (errcode(ERRCODE_SYNTAX_ERROR),
690 errmsg("formatter option only valid for custom formatters")));
691 else
692 elog(ERROR, "option \"%s\" not recognized",
693 defel->defname);
694 }
695
696 /* If CSV format was chosen, make it visible to ProcessCopyOptions. */
697 if (fmttype_is_csv(formattype))
698 {
699 formatOpts = list_copy(formatOpts);
700 formatOpts = lappend(formatOpts, makeDefElem("format", (Node *) makeString("csv"), -1));
701
702 cslist = lappend(cslist, makeDefElem("format", (Node *) makeString("csv"), -1));
703 }
704 else
705 cslist = lappend(cslist, makeDefElem("format", (Node *) makeString("text"), -1));
706
707 /* verify all user supplied control char combinations are legal */
708 ProcessCopyOptions(pstate,

Callers 1

DefineExternalRelationFunction · 0.85

Calls 10

make_parsestateFunction · 0.85
list_copyFunction · 0.85
lappendFunction · 0.85
makeDefElemFunction · 0.85
makeStringFunction · 0.85
ProcessCopyOptionsFunction · 0.85
list_joinFunction · 0.85
foreachFunction · 0.50
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected