Skip to content

Commit

Permalink
types: fix compare float64 with float64 in json (#21709)
Browse files Browse the repository at this point in the history
Signed-off-by: lzmhhh123 <lzmhhh123@gmail.com>
  • Loading branch information
lzmhhh123 authored Dec 15, 2020
1 parent 8935ad1 commit b0d9934
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4404,6 +4404,13 @@ func (s *testIntegrationSuite) TestFuncJSON(c *C) {

// #16267
tk.MustQuery(`select json_array(922337203685477580) = json_array(922337203685477581);`).Check(testkit.Rows("0"))

// #10461
tk.MustExec("drop table if exists tx1")
tk.MustExec("create table tx1(id int key, a double, b double, c double, d double)")
tk.MustExec("insert into tx1 values (1, 0.1, 0.2, 0.3, 0.0)")
tk.MustQuery("select a+b, c from tx1").Check(testkit.Rows("0.30000000000000004 0.3"))
tk.MustQuery("select json_array(a+b) = json_array(c) from tx1").Check(testkit.Rows("0"))
}

func (s *testIntegrationSuite) TestColumnInfoModified(c *C) {
Expand Down
12 changes: 11 additions & 1 deletion types/json/binary_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,16 @@ func compareInt64(x int64, y int64) int {
return 1
}

func compareFloat64(x float64, y float64) int {
if x < y {
return -1
} else if x == y {
return 0
}

return 1
}

func compareUint64(x uint64, y uint64) int {
if x < y {
return -1
Expand Down Expand Up @@ -712,7 +722,7 @@ func CompareBinary(left, right BinaryJSON) int {
case TypeCodeUint64:
cmp = compareFloat64Uint64(left.GetFloat64(), right.GetUint64())
case TypeCodeFloat64:
cmp = compareFloat64PrecisionLoss(left.GetFloat64(), right.GetFloat64())
cmp = compareFloat64(left.GetFloat64(), right.GetFloat64())
}
case TypeCodeString:
cmp = bytes.Compare(left.GetString(), right.GetString())
Expand Down

0 comments on commit b0d9934

Please sign in to comment.