Skip to content

Commit ae37f3b

Browse files
beneschaljoscha
authored andcommitted
sqllogictest: correct printing floats as integers
In SQLite's SLT, floats are printed as integers by casting the float to an integer then printing the integer. Our SLT runner was printing floats rounding the float then printing the float with zero digits after the decimal point. This is almost the same thing, except that "0" is printed as "-0" since rust-lang/rust#78618. Future proof the code (and make it work the same way in the nightly coverage build) by following the SQLite approach. Supersedes MaterializeInc#7096.
1 parent a40763b commit ae37f3b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/sqllogictest/src/runner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ fn format_datum(d: Slt, typ: &Type, mode: Mode, col: usize) -> String {
426426
(Type::Integer, Value::Int4(i)) => i.to_string(),
427427
(Type::Integer, Value::Int8(i)) => i.to_string(),
428428
(Type::Integer, Value::Numeric(d)) => format!("{:.0}", d),
429-
(Type::Integer, Value::Float4(f)) => format!("{:.0}", f.trunc()),
430-
(Type::Integer, Value::Float8(f)) => format!("{:.0}", f.trunc()),
429+
(Type::Integer, Value::Float4(f)) => format!("{}", f as i64),
430+
(Type::Integer, Value::Float8(f)) => format!("{}", f as i64),
431431
// This is so wrong, but sqlite needs it.
432432
(Type::Integer, Value::Text(_)) => "0".to_string(),
433433
(Type::Integer, Value::Bool(b)) => i8::from(b).to_string(),

test/sqllogictest/arithmetic.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ SELECT 1 + CAST ('5' AS double precision)
259259
----
260260
6
261261

262-
query II
262+
query TT
263263
SELECT CAST ('+Inf' AS double precision), CAST ('inf' AS double precision)
264264
----
265265
inf inf

0 commit comments

Comments
 (0)