MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / copy_from_inner

Method copy_from_inner

src/pgwire/src/protocol.rs:2787–3079  ·  view source on GitHub ↗
(
        &mut self,
        target_id: CatalogItemId,
        target_name: String,
        columns: Vec<ColumnIndex>,
        params: CopyFormatParams<'static>,
        row_desc: RelationDesc,
      

Source from the content-addressed store, hash-verified

2785 }
2786
2787 async fn copy_from_inner(
2788 &mut self,
2789 target_id: CatalogItemId,
2790 target_name: String,
2791 columns: Vec<ColumnIndex>,
2792 params: CopyFormatParams<'static>,
2793 row_desc: RelationDesc,
2794 ctx_extra: &mut ExecuteContextGuard,
2795 ) -> Result<State, io::Error> {
2796 let typ = row_desc.typ();
2797 let column_formats = vec![Format::Text; typ.column_types.len()];
2798 self.send(BackendMessage::CopyInResponse {
2799 overall_format: Format::Text,
2800 column_formats,
2801 })
2802 .await?;
2803 self.conn.flush().await?;
2804
2805 // Set up the parallel streaming batch builders in the coordinator.
2806 let writer = match self
2807 .adapter_client
2808 .start_copy_from_stdin(
2809 target_id,
2810 target_name.clone(),
2811 columns.clone(),
2812 row_desc.clone(),
2813 params.clone(),
2814 )
2815 .await
2816 {
2817 Ok(writer) => writer,
2818 Err(e) => {
2819 // Drain remaining CopyData/CopyDone/CopyFail messages from the
2820 // socket. Since CopyInResponse was already sent, the client may
2821 // have pipelined copy data that we must consume before returning
2822 // the error, otherwise they'd be misinterpreted as top-level
2823 // protocol messages and cause a deadlock.
2824 loop {
2825 match self.conn.recv().await? {
2826 Some(FrontendMessage::CopyData(_)) => {}
2827 Some(FrontendMessage::CopyDone) | Some(FrontendMessage::CopyFail(_)) => {
2828 break;
2829 }
2830 Some(FrontendMessage::Flush) | Some(FrontendMessage::Sync) => {}
2831 Some(_) => break,
2832 None => return Ok(State::Done),
2833 }
2834 }
2835 self.adapter_client.retire_execute(
2836 std::mem::take(ctx_extra),
2837 StatementEndedExecutionReason::Errored {
2838 error: e.to_string(),
2839 },
2840 );
2841 return self
2842 .send_error_and_get_state(e.into_response(Severity::Error))
2843 .await;
2844 }

Callers 1

copy_fromMethod · 0.80

Calls 15

takeFunction · 0.85
errorFunction · 0.85
start_copy_from_stdinMethod · 0.80
retire_executeMethod · 0.80
set_copy_modeMethod · 0.80
get_system_varsMethod · 0.80
scan_new_bytesMethod · 0.80
end_marker_endMethod · 0.80
on_truncateMethod · 0.80
current_row_sizeMethod · 0.80

Tested by

no test coverage detected