Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

typed-type-exercise-in-rust

> 编程语言
Open source

Build database expression type checker and vectorized runtime executor in type-safe Rust

100 stars0 likes0 views
WebsiteGitHub

About

Build database expression type checker and vectorized runtime executor in type-safe Rust

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:

  1. 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.

  2. 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.

  3. 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.

  4. Generic types. Use generic in the function signature to reduce the number of hand-written overloads. For example, you can express get(arr: Array, idx: i64) -> T0 in the type system.

Snippet of code

Define a fast, type-safe, auto-downcating and vectorized binary function in several lines of code:

rust
registry.register_2_arg::(
    "and",
    FunctionProperty::default(),
    |lhs, rhs| lhs && rhs,
);

Define a generic function get which returns an item of an array by the index:

rust
registry.register_with_writer_2_arg::>, Int16Type, GenericType, _>(
    "get",
    FunctionProperty::default(),
    |array, idx, output| output.push(array.index(idx as usize)),
);

Run

cargo run

Things to do

  • Automatcially generate the nullable function.
  • Automatcially generate the Null function.
  • Automatcially dispatch arithmetic types.
  • Implement arrays.
  • Implement column builder.
  • Implement unlimited-length tuples.
  • Implment generic functions.
  • Implment functions properties.
  • Implment variadic functions.
  • Implment sparse columns (some of the rows in a column are hidden).
  • Check ambiguity between function overloads.
  • Read material for the project.

Reading material

  • Databend/RFC: Formal Type System
  • type-exercise-in-rust
  • 数据库表达式执行的黑魔法:用 Rust 做类型体操
  • Book: Types and Progaming Language
  • Paper: Type inference with simple subtypes

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rust

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言