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>
impl JobReader<Stdin>
Sourcepub fn from_stdin() -> Self
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>
impl<R: Read> JobReader<R>
Sourcepub fn with_format(input: R, format: YsonFormat) -> Self
pub fn with_format(input: R, format: YsonFormat) -> Self
Reads YSON in an explicit format.
Sourcepub fn with_buffer_size(self, bytes: usize) -> Self
pub fn with_buffer_size(self, bytes: usize) -> Self
Sets the read buffer size. Records larger than this grow the buffer.
Sourcepub fn with_max_record_bytes(self, bytes: usize) -> Self
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.
Sourcepub fn next_event(&mut self) -> Result<Option<Event<'_>>>
pub fn next_event(&mut self) -> Result<Option<Event<'_>>>
Sourcepub fn groups(&mut self) -> Groups<'_, R>
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();
}
}Sourcepub fn groups_by<I>(&mut self, columns: I) -> Groups<'_, R>
pub fn groups_by<I>(&mut self, columns: I) -> Groups<'_, R>
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());
}
}