Skip to content

Simple generic relational algebra evaluator built entirely in Rust.

License

Notifications You must be signed in to change notification settings

V-Wong/ra-evaluator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ra-evaluator

A simple type-safe relational algebra evaluator.

Relational algebra provides the theoretical foundation for relational databases and the SQL language. This library provides a means to build expressions in the language of relational algebra and evaluate them to obtain a concrete result.

Features

  • Type safe and generic expressions operating on arbitrary tuples and structs.
  • Highly composable expression building based on the composite design pattern.
  • Recursive evaluation of complex chained expressions.

Future Possible Features

  • Visualization of expression trees.
  • Query rewriting and optimization.

Sample Usage

We can build relational algebra expressions using the ExpressionBuilder struct:

use ra_evaluator::{ExpressionBuilder, Terminal};

let query = ExpressionBuilder::new(Terminal::new(&[(1, "a"), (2, "b"), (3, "c")]))
    .select(|x| x.0 > 1)
    .project(|x| x.1)
    .cartesian_product(&[1, 2], |x, y| (*x, *y))
    .join(&[(1, "Join1"), (2, "Join2")], |x, y| x.1 == y.0, |x, y| (x.0, y.0, y.1))
    .union(&[("d", 3, "Union")])
    .intersect(&[
        ("c", 1, "Join1"),
        ("c", 2, "Join2"),
        ("d", 3, "Union"),
        ("e", 4, "Removed"),
    ]);
 
// Results in ``[("c", 1, "Join1"), ("c", 2, "Join2"), ("d", 3, "Union")]``
println!("{:?}", query.eval());

About

Simple generic relational algebra evaluator built entirely in Rust.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages