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

expression: fixed json type for truncate #13064

Merged
merged 20 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
6 changes: 6 additions & 0 deletions expression/builtin_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,10 @@ func (c *truncateFunctionClass) getFunction(ctx sessionctx.Context, args []Expre
if argTp == types.ETTimestamp || argTp == types.ETDatetime || argTp == types.ETDuration || argTp == types.ETString {
argTp = types.ETReal
}
// MySQL compatibility
if argTp == types.ETJson {
argTp = types.ETInt
}
ekalinin marked this conversation as resolved.
Show resolved Hide resolved

bf := newBaseBuiltinFuncWithTp(ctx, args, argTp, argTp, types.ETInt)

Expand All @@ -1762,6 +1766,8 @@ func (c *truncateFunctionClass) getFunction(ctx sessionctx.Context, args []Expre
sig = &builtinTruncateRealSig{bf}
case types.ETDecimal:
sig = &builtinTruncateDecimalSig{bf}
default:
return nil, errIncorrectArgs.GenWithStackByArgs("truncate")
wshwsh12 marked this conversation as resolved.
Show resolved Hide resolved
}

return sig, nil
Expand Down
3 changes: 3 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ func (s *testIntegrationSuite2) TestMathBuiltin(c *C) {
result = tk.MustQuery(`select truncate(d, -1), truncate(d, 1), truncate(d, -2), truncate(d, 2) from t;`)
result.Check(testkit.Rows("10 12.3 0 12.34"))

result = tk.MustQuery(`select truncate(json_array(), -1), truncate("cascasc", 1);`)
result.Check(testkit.Rows("0 0"))

// for pow
result = tk.MustQuery("SELECT POW('12', 2), POW(1.2e1, '2.0'), POW(12, 2.0);")
result.Check(testkit.Rows("144 144 144"))
Expand Down