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

Function CopyReadAttributesText

src/backend/commands/copyfromparse.c:1305–1545  ·  view source on GitHub ↗

* Parse the current line into separate attributes (fields), * performing de-escaping as needed. * * The input is in line_buf. We use attribute_buf to hold the result * strings. cstate->raw_fields[k] is set to point to the k'th attribute * string, or NULL when the input matches the null marker string. * This array is expanded as necessary. * * (Note that the caller cannot check for nulls

Source from the content-addressed store, hash-verified

1303 * The return value is the number of fields actually read.
1304 */
1305int
1306CopyReadAttributesText(CopyFromState cstate, int stop_processing_at_field)
1307{
1308 char delimc = cstate->opts.delim[0];
1309 char escapec = cstate->opts.escape[0];
1310 bool delim_off = cstate->opts.delim_off;
1311 int fieldno;
1312 char *output_ptr;
1313 char *cur_ptr;
1314 char *line_end_ptr;
1315
1316 /*
1317 * We need a special case for zero-column tables: check that the input
1318 * line is empty, and return.
1319 */
1320 if (cstate->max_fields <= 0)
1321 {
1322 if (cstate->line_buf.len != 0)
1323 ereport(ERROR,
1324 (errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
1325 errmsg("extra data after last expected column")));
1326 return 0;
1327 }
1328
1329 resetStringInfo(&cstate->attribute_buf);
1330
1331 /*
1332 * The de-escaped attributes will certainly not be longer than the input
1333 * data line, so we can just force attribute_buf to be large enough and
1334 * then transfer data without any checks for enough space. We need to do
1335 * it this way because enlarging attribute_buf mid-stream would invalidate
1336 * pointers already stored into cstate->raw_fields[].
1337 */
1338 if (cstate->attribute_buf.maxlen <= cstate->line_buf.len)
1339 enlargeStringInfo(&cstate->attribute_buf, cstate->line_buf.len);
1340 output_ptr = cstate->attribute_buf.data;
1341
1342 /* set pointer variables for loop */
1343 cur_ptr = cstate->line_buf.data + cstate->line_buf.cursor;
1344 line_end_ptr = cstate->line_buf.data + cstate->line_buf.len;
1345
1346 /* Outer loop iterates over fields */
1347 fieldno = 0;
1348 for (;;)
1349 {
1350 bool found_delim = false;
1351 char *start_ptr;
1352 char *end_ptr;
1353 int input_len;
1354 bool saw_non_ascii = false;
1355
1356 /*
1357 * In QD, stop once we have processed the last field we need in the QD.
1358 */
1359 if (fieldno == stop_processing_at_field)
1360 {
1361 cstate->stopped_processing_at_delim = true;
1362 break;

Callers 2

NextCopyFromRawFieldsXFunction · 0.85
NextCopyFromXFunction · 0.85

Calls 7

resetStringInfoFunction · 0.85
enlargeStringInfoFunction · 0.85
GetDecimalFromHexFunction · 0.85
pg_verifymbstrFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
repallocFunction · 0.50

Tested by

no test coverage detected