packages

table::ops

On this page

Relational algebra as operators: the join symbols of Codd's algebra (⋈ ⟕ ⟖ ⟗ ⋉ ▷), the set operators (∪ ∩ from core, ∖ here) and indexing by column name. The joins bind like *, the set operators like + / -, so a ⋈ b ∪ c is (a ⋈ b) ∪ c.

Operators cannot throw, so where Table::join would throw these panic with the same message; call the methods when the column names come from data.

Structs

KeyedSource

pub struct Keyed

A table with the key columns to join it on: b.on(["id"]).

Trait implementations 1

Traits

JoinSideSource

pub trait JoinSide

The right side of a join operator: a whole table (a natural join on the shared names) or a keyed one.

  • fn side(self, left: Table) -> (Table, List<str>)§

    Source

    The table and the key names, given the left table.

RelationalSource

pub trait Relational<Rhs>

Joins as operators. With a plain table on the right the keys are the shared column names (a natural join); b.on(["k"]) names them.

OperatorJoinMethod
a ⋈ binnera.join(b, ks, How::Inner)
a ⟕ bleft outerHow::Left
a ⟖ bright outerHow::Right
a ⟗ bfull outerHow::Outer
a ⋉ bsemiHow::Semi
a ▷ bantiHow::Anti
nabi
let people = table::table!{ "id": [1, 2, 3], "name": ["ann", "bob", "cy"] };
let orders = table::table!{ "id": [1, 1, 3], "amount": [5.0, 7.0, 2.0] };
assert((people ⋈ orders).nrows() == 3);
assert((people ⟕ orders).nrows() == 4);
assert((people ⋉ orders).nrows() == 2);
assert((people ▷ orders).row(0).str("name") == "bob");
  • fn inner_join(self, rhs: Rhs) -> Table§

    Source

    self ⋈ rhs: inner join.

  • fn left_join(self, rhs: Rhs) -> Table§

    Source

    self ⟕ rhs: left outer join.

  • fn right_join(self, rhs: Rhs) -> Table§

    Source

    self ⟖ rhs: right outer join.

  • fn outer_join(self, rhs: Rhs) -> Table§

    Source

    self ⟗ rhs: full outer join.

  • fn semi_join(self, rhs: Rhs) -> Table§

    Source

    self ⋉ rhs: left semi-join, rows of self with a match.

  • fn anti_join(self, rhs: Rhs) -> Table§

    Source

    self ▷ rhs: anti-join, rows of self with no match.

DifferenceSource

pub trait Difference<Rhs = Self>

∖: set difference.

  • type Output§

    Source
  • fn difference(self, rhs: Rhs) -> Output§

    Source

    self ∖ rhs.

Implementations

impl Table

  • pub fn on(self, names: List<str>) -> Keyed§

    Source

    This table keyed by names, the right side of a join operator.

    nabi
    let a = table::table!{ "id": [1, 2], "x": [1.0, 2.0] };
    let b = table::table!{ "id": [2, 3], "y": ["b", "c"] };
    let j = a ⋈ b.on(["id"]);
    assert(j.nrows() == 1 && j.row(0).str("y") == "b");
    
  • pub fn common_names(self, o: Table) -> List<str>§

    Source

    The names this table shares with o: the keys of a natural join.

Trait implementations 8