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 double #11443

Merged
merged 6 commits into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion expression/builtin_cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func (b *builtinCastIntAsRealSig) evalReal(row chunk.Row) (res float64, isNull b
if isNull || err != nil {
return res, isNull, err
}
if !mysql.HasUnsignedFlag(b.tp.Flag) {
if !mysql.HasUnsignedFlag(b.tp.Flag) && !mysql.HasUnsignedFlag(b.args[0].GetType().Flag) {
zz-jason marked this conversation as resolved.
Show resolved Hide resolved
res = float64(val)
} else if b.inUnion && val < 0 {
res = 0
Expand Down
23 changes: 23 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2330,6 +2330,29 @@ func (s *testIntegrationSuite) TestBuiltin(c *C) {
result = tk.MustQuery("select cast(1 as signed int)")
result.Check(testkit.Rows("1"))

// test cast as double
result = tk.MustQuery("select cast(1 as double)")
result.Check(testkit.Rows("1"))
result = tk.MustQuery("select cast(1.1 as double)")
result.Check(testkit.Rows("1.1"))
result = tk.MustQuery("select cast(1.1 as double)")
result.Check(testkit.Rows("1.1"))
result = tk.MustQuery("select cast('123.321' as double)")
result.Check(testkit.Rows("123.321"))
result = tk.MustQuery("select cast(-1 as double)")
result.Check(testkit.Rows("-1"))
result = tk.MustQuery("select cast(null as double)")
result.Check(testkit.Rows("<nil>"))
/* There is something wrong in showing float number.
The testkit gets the format 'f' (-ddd.dddd, no exponent),
but we need the format 'e' (-d.dddde±dd, a decimal exponent).

result = tk.MustQuery("select cast(12345678901234567890 as double)")
result.Check(testkit.Rows("1.2345678901234567e19"))
result = tk.MustQuery("select cast(cast(-1 as unsigned) as double)")
result.Check(testkit.Rows("1.8446744073709552e19"))
*/

// 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-20190726023712-ca2f45b420fd
github.com/pingcap/parser v0.0.0-20190726045944-46d1b3d054b2
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-20190726023712-ca2f45b420fd h1:vFLYlcLyvWrIN+3Y9uPExiisDjeRCPh1Vic0vnkxBMs=
github.com/pingcap/parser v0.0.0-20190726023712-ca2f45b420fd/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
github.com/pingcap/parser v0.0.0-20190726045944-46d1b3d054b2 h1:uPLL91Kf8Sh86ht/ijNj6iUWw7JBArTcJtyn8aR+uDs=
github.com/pingcap/parser v0.0.0-20190726045944-46d1b3d054b2/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