Skip to content

Commit

Permalink
fix: fix decimal parse (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
sundy-li authored Aug 3, 2023
1 parent 1e854c1 commit ef8ddc0
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [
]

[workspace.package]
version = "0.5.0"
version = "0.5.1"
edition = "2021"
license = "Apache-2.0"
authors = ["Databend Authors <[email protected]>"]
Expand All @@ -18,5 +18,5 @@ keywords = ["databend", "database"]
repository = "https://github.com/datafuselabs/bendsql"

[workspace.dependencies]
databend-client = { path = "core", version = "0.5.0" }
databend-driver = { path = "driver", version = "0.5.0" }
databend-client = { path = "core", version = "0.5.1" }
databend-driver = { path = "driver", version = "0.5.1" }
2 changes: 1 addition & 1 deletion bindings/nodejs/npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@databend-driver/lib-darwin-arm64",
"repository": "https://github.com/datafuselabs/bendsql.git",
"version": "0.5.0",
"version": "0.5.1",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@databend-driver/lib-darwin-x64",
"repository": "https://github.com/datafuselabs/bendsql.git",
"version": "0.5.0",
"version": "0.5.1",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@databend-driver/lib-linux-x64-gnu",
"repository": "https://github.com/datafuselabs/bendsql.git",
"version": "0.5.0",
"version": "0.5.1",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@databend-driver/lib-win32-x64-msvc",
"repository": "https://github.com/datafuselabs/bendsql.git",
"version": "0.5.0",
"version": "0.5.1",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "databend-driver",
"author": "Databend Authors <[email protected]>",
"version": "0.5.0",
"version": "0.5.1",
"license": "Apache-2.0",
"main": "index.js",
"types": "index.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions cli/tests/00-base.result
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ a 1 true
with comment
3.00 3.00
Asia/Shanghai
0 0.00
1 1.00
2 2.00
bye
7 changes: 7 additions & 0 deletions cli/tests/00-base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,12 @@ select 1.00 + 2.00, 3.00;

select/*+ SET_VAR(timezone='Asia/Shanghai') */ timezone();

drop table if exists test_decimal;
create table test_decimal(a decimal(40, 0), b decimal(20 , 2));
insert into test_decimal select number, number from numbers(3);

select * from test_decimal;

select 'bye';
drop table test;
drop table test_decimal;
6 changes: 2 additions & 4 deletions driver/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ pub fn display_decimal_256(num: i256, scale: u8) -> String {
pub fn parse_decimal(text: &str, size: DecimalSize) -> Result<NumberValue> {
let mut start = 0;
let bytes = text.as_bytes();
while bytes[start] == b'0' {
while start < text.len() && bytes[start] == b'0' {
start += 1
}
let text = &text[start..];
Expand All @@ -564,9 +564,7 @@ pub fn parse_decimal(text: &str, size: DecimalSize) -> Result<NumberValue> {
(Some(p1), Some(p2)) => (&text[..p1], &text[(p1 + 1)..p2], Some(&text[(p2 + 1)..])),
(Some(p), None) => (&text[..p], &text[(p + 1)..], None),
(None, Some(p)) => (&text[..p], "", Some(&text[(p + 1)..])),
_ => {
unreachable!()
}
(None, None) => (text, "", None),
};
let exp = match e_part {
Some(s) => s.parse::<i32>()?,
Expand Down

0 comments on commit ef8ddc0

Please sign in to comment.