MCPcopy Create free account
hub / github.com/apecloud/myduckserver / handleCopyDone

Method handleCopyDone

pgserver/connection_handler.go:882–918  ·  view source on GitHub ↗

handleCopyDone handles a COPY DONE message by finalizing the in-progress COPY DATA operation and committing the loaded table data. The |stop| response parameter is true if the connection handler should shut down the connection, |endOfMessages| is true if no more COPY DATA messages are expected, and

(_ *pgproto3.CopyDone)

Source from the content-addressed store, hash-verified

880 return false, false, fmt.Errorf("no COPY FROM STDIN node found")
881 }
882 table := h.copyFromStdinState.targetTable
883 if table == nil {
884 return false, true, fmt.Errorf("no target table found")
885 }
886 rawOptions := h.copyFromStdinState.rawOptions
887
888 switch copyFrom.Options.CopyFormat {
889 case CopyFormatArrow:
890 dataLoader, err = NewArrowDataLoader(
891 sqlCtx, h.duckHandler,
892 copyFrom.Table.Schema(), table, copyFrom.Columns,
893 rawOptions,
894 )
895 case tree.CopyFormatText:
896 // Remove `\.` from the end of the message data, if it exists
897 if bytes.HasSuffix(message.Data, []byte{'\\', '.', '\n'}) {
898 message.Data = message.Data[:len(message.Data)-3]
899 }
900 if bytes.HasSuffix(message.Data, []byte{'\\', '.', '\r', '\n'}) {
901 message.Data = message.Data[:len(message.Data)-4]
902 }
903 fallthrough
904 case tree.CopyFormatCSV:
905 dataLoader, err = NewCsvDataLoader(
906 sqlCtx, h.duckHandler,
907 copyFrom.Table.Schema(), table, copyFrom.Columns,
908 &copyFrom.Options,
909 rawOptions,
910 )
911 case tree.CopyFormatBinary:
912 err = fmt.Errorf("BINARY format is not supported for COPY FROM")
913 default:
914 err = fmt.Errorf("unknown format specified for COPY FROM: %v", copyFrom.Options.CopyFormat)
915 }
916
917 if err != nil {
918 return false, false, err
919 }
920
921 ready := dataLoader.Start()

Callers 1

handleMessageMethod · 0.95

Calls 3

sendMethod · 0.95
NewContextMethod · 0.65
FinishMethod · 0.65

Tested by

no test coverage detected