Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: fix compare float64 with float64 in json #21709

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use compareFloat64PrecisionLoss

Copy link
Contributor Author

@lzmhhh123 lzmhhh123 Dec 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The origin code used it. Then got the wrong result.

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