Merge branch 'master' into qiuyesuifeng/update-vendor

This commit is contained in:
cuiqiu
2016-05-10 11:22:19 +08:00
2 changed files with 5 additions and 0 deletions

View File

@ -258,6 +258,10 @@ func (v *typeInferrer) handleFuncCallExpr(x *ast.FuncCallExpr) {
switch x.FnName.L {
case "abs", "ifnull", "nullif":
tp = x.Args[0].GetType()
// TODO: We should cover all types.
if x.FnName.L == "abs" && tp.Tp == mysql.TypeDatetime {
tp = types.NewFieldType(mysql.TypeDouble)
}
case "pow", "power", "rand":
tp = types.NewFieldType(mysql.TypeDouble)
case "curdate", "current_date", "date":

View File

@ -82,6 +82,7 @@ func (ts *testTypeInferrerSuite) TestInferType(c *C) {
{"count(c1)", mysql.TypeLonglong, charset.CharsetBin},
{"abs(1)", mysql.TypeLonglong, charset.CharsetBin},
{"abs(1.1)", mysql.TypeNewDecimal, charset.CharsetBin},
{"abs(cast(\"20150817015609\" as DATETIME))", mysql.TypeDouble, charset.CharsetBin},
{"IF(1>2,2,3)", mysql.TypeLonglong, charset.CharsetBin},
{"IFNULL(1,0)", mysql.TypeLonglong, charset.CharsetBin},
{"POW(2,2)", mysql.TypeDouble, charset.CharsetBin},