use crate::stream_body::{ReqwestStreamBody, StreamBodyRequest};
use arrow::array::RecordBatch;
use arrow::datatypes::SchemaRef;
use futures::Stream;
use http_streams_core::ArrowRecordBatchIpcStreamFormat;
pub trait ArrowIpcStreamRequest {
fn arrow_ipc_stream_body<S>(self, schema: SchemaRef, stream: S) -> reqwest::RequestBuilder
where
S: Stream<Item = RecordBatch> + Send + 'static;
fn try_arrow_ipc_stream_body<S, E>(
self,
schema: SchemaRef,
stream: S,
) -> reqwest::RequestBuilder
where
S: Stream<Item = Result<RecordBatch, E>> + Send + 'static,
E: Into<Box<dyn std::error::Error + Send + Sync>> + Send + 'static;
}
impl ArrowIpcStreamRequest for reqwest::RequestBuilder {
fn arrow_ipc_stream_body<S>(self, schema: SchemaRef, stream: S) -> reqwest::RequestBuilder
where
S: Stream<Item = RecordBatch> + Send + 'static,
{
self.stream_body(ReqwestStreamBody::new(
ArrowRecordBatchIpcStreamFormat::new(schema),
stream,
))
}
fn try_arrow_ipc_stream_body<S, E>(
self,
schema: SchemaRef,
stream: S,
) -> reqwest::RequestBuilder
where
S: Stream<Item = Result<RecordBatch, E>> + Send + 'static,
E: Into<Box<dyn std::error::Error + Send + Sync>> + Send + 'static,
{
self.stream_body(ReqwestStreamBody::try_new(
ArrowRecordBatchIpcStreamFormat::new(schema),
stream,
))
}
}