Skip to main content

JobReader

Struct JobReader 

Source
pub struct JobReader<R> { /* private fields */ }
Expand description

Reads a YTsaurus job’s input stream incrementally.

§Example

use ytsaurus_job::{Event, JobReader};

let mut reader = JobReader::from_stdin();
while let Some(event) = reader.next_event()? {
    match event {
        Event::Row(row) => {
            let _bytes = row.raw();
        }
        Event::KeySwitch => {}
    }
}

Implementations§

Source§

impl JobReader<Stdin>

Source

pub fn from_stdin() -> Self

Reads binary YSON from fd 0, which is where YTsaurus puts a job’s input.

Use JobReader::text instead if the operation was configured with <format=text>yson.

Source§

impl<R: Read> JobReader<R>

Source

pub fn binary(input: R) -> Self

Reads binary YSON — the format jobs normally use.

Source

pub fn text(input: R) -> Self

Reads text YSON, which is useful for fixtures and debugging.

Source

pub fn with_format(input: R, format: YsonFormat) -> Self

Reads YSON in an explicit format.

Source

pub fn with_buffer_size(self, bytes: usize) -> Self

Sets the read buffer size. Records larger than this grow the buffer.

Source

pub fn with_max_record_bytes(self, bytes: usize) -> Self

Sets the ceiling on a single record.

The buffer grows on demand up to this limit; beyond it the job fails with JobError::RecordTooLarge rather than trying to allocate whatever a corrupt length prefix asked for.

Source

pub fn next_event(&mut self) -> Result<Option<Event<'_>>>

Returns the next event, or None at end of stream.

The returned Event borrows the reader’s buffer, so it must be dropped before the next call — the compiler enforces this.

§Errors

Returns JobError if the stream cannot be read or does not parse.

Source

pub fn groups(&mut self) -> Groups<'_, R>

Splits the stream into reduce groups on key_switch boundaries.

Requires control_attributes.enable_key_switch on the operation; without it the whole input is a single group.

§Example
let mut reader = JobReader::from_stdin();
let mut groups = reader.groups();
while let Some(mut group) = groups.next_group()? {
    while let Some(row) = group.next_row()? {
        let _ = row.raw();
    }
}
Source

pub fn groups_by<I>(&mut self, columns: I) -> Groups<'_, R>
where I: IntoIterator, I::Item: AsRef<str>,

Like JobReader::groups, but decodes the reduce key for each group.

Pass the same columns the operation was given as reduce_by. Each Group then answers Group::key without the caller having to parse its first row and copy the key out.

YTsaurus does not transmit the key: key_switch carries no payload, and the key lives in the rows. So this reads it from the group’s first row — the same work a job would do by hand, done once and in one place.

§Example
let mut reader = JobReader::from_stdin();
let mut groups = reader.groups_by(["user_id"]);
while let Some(mut group) = groups.next_group()? {
    let user = group.key().bytes("user_id").unwrap_or_default().to_vec();
    while let Some(row) = group.next_row()? {
        let _ = (&user, row.raw());
    }
}

Trait Implementations§

Source§

impl<R: Debug> Debug for JobReader<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> Freeze for JobReader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for JobReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for JobReader<R>
where R: Send,

§

impl<R> Sync for JobReader<R>
where R: Sync,

§

impl<R> Unpin for JobReader<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for JobReader<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for JobReader<R>
where R: UnwindSafe,

Blanket Implementations§

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.