Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UINT32, UINT64 and UINT128 data types #1019

Merged
merged 67 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
0411a1f
feat: add new unsigned integer data type
ChobobDev Nov 26, 2022
45e8159
feat: add new unsinged integer data type
ChobobDev Nov 26, 2022
784cdcc
feat: add new datatype into macro.rs
ChobobDev Nov 26, 2022
f22f06c
feat: implememnt convert for unsigned int
ChobobDev Nov 26, 2022
bbfcede
feat: add unsinged int to primitive
ChobobDev Nov 26, 2022
f4232ad
feat: add unsinged int to key and json rs
ChobobDev Nov 26, 2022
e6dcdc5
fix: remove unreachable data type
ChobobDev Nov 26, 2022
e5f1b9c
style: thx fmt
ChobobDev Nov 26, 2022
9928766
test: improve coverage of macros
ChobobDev Nov 26, 2022
f285763
test: improve coverage of json.rs
ChobobDev Nov 26, 2022
1a296e3
test: improve line coverage of convert.rs
ChobobDev Nov 26, 2022
6a93f2e
style: thx fmt
ChobobDev Nov 26, 2022
7ee58e4
test: remove misleading test case
ChobobDev Nov 26, 2022
2cd2f89
test: improve line coverage
ChobobDev Jan 13, 2023
ef3c5f8
Merge branch 'main' into feature/uint_data_type
ChobobDev Jan 13, 2023
bc2a1ef
style: thx clippy
ChobobDev Jan 13, 2023
29893a7
fix: fix misleading expression
ChobobDev Jan 13, 2023
4de73ee
fix : fix typo
ChobobDev Jan 13, 2023
0ef9781
test : improve line coverage of `expr.rs`
ChobobDev Jan 13, 2023
64e5f39
test: improve coverage of `bigdecimal_ext.rs`
ChobobDev Jan 13, 2023
52ee74e
style: cargo fmt
ChobobDev Jan 13, 2023
5807764
test: improve line coverage of `value/mod.rs`
ChobobDev Jan 13, 2023
33b2c0f
style : cargo fmt
ChobobDev Jan 13, 2023
884a16c
test: improve line coverage of `value/mod.rs`
ChobobDev Jan 13, 2023
e994a0a
style: cargo fmt
ChobobDev Jan 13, 2023
4cf9eff
test: improve line coverage of `f64.rs`
ChobobDev Jan 13, 2023
7b35f26
style: cargo fmt
ChobobDev Jan 13, 2023
67d4cf6
test: improve line coverage of `decimal.rs`
ChobobDev Jan 13, 2023
8d163f3
style: cargo fmt
ChobobDev Jan 13, 2023
589f32d
test: improve line coverage of `key.rs`
ChobobDev Jan 14, 2023
621c502
feat: add the missing data type translation in `translate/data_type.rs`
ChobobDev Jan 14, 2023
d6d7441
feat: Add literals for missing data types
ChobobDev Jan 14, 2023
06efa4a
test: improve line coverage of `primitive.rs`
ChobobDev Jan 14, 2023
c0ecf44
test : improve line coverage
ChobobDev Jan 14, 2023
cf4a4c8
fix : resolve `try_from_literal` error
ChobobDev Jan 14, 2023
288c453
test: improve line coverage of `mod.rs`
ChobobDev Jan 14, 2023
0cb6a7b
test: improve line coverage of `mod.rs`
ChobobDev Jan 14, 2023
d78bc02
test: add missing tests
ChobobDev Jan 14, 2023
60dcdd3
style: cargo fmt
ChobobDev Jan 14, 2023
7387c31
Merge branch 'main' into feature/uint_data_type
ChobobDev Feb 10, 2023
18aa579
merge main into feature branch
ChobobDev Feb 10, 2023
dcd7d59
style: cargo fmt
ChobobDev Feb 10, 2023
5a9db7f
fix: fix merge error
ChobobDev Feb 10, 2023
fd6a036
fix : try merging the main again
ChobobDev Feb 10, 2023
c7cfbbe
Merge branch 'main' into feature/uint_data_type
ChobobDev Feb 10, 2023
eeaff8a
merge main into feature branch
ChobobDev Mar 25, 2023
2c7bcef
fix : fix impossibleCast list for the newly added data types
ChobobDev Mar 25, 2023
953bbc2
fix: handle uuid in u128 format
ChobobDev Mar 25, 2023
8748bbc
fix : allow both uuid and str to be ran
ChobobDev Mar 25, 2023
1de3bbd
fix: tried using and_then
ChobobDev Mar 25, 2023
9731a11
fix: check parse_uuid whether it returns error
ChobobDev Mar 25, 2023
129a5de
fix: remove unnecessary Str to Uuid conversion
ChobobDev Mar 26, 2023
6831d5d
Merge branch 'main' into feature/uint_data_type
ChobobDev Apr 2, 2023
96e19f1
fix: fix wierdly merged lines
ChobobDev Apr 2, 2023
b8c1cb3
test : add test case
ChobobDev Apr 2, 2023
9c62b2c
fix : reset the branch
ChobobDev Apr 4, 2023
f33230b
Merge branch 'main' into feature/uint_data_type
ChobobDev Apr 4, 2023
bdbff0d
style: cargo fmt
ChobobDev Apr 4, 2023
b63e68d
fix: remove unnecessary comment
ChobobDev Apr 6, 2023
dbb5094
test : improve line coverage
ChobobDev Apr 6, 2023
59357a7
style: cargo fmt
ChobobDev Apr 6, 2023
da3be0d
test : fix misleading test case
ChobobDev Apr 6, 2023
b32e786
test: add ommited test case
ChobobDev Apr 6, 2023
d8feb37
test : improve line coverage
ChobobDev Apr 6, 2023
9693a12
test : add ommitted test case
ChobobDev Apr 6, 2023
3bfc068
test : change misleading test case
ChobobDev Apr 6, 2023
6a4252a
test : add omitted test-suites for new data types
ChobobDev Apr 6, 2023
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
Prev Previous commit
Next Next commit
Merge branch 'main' into feature/uint_data_type
  • Loading branch information
