expression: Support mathematical functions pushdown to tiflash (#25596)

This commit is contained in:
chAnge
2021-08-05 14:55:13 +08:00
committed by GitHub
parent 019fab3b0a
commit ebb7d70268
2 changed files with 55 additions and 4 deletions

View File

@ -755,7 +755,7 @@ func (s *testEvaluatorSuite) TestExprPushDownToFlash(c *C) {
c.Assert(err, IsNil)
exprs = append(exprs, function)
// ScalarFuncSig_CeilDecimalToDecimal
// ScalarFuncSig_CeilDecToDec
function, err = NewFunction(mock.NewContext(), ast.Ceil, types.NewFieldType(mysql.TypeNewDecimal), decimalColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)
@ -770,16 +770,66 @@ func (s *testEvaluatorSuite) TestExprPushDownToFlash(c *C) {
c.Assert(err, IsNil)
exprs = append(exprs, function)
// ScalarFuncSig_FloorDecimalToInt
// ScalarFuncSig_FloorDecToInt
function, err = NewFunction(mock.NewContext(), ast.Floor, types.NewFieldType(mysql.TypeLonglong), decimalColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)
// ScalarFuncSig_FloorDecimalToDecimal
// ScalarFuncSig_FloorDecToDec
function, err = NewFunction(mock.NewContext(), ast.Floor, types.NewFieldType(mysql.TypeNewDecimal), decimalColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)
// ScalarFuncSig_Log1Arg
function, err = NewFunction(mock.NewContext(), ast.Log, types.NewFieldType(mysql.TypeDouble), realColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)
// ScalarFuncSig_Log2Args
function, err = NewFunction(mock.NewContext(), ast.Log, types.NewFieldType(mysql.TypeDouble), realColumn, realColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)
// ScalarFuncSig_Log2
function, err = NewFunction(mock.NewContext(), ast.Log2, types.NewFieldType(mysql.TypeDouble), realColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)
// ScalarFuncSig_Log10
function, err = NewFunction(mock.NewContext(), ast.Log10, types.NewFieldType(mysql.TypeDouble), realColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)
// ScalarFuncSig_Exp
function, err = NewFunction(mock.NewContext(), ast.Exp, types.NewFieldType(mysql.TypeDouble), realColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)
// ScalarFuncSig_Pow
function, err = NewFunction(mock.NewContext(), ast.Pow, types.NewFieldType(mysql.TypeDouble), realColumn, realColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)
// ScalarFuncSig_Radians
function, err = NewFunction(mock.NewContext(), ast.Radians, types.NewFieldType(mysql.TypeDouble), realColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)
// ScalarFuncSig_Degrees
function, err = NewFunction(mock.NewContext(), ast.Degrees, types.NewFieldType(mysql.TypeDouble), realColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)
// ScalarFuncSig_CRC32
function, err = NewFunction(mock.NewContext(), ast.CRC32, types.NewFieldType(mysql.TypeLonglong), stringColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)
// ScalarFuncSig_Conv
function, err = NewFunction(mock.NewContext(), ast.Conv, types.NewFieldType(mysql.TypeDouble), stringColumn, intColumn, intColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)
// Replace
function, err = NewFunction(mock.NewContext(), ast.Replace, types.NewFieldType(mysql.TypeString), stringColumn, stringColumn, stringColumn)
c.Assert(err, IsNil)

View File

@ -1017,7 +1017,8 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool {
ast.Concat, ast.ConcatWS,
ast.Year, ast.Month, ast.Day,
ast.DateDiff, ast.TimestampDiff, ast.DateFormat, ast.FromUnixTime,
ast.Sqrt,
ast.Sqrt, ast.Log, ast.Log2, ast.Log10, ast.Ln, ast.Exp, ast.Pow, ast.Sign,
ast.Radians, ast.Degrees, ast.Conv, ast.CRC32,
ast.JSONLength:
return true
case ast.Substr, ast.Substring, ast.Left, ast.Right, ast.CharLength: