Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,15 @@ jobs:
# as it is set as an "override" for current directory

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
run: make cargo-check


- name: Run cargo build
uses: actions-rs/cargo@v1
with:
command: build
run: make build


- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --all
run: make test
# 2
fmt:
name: Rust fmt
Expand All @@ -62,10 +55,7 @@ jobs:
# as it is set as an "override" for current directory

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check
run: make fmt
# 3
e2e:
name: Rust e2e sqllogictest
Expand All @@ -85,11 +75,8 @@ jobs:
# `cargo check` command here will use installed `nightly`
# as it is set as an "override" for current directory

- name: Run cargo run sqllogictest-test
uses: actions-rs/cargo@v1
with:
command: run
args: --bin sqllogictest-test --manifest-path ./tests/sqllogictest/Cargo.toml
- name: Run sqllogictest suite
run: make test-slt
# 4
wasm-tests:
name: Wasm cargo tests
Expand All @@ -115,7 +102,7 @@ jobs:
version: latest

- name: Run wasm-bindgen tests (wasm32 target)
run: wasm-pack test --node -- --package kite_sql --lib
run: make test-wasm
# 5
wasm-examples:
name: Wasm examples (nodejs)
Expand All @@ -141,12 +128,10 @@ jobs:
version: latest

- name: Build wasm package
run: wasm-pack build --release --target nodejs
run: make wasm-build

- name: Run wasm example scripts
run: |
node examples/wasm_hello_world.test.mjs
node examples/wasm_index_usage.test.mjs
run: make wasm-examples
# 6
native-examples:
name: Native examples
Expand All @@ -160,8 +145,5 @@ jobs:
toolchain: stable
override: true

- name: Run hello_world example
run: cargo run --example hello_world

- name: Run transaction example
run: cargo run --example transaction
- name: Run native examples
run: make native-examples
34 changes: 29 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@ CARGO ?= cargo
WASM_PACK ?= wasm-pack
SQLLOGIC_PATH ?= tests/slt/**/*.slt

.PHONY: test test-wasm test-slt test-all wasm-build check tpcc
.PHONY: test test-wasm test-slt test-all wasm-build check tpcc cargo-check build wasm-examples native-examples fmt clippy

## Run default Rust tests in the current environment (non-WASM).
test:
$(CARGO) test
$(CARGO) test --all

## Perform a `cargo check` across the workspace.
cargo-check:
$(CARGO) check

## Build the workspace artifacts (debug).
build:
$(CARGO) build

## Build the WebAssembly package (artifact goes to ./pkg).
wasm-build:
$(WASM_PACK) build --release --target nodejs

## Execute wasm-bindgen tests under Node.js (wasm32 target).
test-wasm:
$(WASM_PACK) test --node --release
$(WASM_PACK) test --node -- --package kite_sql --lib

## Run the sqllogictest harness against the configured .slt suite.
test-slt:
Expand All @@ -24,11 +32,27 @@ test-slt:
## Convenience target to run every suite in sequence.
test-all: test test-wasm test-slt

## Run formatting (check mode) and clippy linting together.
check:
## Run formatting (check mode) across the workspace.
fmt:
$(CARGO) fmt --all -- --check

## Execute clippy across all targets/features with warnings elevated to errors.
clippy:
$(CARGO) clippy --all-targets --all-features -- -D warnings

## Run formatting (check mode) and clippy linting together.
check: fmt clippy

## Execute the TPCC workload example as a standalone command.
tpcc:
$(CARGO) run -p tpcc --release

## Run JavaScript-based Wasm example scripts.
wasm-examples:
node examples/wasm_hello_world.test.mjs
node examples/wasm_index_usage.test.mjs

## Run the native (non-Wasm) example binaries.
native-examples:
$(CARGO) run --example hello_world
$(CARGO) run --example transaction
24 changes: 12 additions & 12 deletions benchmarks/query_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use sqlite::Error;
use std::fs;
use std::path::Path;

const QUERY_BENCH_KITE_SQL_PATH: &'static str = "./kitesql_bench";
const QUERY_BENCH_SQLITE_PATH: &'static str = "./sqlite_bench";
const QUERY_BENCH_KITE_SQL_PATH: &str = "./kitesql_bench";
const QUERY_BENCH_SQLITE_PATH: &str = "./sqlite_bench";
const TABLE_ROW_NUM: u64 = 200_000;

