Skip to content

Commit

Permalink
sqllogictest: correct printing floats as integers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benesch authored and ruchirK committed Jun 21, 2021
1 parent df7d083 commit 70b3b4c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/sqllogictest/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ fn format_datum(d: Slt, typ: &Type, mode: Mode, col: usize) -> String {
(Type::Integer, Value::Int4(i)) => i.to_string(),
(Type::Integer, Value::Int8(i)) => i.to_string(),
(Type::Integer, Value::Numeric(d)) => format!("{:.0}", d),
(Type::Integer, Value::Float4(f)) => format!("{:.0}", f.trunc()),
(Type::Integer, Value::Float8(f)) => format!("{:.0}", f.trunc()),
(Type::Integer, Value::Float4(f)) => format!("{}", f as i64),
(Type::Integer, Value::Float8(f)) => format!("{}", f as i64),
// This is so wrong, but sqlite needs it.
(Type::Integer, Value::Text(_)) => "0".to_string(),
(Type::Integer, Value::Bool(b)) => i8::from(b).to_string(),
Expand Down
2 changes: 1 addition & 1 deletion test/sqllogictest/arithmetic.slt
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ SELECT 1 + CAST ('5' AS double precision)
----
6

query II
query TT
SELECT CAST ('+Inf' AS double precision), CAST ('inf' AS double precision)
----
inf inf
Expand Down

0 comments on commit 70b3b4c

Please sign in to comment.