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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ wkt = "0.11.1"
xorfilter-rs = { version = "0.5", features = ["cbordata"] }
zerocopy = { version = "0.8.26", features = ["derive"] }
zip = "3.0.0"
zmij = "1.0"
zstd = "0.12.3"

# AST needed
Expand Down
1 change: 1 addition & 0 deletions src/query/ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ strum = { workspace = true }
strum_macros = { workspace = true }
unindent = { workspace = true }
url = { workspace = true }
zmij = { workspace = true }

[dev-dependencies]
divan = { workspace = true }
Expand Down
4 changes: 3 additions & 1 deletion src/query/ast/src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,9 @@ impl Display for Literal {
} else if val.is_nan() {
write!(f, "'NaN'::FLOAT64")
} else {
write!(f, "{val}")
let mut buffer = zmij::Buffer::new();
let s = buffer.format_finite(*val);
write!(f, "{s}")
}
}
Literal::String(val) => {
Expand Down
23 changes: 12 additions & 11 deletions src/query/ast/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2782,31 +2782,32 @@ pub fn parse_float(text: &str) -> Result<Literal, ErrorKind> {
None => 0,
};

let p = i_part.len() as i32 + exp - f_part.len() as i32;
if !(-76..=76).contains(&p) {
let i_part_len = i_part.len() as i32;
let f_part_len = f_part.len() as i32;
let mut precision = i_part_len + f_part_len;
if exp > f_part_len {
precision += exp - f_part_len;
} else if i_part_len + exp < 0 {
precision -= i_part_len + exp;
}

if precision > 76 {
Ok(Literal::Float64(fast_float2::parse(text)?))
} else {
let mut digits = String::with_capacity(76);
let mut digits = String::with_capacity(precision as usize);
digits.push_str(i_part);
digits.push_str(f_part);
if digits.is_empty() {
digits.push('0')
}
let mut scale = f_part.len() as i32 - exp;
let mut scale = f_part_len - exp;
if scale < 0 {
// e.g 123.1e3
for _ in 0..(-scale) {
digits.push('0')
}
scale = 0;
};

// truncate
if digits.len() > 76 {
scale -= digits.len() as i32 - 76;
digits.truncate(76);
}

Ok(Literal::Decimal256 {
value: i256::from_str_radix(&digits, 10)?,
precision: 76,
Expand Down
1 change: 1 addition & 0 deletions src/query/formats/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ num = { workspace = true }
num-traits = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
zmij = { workspace = true }

[dev-dependencies]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ macro_rules! impl_float {
if self.is_nan() {
buf.extend_from_slice(&settings.nan_bytes);
} else {
extend_lexical(self, buf);
let mut buffer = zmij::Buffer::new();
let s = buffer.format_finite(self);
buf.extend_from_slice(s.as_bytes());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ SELECT * FROM t
----
-128 0

onlyif mysql
query FF
select 10.234567899999999e80, 1234567890123456789012345678901234567890123456789012345678901234567890.1e-80;
----
1.0234567899999998e+81 1.2345678901234568e-11

statement ok
DROP DATABASE data_type

Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ drop table if exists t_epoch;
query T
select EXTRACT(EPOCH FROM to_datetime('1969-12-31 23:59:59.999999'))
----
-1.0e-6
-1e-6

query B
select EXTRACT(EPOCH FROM now()) = epoch(now())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ SELECT
(FLOOR(EXP(SQRT(1234.56789)) * 10000) % 18446744073709551615) b,
(FLOOR(PI() * 10000) % 18446744073709551615) c, a + b - c
----
9.754610558146624e15 1.817827108747062e19 31415.0 1.8188025698028737e19

9754610558146624.0 1.817827108747062e+19 31415.0 1.8188025698028737e+19

query F
SELECT power(-2, 2)
Expand Down Expand Up @@ -434,7 +433,7 @@ SELECT
(FLOOR(EXP(SQRT(1234.56789)) * 10000) % 18446744073709551615) b,
(FLOOR(PI() * 10000) % 18446744073709551615) c, a + b - c
----
9.754610558146624e15 1.817827108747062e19 31415.0 1.8188025698028737e19
9754610558146624.0 1.817827108747062e+19 31415.0 1.8188025698028737e+19

query T
SELECT TRUNC(10.6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ select point_in_polygon((2.5,), [(4., 0.), (8., 4.), (4., 8.), (0., 4.)], [(3.,
query T
select great_circle_angle(-2181569507.9714413, 15253014773.129665, 0.5823419941455749, 0.5823419941455749)
----
1.3941863e12
1394186300000.0
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ select h3_get_base_cell(644325524701193974)
query F
select h3_hex_area_m2(1)
----
6.097884417941339e11
609788441794.1339

query F
select h3_hex_area_km2(1)
Expand Down Expand Up @@ -154,9 +154,9 @@ query F
select h3_hex_area_m2(res) as m2 from t2 order by m2
----
1770347654.491309
1.239343465508818e10
8.680178039899731e10
6.097884417941339e11
12393434655.08818
86801780398.99731
609788441794.1339

query F
select h3_hex_area_km2(res) as km2 from t2 order by km2
Expand Down
4 changes: 2 additions & 2 deletions tests/sqllogictests/suites/stage/formats/avro/avro_copy.test
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ avro/number.avro 2 0 NULL NULL
query
select * from t
----
2147483647 9223372036854775807 3.4028235e38 1.7976931348623157e308
-2147483648 -9223372036854775808 -3.4028235e38 -1.7976931348623157e308
2147483647 9223372036854775807 3.4028235e+38 1.7976931348623157e+308
-2147483648 -9223372036854775808 -3.4028235e+38 -1.7976931348623157e+308
2 changes: 1 addition & 1 deletion tests/sqllogictests/suites/stage/formats/csv/csv_copy.test
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ select * from t2
100.2345
200.789
300.0
3.698114021686886e16
3.698114021686886e+16