fn query_cases() -> Vec<(&'static str, &'static str)> {
Expand Down Expand Up @@ -62,9 +62,9 @@ fn init_kitesql_query_bench() -> Result<(), DatabaseError> {
}

fn init_sqlite_query_bench() -> Result<(), Error> {
let connection = sqlite::open(QUERY_BENCH_SQLITE_PATH.to_owned())?;
let connection = sqlite::open(QUERY_BENCH_SQLITE_PATH)?;

let _ = connection.execute("create table t1 (c1 int primary key, c2 int)")?;
connection.execute("create table t1 (c1 int primary key, c2 int)")?;

let pb = ProgressBar::new(TABLE_ROW_NUM);
pb.set_style(
Expand All @@ -73,7 +73,7 @@ fn init_sqlite_query_bench() -> Result<(), Error> {
.unwrap(),
);
for i in 0..TABLE_ROW_NUM {
let _ = connection.execute(format!("insert into t1 values({}, {})", i, i + 1))?;
connection.execute(format!("insert into t1 values({i}, {})", i + 1).as_str())?;
pb.set_position(i + 1);
}
pb.finish_with_message("Insert completed!");
Expand All @@ -91,16 +91,14 @@ fn path_exists_and_is_directory(path: &str) -> bool {
fn query_on_execute(c: &mut Criterion) {
if !Path::new(QUERY_BENCH_SQLITE_PATH).exists() {
println!(
"SQLITE: The table is not initialized and data insertion is started. => {}",
TABLE_ROW_NUM
"SQLITE: The table is not initialized and data insertion is started. => {TABLE_ROW_NUM}"
);

init_sqlite_query_bench().unwrap();
}
if !path_exists_and_is_directory(QUERY_BENCH_KITE_SQL_PATH) {
println!(
"KiteSQL: The table is not initialized and data insertion is started. => {}",
TABLE_ROW_NUM
"KiteSQL: The table is not initialized and data insertion is started. => {TABLE_ROW_NUM}"
);

init_kitesql_query_bench().unwrap();
Expand All @@ -111,16 +109,18 @@ fn query_on_execute(c: &mut Criterion) {
println!("Table initialization completed");

for (name, case) in query_cases() {
c.bench_function(format!("KiteSQL: {} by '{}'", name, case).as_str(), |b| {
let kite_label = format!("KiteSQL: {name} by '{case}'");
c.bench_function(&kite_label, |b| {
b.iter(|| {
for tuple in database.run(case).unwrap() {
let _ = tuple.unwrap();
}
})
});

let connection = sqlite::open(QUERY_BENCH_SQLITE_PATH.to_owned()).unwrap();
c.bench_function(format!("SQLite: {} by '{}'", name, case).as_str(), |b| {
let connection = sqlite::open(QUERY_BENCH_SQLITE_PATH).unwrap();
let sqlite_label = format!("SQLite: {name} by '{case}'");
c.bench_function(&sqlite_label, |b| {
b.iter(|| {
for row in connection.prepare(case).unwrap() {
let _ = row.unwrap();
Expand Down
11 changes: 7 additions & 4 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use futures::stream;
use kite_sql::db::{DBTransaction, DataBaseBuilder, Database, ResultIter};
use kite_sql::errors::DatabaseError;
use kite_sql::storage::rocksdb::RocksStorage;
use kite_sql::types::tuple::{Schema, SchemaRef, Tuple};
use kite_sql::types::tuple::{SchemaRef, Tuple};
use kite_sql::types::LogicalType;
use log::{error, info, LevelFilter};
use parking_lot::Mutex;
Expand Down Expand Up @@ -172,7 +172,10 @@ impl SimpleQueryHandler for SessionBackend {
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
guard.replace(TransactionPtr(
Box::leak(Box::<DBTransaction<'static, RocksStorage>>::new(unsafe {
transmute(transaction)
transmute::<
DBTransaction<'_, RocksStorage>,
DBTransaction<'static, RocksStorage>,
>(transaction)
}))
.into(),
));
Expand Down Expand Up @@ -371,7 +374,7 @@ async fn main() {
tokio::select! {
res = server_run(listener,factory) => {
if let Err(err) = res {
error!("[Listener][Failed To Accept]: {}", err);
error!("[Listener][Failed To Accept]: {err}");
}
}
_ = quit() => info!("Bye!")
Expand All @@ -388,7 +391,7 @@ async fn server_run(

tokio::spawn(async move {
if let Err(err) = process_socket(incoming_socket.0, None, factory_ref).await {
error!("Failed To Process: {}", err);
error!("Failed To Process: {err}");
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/binder/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ mod tests {
Operator::CreateTable(op) => {
assert_eq!(op.table_name.as_ref(), "t1");
assert_eq!(op.columns[0].name(), "id");
assert_eq!(op.columns[0].nullable(), false);
assert!(!op.columns[0].nullable());
assert_eq!(
op.columns[0].desc(),
&ColumnDesc::new(LogicalType::Integer, Some(0), false, None)?
);
assert_eq!(op.columns[1].name(), "name");
assert_eq!(op.columns[1].nullable(), true);
assert!(op.columns[1].nullable());
assert_eq!(
op.columns[1].desc(),
&ColumnDesc::new(
Expand Down
2 changes: 1 addition & 1 deletion src/binder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ pub mod test {
);
let stmt = crate::parser::parse_sql(sql)?;

Ok(binder.bind(&stmt[0])?)
binder.bind(&stmt[0])
}

pub(crate) fn column_id_by_name(&self, name: &str) -> &ColumnId {
Expand Down
18 changes: 9 additions & 9 deletions src/binder/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,27 +1213,27 @@ mod tests {
let table_states = build_t1_table()?;

let plan_1 = table_states.plan("select * from t1")?;
println!("just_col:\n {:#?}", plan_1);
println!("just_col:\n {plan_1:#?}");
let plan_2 = table_states.plan("select t1.c1, t1.c2 from t1")?;
println!("table_with_col:\n {:#?}", plan_2);
println!("table_with_col:\n {plan_2:#?}");
let plan_3 = table_states.plan("select t1.c1, t1.c2 from t1 where c1 > 2")?;
println!("table_with_col_and_c1_compare_constant:\n {:#?}", plan_3);
println!("table_with_col_and_c1_compare_constant:\n {plan_3:#?}");
let plan_4 = table_states.plan("select t1.c1, t1.c2 from t1 where c1 > c2")?;
println!("table_with_col_and_c1_compare_c2:\n {:#?}", plan_4);
println!("table_with_col_and_c1_compare_c2:\n {plan_4:#?}");
let plan_5 = table_states.plan("select avg(t1.c1) from t1")?;
println!("table_with_col_and_c1_avg:\n {:#?}", plan_5);
println!("table_with_col_and_c1_avg:\n {plan_5:#?}");
let plan_6 = table_states.plan("select t1.c1, t1.c2 from t1 where (t1.c1 - t1.c2) > 1")?;
println!("table_with_col_nested:\n {:#?}", plan_6);
println!("table_with_col_nested:\n {plan_6:#?}");

let plan_7 = table_states.plan("select * from t1 limit 1")?;
println!("limit:\n {:#?}", plan_7);
println!("limit:\n {plan_7:#?}");

let plan_8 = table_states.plan("select * from t1 offset 2")?;
println!("offset:\n {:#?}", plan_8);
println!("offset:\n {plan_8:#?}");

let plan_9 =
table_states.plan("select c1, c3 from t1 inner join t2 on c1 = c3 and c1 > 1")?;
println!("join:\n {:#?}", plan_9);
println!("join:\n {plan_9:#?}");

Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions src/catalog/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,19 +309,19 @@ mod tests {
let col_catalogs = vec![col0, col1];
let table_catalog = TableCatalog::new("test".to_string().into(), col_catalogs).unwrap();

assert_eq!(table_catalog.contains_column("a"), true);
assert_eq!(table_catalog.contains_column("b"), true);
assert_eq!(table_catalog.contains_column("c"), false);
assert!(table_catalog.contains_column("a"));
assert!(table_catalog.contains_column("b"));
assert!(!table_catalog.contains_column("c"));

let col_a_id = table_catalog.get_column_id_by_name("a").unwrap();
let col_b_id = table_catalog.get_column_id_by_name("b").unwrap();
assert!(col_a_id < col_b_id);

let column_catalog = table_catalog.get_column_by_id(&col_a_id).unwrap();
let column_catalog = table_catalog.get_column_by_id(col_a_id).unwrap();
assert_eq!(column_catalog.name(), "a");
assert_eq!(*column_catalog.datatype(), LogicalType::Integer,);

let column_catalog = table_catalog.get_column_by_id(&col_b_id).unwrap();
let column_catalog = table_catalog.get_column_by_id(col_b_id).unwrap();
assert_eq!(column_catalog.name(), "b");
assert_eq!(*column_catalog.datatype(), LogicalType::Boolean,);
}
Expand Down
2 changes: 1 addition & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ pub(crate) mod test {
let database = DataBaseBuilder::path(temp_dir.path()).build()?;
let mut transaction = database.storage.transaction()?;

build_table(&database.state.table_cache(), &mut transaction)?;
build_table(database.state.table_cache(), &mut transaction)?;
transaction.commit()?;

for result in database.run("select * from t1")? {
Expand Down
2 changes: 1 addition & 1 deletion src/execution/dml/copy_from_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod tests {
let csv = "1,1.5,one\n2,2.5,two\n";

let mut file = tempfile::NamedTempFile::new().expect("failed to create temp file");
write!(file, "{}", csv).expect("failed to write file");
write!(file, "{csv}").expect("failed to write file");

let columns = vec![
ColumnRef::from(ColumnCatalog::direct_new(
Expand Down
4 changes: 2 additions & 2 deletions src/execution/dml/copy_to_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ mod tests {
let storage = db.storage;
let mut transaction = storage.transaction()?;
let table = transaction
.table(&db.state.table_cache(), "t1".to_string().into())?
.table(db.state.table_cache(), "t1".to_string().into())?
.unwrap();

let executor = CopyToFile {
Expand Down Expand Up @@ -224,7 +224,7 @@ mod tests {

assert!(records.next().is_none());

assert_eq!(tuple, TupleBuilder::build_result(format!("{}", op)));
assert_eq!(tuple, TupleBuilder::build_result(format!("{op}")));

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/execution/dql/join/nested_loop_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ mod test {
)?;
let mut actual = Vec::new();

while let Some(row) = iter.next() {
for row in iter.by_ref() {
let tuple = row?;
actual.push(tuple_to_strings(&tuple));
}
Expand Down
Loading
Loading