Typed Type Exercise in Rust
Build database expression type checker and vectorized runtime executor in type-safe Rust.
This project is highly inspired by @skyzh's type-exercise-in-rust. While adopting his idea in Databend, I also implemented a few features that I think are useful:
-
Type checking. The type checker can catch all type errors in the SQL compilation phase with a set of carefully defined typing rules. The type checker outputs a totally untyped expression that is ready for runtime execution. So this makes the runtime free of any type information.
-
Type-safe downcast. Function authors no longer have to worry about downcasting runtime inputs. Thanks to Rust's type system, so long as your function compiles, the downcast is always successful.
-
All-in-one generic trait. We've only one trait
Type
. All other traits likeArray
,ArrayBuilder
,ArrayRef
and their sophisticated trait bound are all wiped out. -
Enum-dispatched columns. Use enum to exhaustive all column types and scalar types. They should further minimize runtime overhead and mental effort, compared to
dyn
-dispatched strategy.
Snippet of code
Define a fast, type-safe, auto-downcating and vectorized binary function in three lines of code:
let bool_and = Function::new_2_arg::<BooleanType, BooleanType, BooleanType, _>("and", |lhs, rhs| {
vectorize_binary(lhs, rhs, |lhs: &bool, rhs: &bool| *lhs && *rhs)
});
Run
cargo run
Things to do
- Automatcially generate the nullable function.
- Implement arrays.
- Implement unlimited-length tuples.
- Implment generic functions.
- Check ambiguity between function overloads.
- Read material for the project.