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

parser: support cast as float #11519

Merged
merged 3 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 28 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2372,6 +2372,34 @@ func (s *testIntegrationSuite) TestBuiltin(c *C) {
result = tk.MustQuery("select cast(0x12345678 as double)")
result.Check(testkit.Rows("305419896"))

// test cast as float
result = tk.MustQuery("select cast(1 as float)")
result.Check(testkit.Rows("1"))
result = tk.MustQuery("select cast(cast(12345 as unsigned) as float)")
result.Check(testkit.Rows("12345"))
result = tk.MustQuery("select cast(1.1 as float) = 1.1")
result.Check(testkit.Rows("1"))
result = tk.MustQuery("select cast(-1.1 as float) = -1.1")
result.Check(testkit.Rows("1"))
result = tk.MustQuery("select cast('123.321' as float) =123.321")
result.Check(testkit.Rows("1"))
result = tk.MustQuery("select cast('12345678901234567890' as float) = 1.2345678901234567e19")
result.Check(testkit.Rows("1"))
result = tk.MustQuery("select cast(-1 as float)")
result.Check(testkit.Rows("-1"))
result = tk.MustQuery("select cast(null as float)")
result.Check(testkit.Rows("<nil>"))
result = tk.MustQuery("select cast(12345678901234567890 as float) = 1.2345678901234567e19")
result.Check(testkit.Rows("1"))
result = tk.MustQuery("select cast(cast(-1 as unsigned) as float) = 1.8446744073709552e19")
result.Check(testkit.Rows("1"))
result = tk.MustQuery("select cast(1e100 as float(40)) = 1e100")
result.Check(testkit.Rows("1"))
result = tk.MustQuery("select cast(123456789012345678901234567890 as float(40)) = 1.2345678901234568e29")
result.Check(testkit.Rows("1"))
result = tk.MustQuery("select cast(0x12345678 as float(40)) = 305419896")
result.Check(testkit.Rows("1"))

// test cast time as decimal overflow
tk.MustExec("drop table if exists t1")
tk.MustExec("create table t1(s1 time);")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ require (
github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e
github.com/pingcap/kvproto v0.0.0-20190703131923-d9830856b531
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596
github.com/pingcap/parser v0.0.0-20190730091357-5238015a66f8
github.com/pingcap/parser v0.0.0-20190801033650-4849eb88ee66
github.com/pingcap/pd v0.0.0-20190712044914-75a1f9f3062b
github.com/pingcap/tidb-tools v2.1.3-0.20190321065848-1e8b48f5c168+incompatible
github.com/pingcap/tipb v0.0.0-20190428032612-535e1abaa330
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ github.com/pingcap/kvproto v0.0.0-20190703131923-d9830856b531/go.mod h1:QMdbTAXC
github.com/pingcap/log v0.0.0-20190214045112-b37da76f67a7/go.mod h1:xsfkWVaFVV5B8e1K9seWfyJWFrIhbtUTAD8NV1Pq3+w=
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596 h1:t2OQTpPJnrPDGlvA+3FwJptMTt6MEPdzK1Wt99oaefQ=
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw=
github.com/pingcap/parser v0.0.0-20190730091357-5238015a66f8 h1:Htdqrie9rVA/x2yqnXjqYu+VNvff3Cnj7clCNvIyXVU=
github.com/pingcap/parser v0.0.0-20190730091357-5238015a66f8/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
github.com/pingcap/parser v0.0.0-20190801033650-4849eb88ee66 h1:RQlXn268eNxAh4ZcDGHSdDkv20x1eJDQu8vYvQh3x5c=
github.com/pingcap/parser v0.0.0-20190801033650-4849eb88ee66/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
github.com/pingcap/pd v0.0.0-20190712044914-75a1f9f3062b h1:oS9PftxQqgcRouKhhdaB52tXhVLEP7Ng3Qqsd6Z18iY=
github.com/pingcap/pd v0.0.0-20190712044914-75a1f9f3062b/go.mod h1:3DlDlFT7EF64A1bmb/tulZb6wbPSagm5G4p1AlhaEDs=
github.com/pingcap/tidb-tools v2.1.3-0.20190321065848-1e8b48f5c168+incompatible h1:MkWCxgZpJBgY2f4HtwWMMFzSBb3+JPzeJgF3VrXE/bU=
Expand Down