Skip to main content

CsvStreamer

Struct CsvStreamer 

Source
pub(crate) struct CsvStreamer<'a, S: ExportSink + Send> {
    pub(crate) sink: &'a mut S,
    pub(crate) bytes_sent: usize,
    pub(crate) asset: u32,
    pub(crate) start: DateTime<Utc>,
    pub(crate) end: DateTime<Utc>,
    pub(crate) filters: Option<ExportFilters>,
}
Expand description

CSV streamer for direct WebSocket exports.

Builds the CSV on a CSV thread (spawn_csv) and hands it to an ExportSink in chunks of about Self::CHUNK_SIZE bytes. There is no ack protocol; backpressure comes from awaiting each send on the sink.

Fields§

§sink: &'a mut S

Transport that receives the frames.

§bytes_sent: usize

CSV bytes handed to the sink so far.

§asset: u32

Asset number used to locate the Parquet partitions.

§start: DateTime<Utc>

Inclusive start of the export range.

§end: DateTime<Utc>

Inclusive end of the export range.

§filters: Option<ExportFilters>

Filters asked for; None for a plain export.

Implementations§

Source§

impl<'a, S: ExportSink + Send> CsvStreamer<'a, S>

Source

pub(crate) const CHUNK_SIZE: usize

Buffer size in bytes at which a chunk is sent to the sink (128 KiB).

Source

pub(crate) fn new( sink: &'a mut S, asset: u32, start: DateTime<Utc>, end: DateTime<Utc>, ) -> Self

Creates a direct CSV streamer.

§Arguments
  • sink - Transport that receives the frames.
  • asset - Asset number used to locate the Parquet partitions.
  • start - Inclusive start of the export range.
  • end - Inclusive end of the export range.
Source

pub(crate) fn with_filters(self, filters: Option<ExportFilters>) -> Self

Sets the filters of the export. With Some, the header gets a filtered_value column and every row a value for it.

Source

pub(crate) async fn stream_channels( &mut self, parquet_root: &Path, channels: &[u8], ) -> Result<Vec<u8>>

Streams all requested channels, one after another, in the given order.

The CSV is built by spawn_csv and every chunk is sent as soon as it is ready.

§Arguments
  • parquet_root - Root of the Parquet archive.
  • channels - Channels to export.
§Returns

The channels that produced no rows in the range, in request order.

§Errors

Returns an error if the sink fails to send, or the first channel error from spawn_csv, prefixed with channel NN:, after the chunks completed before it.

Source

pub(crate) async fn finish(self, missing_channels: Vec<u8>) -> Result<()>

Sends the summary and completion frames.

Call after Self::stream_channels, which sends every chunk. The missing channels are sorted and deduplicated.

§Arguments
  • missing_channels - Channels that produced no rows.
§Errors

Returns an error if the sink fails to send.

Auto Trait Implementations§

§

impl<'a, S> !UnwindSafe for CsvStreamer<'a, S>

§

impl<'a, S> Freeze for CsvStreamer<'a, S>

§

impl<'a, S> RefUnwindSafe for CsvStreamer<'a, S>
where S: RefUnwindSafe,

§

impl<'a, S> Send for CsvStreamer<'a, S>

§

impl<'a, S> Sync for CsvStreamer<'a, S>
where S: Sync,

§

impl<'a, S> Unpin for CsvStreamer<'a, S>

§

impl<'a, S> UnsafeUnpin for CsvStreamer<'a, S>

Blanket Implementations§

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more