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 18 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: 4 additions & 2 deletions expression/builtin_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,7 @@ func (c *truncateFunctionClass) getFunction(ctx sessionctx.Context, args []Expre
}

argTp := args[0].GetType().EvalType()
if argTp == types.ETTimestamp || argTp == types.ETDatetime || argTp == types.ETDuration || argTp == types.ETString {
if argTp.IsStringKind() {
argTp = types.ETReal
}

Expand All @@ -1796,7 +1796,9 @@ func (c *truncateFunctionClass) getFunction(ctx sessionctx.Context, args []Expre
case types.ETDecimal:
sig = &builtinTruncateDecimalSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_TruncateDecimal)
}
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