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

Function parseFormatOpts

gpcontrib/gpcloud/src/gpcloud.cpp:127–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125char eolString[EOL_CHARS_MAX_LEN + 1] = "\n"; // LF by default
126
127static void parseFormatOpts(FunctionCallInfo fcinfo) {
128 Relation rel = EXTPROTOCOL_GET_RELATION(fcinfo);
129 ExtTableEntry *exttbl = GetExtTableEntry(rel->rd_id);
130
131 const char fmtcode = exttbl->fmtcode;
132 const List *fmtopts = exttbl->options;
133 char *newline_str = NULL;
134
135 // only TEXT and CSV have detailed options
136 if (fmttype_is_csv(fmtcode) || fmttype_is_text(fmtcode)) {
137 ListCell *option;
138
139 foreach (option, fmtopts) {
140 DefElem *defel = (DefElem *)lfirst(option);
141 if (strcmp(defel->defname, "header") == 0) {
142 hasHeader = defGetBoolean(defel);
143 } else if (strcmp(defel->defname, "newline") == 0) {
144 newline_str = defGetString(defel);
145 }
146 }
147
148 // default end-of-line terminator
149 eolString[0] = '\n';
150 eolString[1] = '\0';
151
152 if (newline_str != NULL) {
153 if (pg_strcasecmp(newline_str, "crlf") == 0) {
154 eolString[0] = '\r';
155 eolString[1] = '\n';
156 eolString[2] = '\0';
157 } else if (pg_strcasecmp(newline_str, "cr") == 0) {
158 eolString[0] = '\r';
159 eolString[1] = '\0';
160 } else if (pg_strcasecmp(newline_str, "lf") == 0) {
161 eolString[0] = '\n';
162 eolString[1] = '\0';
163 } else { // should never come here
164 ereport(ERROR, errmsg("invalid value for NEWLINE (%s), "
165 "valid options are: 'LF', 'CRLF', 'CR'",
166 newline_str));
167 }
168 }
169 }
170}
171
172typedef struct gpcloudResHandle {
173 GPReader *gpreader;

Callers 1

s3_importFunction · 0.85

Calls 3

GetExtTableEntryFunction · 0.85
pg_strcasecmpFunction · 0.85
errmsgFunction · 0.50

Tested by

no test coverage detected