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 committed Jun 18, 2021
1 parent 744217d commit 07c9b2b
Showing 1 changed file with 2 additions and 2 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

0 comments on commit 07c9b2b

Please sign in to comment.