Skip to main content

TablePath

Struct TablePath 

Source
pub struct TablePath { /* private fields */ }
Expand description

A table to read from or write to, and which part of it.

Built from a &str wherever a plain path will do:

let replace = TablePath::from("//tmp/log");
let add = TablePath::new("//tmp/log").append();
let head = TablePath::new("//tmp/log").columns(["host", "status"]).range(0..100);

Append is a write-side attribute; columns and ranges are read-side ones, the same split the C++ TRichYPath and the Go ypath.Rich carry. The write methods refuse a path with a read selection rather than sending it — the cluster ignores a selection on a write and replaces the whole table with a 200, which is silent data loss. Measured on a local cluster, in both spellings: write_table_rows("//tmp/t[#0:#2]", rows) replaced everything and reported success, and a write_table whose path carried <ranges=[{lower_limit={row_index=0};upper_limit={row_index=2}}]> as an attribute did exactly the same — 200, three rows replaced by one.

The path string is never parsed. Rich YPath syntax spelled into it — <append=%true>//tmp/t, //tmp/t[#0:#2], //tmp/t{a,b} — goes to the cluster verbatim on a read, where the cluster honours it, and is refused on a write, where the cluster would not: the attribute form of a selection is ignored there, and this type exists so that cannot happen by accident.

Implementations§

Source§

impl TablePath

Source

pub fn new(path: impl Into<String>) -> Self

A path that names the whole table: a write replaces its contents, a read returns every row of every column — the defaults everywhere in YTsaurus.

Source

pub fn append(self) -> Self

Adds rows to the table instead of replacing it.

The table has to exist: appending to a path that does not is refused with Error getting basic attributes of user objects, which is the cluster’s way of saying there was nothing to append to.

A sorted table stays sorted, and the cluster checks. Rows appended after a larger key are refused — Sort order violation: [0#9] > [0#1] — so an append to a sorted table is a continuation of it rather than an addition to it.

Source

pub fn columns( self, columns: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Reads only the named columns.

Three columns out of a forty-column table cost three columns’ worth of wire and decode, which is what makes a laptop-side read of a wide table reasonable. The names travel as the columns attribute on the path, which the rich YPath reference says is “recognized by the table data read command (read_table)” — and by read commands only, which is why the write methods refuse a path carrying one rather than letting the cluster ignore it.

A column the table does not have is not an error — measured on a local cluster: columns(["a", "nosuch"]) against a table with no nosuch answered 200, every row carrying only a. Rows simply come back without the key, exactly as they do for a row with no value in a named column, so a typo here reads clean and decodes short. A struct decoded from such a read fails loudly on the missing field, which is where the typo surfaces; a map decodes to fewer keys and does not.

The empty selection is that same shape taken to its end, and it is sent. Measured: <columns=[]> answers 200 with one empty map per row, and it composes with a range — <columns=[];ranges=[{lower_limit={row_index=0};upper_limit={row_index=2}}]> came back as two empty maps, and the same range spelled with key bounds came back as three. That is how many rows a range holds, or whether a key range holds any, with no column bytes on the wire — a question Client::row_count cannot answer, since it reads the @row_count attribute and so speaks only for a whole static table. It decodes to a map with no keys and to a struct missing every field, so name the columns when the rows are what is wanted.

Calling this again replaces the selection rather than adding to it.

Source

pub fn range(self, range: impl Into<RowRange>) -> Self

Reads only the rows a RowRange selects. May be called several times: the ranges are read one after another, in the order given — the documented meaning of the ranges attribute.

Plain Rust ranges convert, so row windows read as they would on a slice:

let first_two = TablePath::new("//tmp/t").range(0..2);
let from_key = TablePath::new("//tmp/t")
    .range(RowRange::keys(Key::from("alice")..Key::from("bob")));
Source

pub fn is_append(&self) -> bool

Whether TablePath::append was called on this path.

Not “whether the cluster will append”: the cluster parses attributes out of the path string too, so a path built from the text <append=%true>//tmp/t appends while this answers false. Spelling the attribute into the string is not a supported way to ask for it, and a write to such a string is refused outright — see TablePath.

Source

pub fn selected_columns(&self) -> Option<&[String]>

The columns TablePath::columns selected, if any.

Source

pub fn selected_ranges(&self) -> &[RowRange]

The ranges TablePath::range added, in the order they will be read.

Source

pub fn as_str(&self) -> &str

The path itself, without the attributes.

Trait Implementations§

Source§

impl Clone for TablePath

Source§

fn clone(&self) -> TablePath

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TablePath

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for TablePath

Source§

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

Prints the path the way the cluster spells it — <append=%true;columns=[a]>//tmp/out — so an error naming the path says which rows and columns were in play, not only which table.

Source§

impl From<&&str> for TablePath

Source§

fn from(path: &&str) -> Self

Converts to this type from the input type.
Source§

impl From<&String> for TablePath

Source§

fn from(path: &String) -> Self

Converts to this type from the input type.
Source§

impl From<&TablePath> for TablePath

Source§

fn from(path: &TablePath) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for TablePath

Source§

fn from(path: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Cow<'_, str>> for TablePath

Source§

fn from(path: Cow<'_, str>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for TablePath

Source§

fn from(path: String) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for TablePath

Source§

fn eq(&self, other: &TablePath) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TablePath

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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