(
&mut self,
target_id: CatalogItemId,
target_name: String,
columns: Vec<ColumnIndex>,
params: CopyFormatParams<'static>,
row_desc: RelationDesc,
| 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 | } |
no test coverage detected