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

Function CopyLoadInputBuf

src/backend/commands/copyfromparse.c:618–707  ·  view source on GitHub ↗

* CopyLoadInputBuf loads some more data into input_buf * * On return, at least one more input character is loaded into * input_buf, or input_reached_eof is set. * * If INPUT_BUF_BYTES(cstate) > 0, the unprocessed bytes are moved to the start * of the buffer and then we load more data after that. */

Source from the content-addressed store, hash-verified

616 * of the buffer and then we load more data after that.
617 */
618static void
619CopyLoadInputBuf(CopyFromState cstate)
620{
621 int nbytes = INPUT_BUF_BYTES(cstate);
622
623 /*
624 * The caller has updated input_buf_index to indicate how much of the
625 * input has been consumed and isn't needed anymore. If input_buf is the
626 * same physical area as raw_buf, update raw_buf_index accordingly.
627 */
628 if (cstate->raw_buf == cstate->input_buf)
629 {
630 Assert(!cstate->need_transcoding);
631 Assert(cstate->input_buf_index >= cstate->raw_buf_index);
632 cstate->raw_buf_index = cstate->input_buf_index;
633 }
634
635 for (;;)
636 {
637 /* If we now have some unconverted data, try to convert it */
638sreh_conversion_error:
639 CopyConvertBuf(cstate);
640
641 /* If we now have some more input bytes ready, return them */
642 if (INPUT_BUF_BYTES(cstate) > nbytes)
643 return;
644
645 /*
646 * If we reached an invalid byte sequence, or we're at an incomplete
647 * multi-byte character but there is no more raw input data, report
648 * conversion error.
649 */
650 if (cstate->input_reached_error)
651 {
652 /* so far, we only support no transcoding conversion error handling */
653 if (cstate->cdbsreh && !cstate->need_transcoding)
654 {
655 MemoryContext oldcontext = CurrentMemoryContext;
656 PG_TRY();
657 {
658 CopyConversionError(cstate);
659 }
660 PG_CATCH();
661 {
662 HandleCopyError(cstate);
663 RemoveInvalidDataInBuf(cstate);
664 MemoryContextSwitchTo(oldcontext);
665 }
666 PG_END_TRY();
667 /* clean illegal character do conversion again */
668 goto sreh_conversion_error;
669 }
670 else
671 CopyConversionError(cstate);
672 }
673
674 /* no more input, and everything has been converted */
675 if (cstate->input_reached_eof)

Callers 1

CopyReadLineTextFunction · 0.85

Calls 7

CopyConvertBufFunction · 0.85
CopyConversionErrorFunction · 0.85
HandleCopyErrorFunction · 0.85
RemoveInvalidDataInBufFunction · 0.85
MemoryContextSwitchToFunction · 0.85
CopyLoadRawBufFunction · 0.85
FindEolInUnverifyRawBufFunction · 0.85

Tested by

no test coverage detected