Skip to main content

Crate darwen

Crate darwen 

Source
Expand description

Darwen is an in-memory engine for relational algebra.

The project is inspired by The Third Manifesto by Date, Codd, and Darwen, and focuses on a compact in-memory model for experimenting with relational operators.

§Example

use darwen::{
    heading,
    tuple,
    prelude::{
        AttributeName, HeadingBuilder, Predicate, RelationBuilder, Scalar,
        ScalarType, TupleBuilder,
    },
};

let users = RelationBuilder::new()
    .with_heading(heading!(name = ScalarType::String, age = ScalarType::Integer)?)
    .with_body(vec![
        tuple!(name = "Monica", age = 18)?,
        tuple!(name = "Erica", age = 19)?,
        tuple!(name = "Rita", age = 20)?,
        tuple!(name = "Tina", age = 21)?,
        tuple!(name = "Sandra", age = 22)?,
        tuple!(name = "Mary", age = 23)?,
        tuple!(name = "Jessica", age = 18)?,
    ])
    .build()?;

let adults = users.restrict(&Predicate::gt(
    AttributeName::from("age"),
    Scalar::Integer(20),
))?;

let expected = RelationBuilder::new()
    .with_heading(heading!(name = ScalarType::String, age = ScalarType::Integer)?)
    .with_body(vec![
        tuple!(name = "Tina", age = 21)?,
        tuple!(name = "Sandra", age = 22)?,
        tuple!(name = "Mary", age = 23)?,
    ])
    .build()?;

assert_eq!(adults, expected);

§Predicates

Darwen supports six predicate forms:

§Operators

§Restrict

Relation::restrict implements selection (σ) and returns only tuples that satisfy a Predicate.

§Project

Relation::project implements projection (π) and keeps only the requested attributes.

§Rename

Relation::rename implements renaming (ρ) and changes attribute names according to a mapping.

§Union

Relation::union implements union () for relations with identical headings.

§Difference

Relation::difference implements difference () for relations with identical headings.

§Product

Relation::product implements Cartesian product (×) for relations with disjoint headings.

§Join

Relation::join implements natural join () on shared attributes.

§Intersect

Relation::intersect implements intersection () for relations with identical headings.

§Divide

Relation::divide implements relational division (÷).

Modules§

prelude
Convenient re-exports for the public relational algebra API.

Macros§

heading
Builds a Heading from name = type pairs.
tuple
Builds a Tuple from name = value pairs.

Structs§

AttributeName
The name of an attribute in a heading or tuple.
Heading
Defines the schema of a relation as a set of named attributes and types.
HeadingBuilder
Builds a Heading attribute by attribute.
Relation
Represents a relation with a heading and a set of tuples.
RelationBuilder
Builds a Relation from a heading and a body of tuples.
Tuple
Represents one tuple in a relation body.
TupleBuilder
Builds a Tuple value by adding attributes one by one.

Enums§

Error
Errors returned by relation construction and relational algebra operations.
Expression
Describes a value used during predicate evaluation.
Predicate
Represents a boolean condition evaluated against a tuple.
Scalar
Stores a typed scalar value used in tuples and predicates.
ScalarType
Enumerates the scalar types supported by the engine.