Skip to content

Commit

Permalink
expression: fixed json type for truncate (#13064)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekalinin authored and sre-bot committed Dec 4, 2019
1 parent bb02b70 commit 9d582b6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion 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,6 +1796,8 @@ 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")
}

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

0 comments on commit 9d582b6

Please sign in to comment.