Skip to content

Commit

Permalink
Refactor column storage to row storage (#49)
Browse files Browse the repository at this point in the history
* refactor: clear useless code and dependencies

* feat: impl eval_column for tp

* feat: impl storage for tp

* feat: impl dml(insert/values/seq_scan/project) and ddl(create) for tp

* feat: impl dml(filter) for tp

* feat: impl dml(sort) for tp

* feat: impl dml(limit) for tp

* feat: `SeqScan` supports Projection and Limit pushdown

* style: new dql

* feat: impl dql(hash_join) for tp

* feat: impl `on filter` for dql(hash_join)

* feat: impl `repeat join` for dql(hash_join)

* style: remove ap

* perf: use Arc pointers to encapsulate `DataValue` and `ColumnCatalog` to avoid copy loss

* docs: rewrite README.md and fix `hash_join` bug

* style: version reset
  • Loading branch information
KKould authored Aug 22, 2023
1 parent 915f01b commit 512690f
Show file tree
Hide file tree
Showing 109 changed files with 2,091 additions and 4,346 deletions.
17 changes: 2 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,33 @@

[package]
name = "kip-sql"
version = "0.1.0"
version = "0.0.1-alpha.0"
edition = "2021"

[lib]
doctest = false

[dependencies]
log = "^0.4"
sqlparser = "0.34.0"
thiserror = "1"
parking_lot = "0.12.1"
itertools = "0.10"
sqllogictest = "0.11.1"
rust_decimal = "1"
paste = "1.0.11"
tracing = "0.1.37"
pin-project = "1.1.0"
chrono = "0.4.26"
roaring = "0.10.1"
educe = "0.4"
num-traits = "0.2"
num-derive = "0.3"
anyhow = "1.0.71"
tokio = { version = "1.28.2", features = ["full"] }
tokio-process = "0.2.5"
serde = { version = "1", features = ["derive", "rc"] }
serde_json = "1"
async-trait = "0.1.68"
integer-encoding = "3.0.4"
arrow = { version = "28", features = ["prettyprint", "simd"] }
strum_macros = "0.24"
ordered-float = "3.0"
petgraph = "0.6.3"
futures-async-stream = "0.2.6"
async-channel = "1.8.0"
async-backtrace = "0.2.6"
futures = "0.3.25"
futures-lite = "1.12.0"
ahash = "0.8.3"
lazy_static = "1.4.0"
comfy-table = "7.0.1"

[dev-dependencies]
tokio-test = "0.4.2"
Expand Down
129 changes: 71 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,84 @@
# KipSQL

> build the SQL layer of KipDB database.
> Lightweight SQL calculation engine, as the SQL layer of KipDB, implemented with TalentPlan's TinySQL as the reference standard
### Architecture
![architecture](./static/images/architecture.png)

> 目前处于探索阶段
轻量级SQL计算引擎,作为KipDB的SQL层,以TalentPlan的TinySQL作为参考标准进行实现

## Example
```rust
let kipsql = Database::new_on_mem();

let _ = kipsql.run("create table t1 (a int, b int)").await?;
let _ = kipsql.run("create table t2 (c int, d int)").await?;
let _ = kipsql.run("insert into t1 (b, a) values (1, 1), (3, 3), (5, 4)").await?;
let _ = kipsql.run("insert into t2 (d, c) values (1, 2), (2, 3), (5, 6)").await?;

println!("full t1:");
let vec_batch_full_fields_t1 = kipsql.run("select * from t1").await?;
print_batches(&vec_batch_full_fields_t1)?;

println!("full t2:");
let vec_batch_full_fields_t2 = kipsql.run("select * from t2").await?;
print_batches(&vec_batch_full_fields_t2)?;

println!("projection_and_filter:");
let vec_batch_projection_a = kipsql.run("select a from t1 where a <= b").await?;
print_batches(&vec_batch_projection_a)?;

println!("projection_and_sort:");
let vec_batch_projection_a = kipsql.run("select a from t1 order by a").await?;
print_batches(&vec_batch_projection_a)?;

println!("limit:");
let vec_batch_limit=kipsql.run("select * from t1 limit 1 offset 1").await?;
print_batches(&vec_batch_limit)?;

println!("inner join:");
let vec_batch_inner_join = kipsql.run("select * from t1 inner join t2 on a = c").await?;
print_batches(&vec_batch_inner_join)?;
### Get Started
Install rust toolchain first.
```
cargo run
```
test command
```mysql
create table t1 (a int, b int);

println!("left join:");
let vec_batch_left_join = kipsql.run("select * from t1 left join t2 on a = c").await?;
print_batches(&vec_batch_left_join)?;
insert into t1 (a, b) values (1, 1), (5, 3), (5, 2);

println!("right join:");
let vec_batch_right_join = kipsql.run("select * from t1 right join t2 on a = c and a > 1").await?;
print_batches(&vec_batch_right_join)?;
select * from t1;

println!("full join:");
let vec_batch_full_join = kipsql.run("select d, b from t1 full join t2 on a = c and a > 1").await?;
print_batches(&vec_batch_full_join)?;
select * from t1 order by a asc nulls first
```

![demo](./static/images/demo.png)

### Features
- Select
- Filter
- Limit
- Sort
- Projection
- TableScan
- Join (HashJoin)
- Inner
- Left
- Right
- Full
- Insert
- CreateTable
- DDL
- Create
- [x] CreateTable
- [ ] CreateIndex
- Drop
- DQL
- [x] Select
- [x] Where
- [ ] Distinct
- [ ] Aggregation: count()/sum()/avg()/min()/max()
- [ ] Subquery
- [x] Join: Inner/Left/Right/Full Cross(x)
- [ ] Group By
- [ ] Having
- [x] Order By
- [x] Limit
- DML
- [x] Insert
- [ ] Update
- [ ] Delete
- DataTypes
- Invalid
- SqlNull
- Boolean
- Tinyint
- UTinyint
- Smallint
- USmallint
- Integer
- UInteger
- Bigint
- UBigint
- Float
- Double
- Varchar
- Optimizer rules
- Limit Project Transpose
- Eliminate Limits
- Push Limit Through Join
- Push Limit Into Scan
- Combine Filters
- Column Pruning
- Collapse Project
- Executors
- [x] CreateTable
- [x] SeqScan
- [ ] IndexScan
- [x] Filter
- [x] Project
- [x] Limit
- [x] Hash Join
- [x] Insert
- [x] Values
- [ ] Update
- [ ] Delete

### Thanks For
- [Fedomn/sqlrs](https://github.com/Fedomn/sqlrs): 主要参考资料,Optimizer、Executor均参考自sqlrs的设计
Expand Down
Loading

0 comments on commit 512690f

Please sign in to comment.