ChobobDev committed Feb 10, 2023
commit 7387c3103d08bd1a9585a1ec91c2278d001b243f
2 changes: 0 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,4 @@ jobs:
cd ../../../
cd storages/web-storage
wasm-pack test --headless --firefox
cd ../idb-storage
WASM_BINDGEN_TEST_TIMEOUT=60 wasm-pack test --headless --firefox
cd ../../
7 changes: 0 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,3 @@ default-members = [
# enable this only for gluesql-js build
# [profile.release]
# opt-level = "s"

[workspace.package]
edition = "2021"
description = "GlueSQL - Open source SQL database engine fully written in Rust with pure functional execution layer, easily swappable storage and web assembly support!"
license = "Apache-2.0"
repository = "https://github.com/gluesql/gluesql"
documentation = "https://docs.rs/gluesql/"
10 changes: 5 additions & 5 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "gluesql-cli"
version = "0.13.1"
edition = "2021"
authors = ["Taehoon Moon <taehoon.moon@outlook.com>"]
edition.workspace = true
description.workspace = true
license.workspace = true
repository.workspace = true
documentation.workspace = true
description = "GlueSQL - Open source SQL database engine fully written in Rust with pure functional execution layer, easily swappable storage and web assembly support!"
license = "Apache-2.0"
repository = "https://github.com/gluesql/gluesql"
documentation = "https://docs.rs/gluesql/"

[dependencies]
gluesql-core = { path = "../core", version = "0.13.1", features = ["alter-table"] }
Expand Down
10 changes: 5 additions & 5 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub fn run() -> Result<()> {
let path = path.as_path().to_str().expect("wrong path");

if let Some(dump_path) = args.dump {
let mut storage = SledStorage::new(path).expect("failed to load sled-storage");
dump_database(&mut storage, dump_path)?;
let storage = SledStorage::new(path).expect("failed to load sled-storage");
dump_database(storage, dump_path)?;

return Ok::<_, Error>(());
}
Expand Down Expand Up @@ -78,11 +78,11 @@ pub fn run() -> Result<()> {
Ok(())
}

pub fn dump_database(storage: &mut SledStorage, dump_path: PathBuf) -> Result<()> {
pub fn dump_database(storage: SledStorage, dump_path: PathBuf) -> Result<SledStorage> {
let file = File::create(dump_path)?;

block_on(async {
storage.begin(true).await?;
let (storage, _) = storage.begin(true).await.map_err(|(_, error)| error)?;
let schemas = storage.fetch_all_schemas().await?;
for schema in schemas {
writeln!(&file, "{}", schema.clone().to_ddl())?;
Expand Down Expand Up @@ -128,6 +128,6 @@ pub fn dump_database(storage: &mut SledStorage, dump_path: PathBuf) -> Result<()
writeln!(&file)?;
}

Ok(())
Ok(storage)
})
}
6 changes: 3 additions & 3 deletions cli/tests/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ async fn dump_and_import() {
uinti8 UINT8,
text TEXT,
bytea BYTEA,
inet INET,
date DATE,
timestamp TIMESTAMP,
time TIME,
Expand All @@ -45,7 +44,6 @@ async fn dump_and_import() {
6,
'a',
X'123456',
'::1',
DATE '2022-11-01',
TIMESTAMP '2022-11-02',
TIME '23:59:59',
Expand All @@ -68,7 +66,7 @@ async fn dump_and_import() {
source_glue.execute(sql).unwrap();
}

dump_database(&mut source_glue.storage, dump_path.clone()).unwrap();
let source_storage = dump_database(source_glue.storage.unwrap(), dump_path.clone()).unwrap();

let data_path = "tmp/target";
let config = sled::Config::default().path(data_path).temporary(true);
Expand All @@ -85,6 +83,8 @@ async fn dump_and_import() {
target_glue.execute(sql).unwrap();
}

let mut source_glue = Glue::new(source_storage);

// schemas should be identical
let sql = "SELECT OBJECT_TYPE, OBJECT_NAME FROM GLUE_OBJECTS";
let source_data = source_glue.execute(sql).unwrap();
Expand Down
11 changes: 5 additions & 6 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "gluesql-core"
version = "0.13.1"
edition = "2021"
authors = ["Taehoon Moon <taehoon.moon@outlook.com>"]
edition.workspace = true
description.workspace = true
license.workspace = true
repository.workspace = true
documentation.workspace = true
description = "GlueSQL - Open source SQL database engine fully written in Rust with pure functional execution layer, easily swappable storage and web assembly support!"
license = "Apache-2.0"
repository = "https://github.com/gluesql/gluesql"
documentation = "https://docs.rs/gluesql/"

[dependencies]
utils = { package = "gluesql-utils", path = "../utils", version = "0.13.0" }
Expand All @@ -29,7 +29,6 @@ thiserror = "1.0"
strum_macros = "0.24"
bigdecimal = { version = "0.3", features = ["serde", "string-only"] }
hex = "0.4"
rand = "0.8"

[target.'cfg(target_arch = "wasm32")'.dependencies.uuid]
version = "1"
Expand Down
1 change: 0 additions & 1 deletion core/src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub enum DataType {
Float,
Text,
Bytea,
Inet,
Date,
Timestamp,
Time,
Expand Down
18 changes: 0 additions & 18 deletions core/src/ast/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub enum Function {
expr: Expr,
then: Expr,
},
Rand(Option<Expr>),
Round(Expr),
Floor(Expr),
Trim {
Expand Down Expand Up @@ -196,10 +195,6 @@ impl ToSql for Function {
Function::IfNull { expr, then } => {
format!("IFNULL({}, {})", expr.to_sql(), then.to_sql())
}
Function::Rand(e) => match e {
Some(v) => format!("RAND({})", v.to_sql()),
None => "RAND()".to_owned(),
},
Function::Round(e) => format!("ROUND({})", e.to_sql()),
Function::Floor(e) => format!("FLOOR({})", e.to_sql()),
Function::Trim {
Expand Down Expand Up @@ -501,19 +496,6 @@ mod tests {
.to_sql()
);

assert_eq!(
"RAND()",
&Expr::Function(Box::new(Function::Rand(None))).to_sql()
);

assert_eq!(
"RAND(num)",
&Expr::Function(Box::new(Function::Rand(Some(Expr::Identifier(
"num".to_owned()
)))))
.to_sql()
);

assert_eq!(
"ROUND(num)",
&Expr::Function(Box::new(Function::Round(Expr::Identifier(
Expand Down
119 changes: 32 additions & 87 deletions core/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ pub enum Statement {
/// Table name
name: String,
/// Optional schema
columns: Option<Vec<ColumnDef>>,
columns: Vec<ColumnDef>,
source: Option<Box<Query>>,
engine: Option<String>,
},
/// ALTER TABLE
#[cfg(feature = "alter-table")]
Expand Down Expand Up @@ -168,42 +167,27 @@ impl ToSql for Statement {
name,
columns,
source,
engine,
} => {
let if_not_exists = if_not_exists.then_some("IF NOT EXISTS");
let body = match source {
Some(query) => Some(format!("AS {}", query.to_sql())),
None if columns.is_none() => None,
None => {
let columns = columns
.as_ref()
.map(|columns| {
columns
.iter()
.map(ToSql::to_sql)
.collect::<Vec<_>>()
.join(", ")
})
.unwrap_or_else(|| "".to_owned());

Some(format!("({columns})"))
} => match source {
Some(query) => match if_not_exists {
true => format!("CREATE TABLE IF NOT EXISTS {name} AS {};", query.to_sql()),
false => format!("CREATE TABLE {name} AS {};", query.to_sql()),
},
None if columns.is_empty() => match if_not_exists {
true => format!("CREATE TABLE IF NOT EXISTS {name};"),
false => format!("CREATE TABLE {name};"),
},
None => {
let columns = columns
.iter()
.map(ToSql::to_sql)
.collect::<Vec<_>>()
.join(", ");
match if_not_exists {
true => format!("CREATE TABLE IF NOT EXISTS {name} ({columns});"),
false => format!("CREATE TABLE {name} ({columns});"),
}
};
let engine = engine.as_ref().map(|engine| format!("ENGINE = {engine}"));
let sql = vec![
Some("CREATE TABLE"),
if_not_exists,
Some(name),
body.as_deref(),
engine.as_deref(),
]
.into_iter()
.flatten()
.collect::<Vec<&str>>()
.join(" ");

format!("{sql};")
}
}
},
#[cfg(feature = "alter-table")]
Statement::AlterTable { name, operation } => {
format!("ALTER TABLE {name} {};", operation.to_sql())
Expand Down Expand Up @@ -375,9 +359,8 @@ mod tests {
Statement::CreateTable {
if_not_exists: true,
name: "Foo".into(),
columns: None,
columns: Vec::new(),
source: None,
engine: None,
}
.to_sql()
);
Expand All @@ -387,9 +370,8 @@ mod tests {
Statement::CreateTable {
if_not_exists: false,
name: "Foo".into(),
columns: None,
columns: Vec::new(),
source: None,
engine: None,
}
.to_sql()
);
Expand All @@ -399,15 +381,14 @@ mod tests {
Statement::CreateTable {
if_not_exists: true,
name: "Foo".into(),
columns: Some(vec![ColumnDef {
columns: vec![ColumnDef {
name: "id".to_owned(),
data_type: DataType::Boolean,
nullable: false,
default: None,
unique: None,
},]),
},],
source: None,
engine: None,
}
.to_sql()
);
Expand All @@ -417,7 +398,7 @@ mod tests {
Statement::CreateTable {
if_not_exists: false,
name: "Foo".into(),
columns: Some(vec![
columns: vec![
ColumnDef {
name: "id".to_owned(),
data_type: DataType::Int,
Expand All @@ -439,9 +420,8 @@ mod tests {
default: None,
unique: None,
}
]),
source: None,
engine: None,
],
source: None
}
.to_sql()
);
Expand All @@ -454,7 +434,7 @@ mod tests {
Statement::CreateTable {
if_not_exists: false,
name: "Foo".into(),
columns: None,
columns: vec![],
source: Some(Box::new(Query {
body: SetExpr::Select(Box::new(Select {
projection: vec![
Expand Down Expand Up @@ -482,8 +462,7 @@ mod tests {
order_by: vec![],
limit: None,
offset: None
})),
engine: None,
}))
}
.to_sql()
);
Expand All @@ -493,49 +472,15 @@ mod tests {
Statement::CreateTable {
if_not_exists: true,
name: "Foo".into(),
columns: None,
columns: vec![],
source: Some(Box::new(Query {
body: SetExpr::Values(Values(vec![vec![Expr::Literal(AstLiteral::Boolean(
true
))]])),
order_by: vec![],
limit: None,
offset: None
})),
engine: None,
}
.to_sql()
);
}

#[test]
fn to_sql_create_table_with_engine() {
assert_eq!(
"CREATE TABLE Foo ENGINE = MEMORY;",
Statement::CreateTable {
if_not_exists: false,
name: "Foo".into(),
columns: None,
source: None,
engine: Some("MEMORY".to_owned()),
}
.to_sql()
);

assert_eq!(
"CREATE TABLE Foo (id BOOLEAN NOT NULL) ENGINE = SLED;",
Statement::CreateTable {
if_not_exists: false,
name: "Foo".into(),
columns: Some(vec![ColumnDef {
name: "id".to_owned(),
data_type: DataType::Boolean,
nullable: false,
default: None,
unique: None,
},]),
source: None,
engine: Some("SLED".to_owned()),
}))
}
.to_sql()
);
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.