Skip to content

Commit

Permalink
push Concat and UnixTimestamp to TiFlash (#24845)
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleFall authored May 23, 2021
1 parent 6b126a7 commit 4a1299d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
27 changes: 27 additions & 0 deletions expression/expr_to_pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,14 +742,41 @@ func (s *testEvaluatorSuite) TestExprPushDownToFlash(c *C) {
c.Assert(err, IsNil)
exprs = append(exprs, function)

// ScalarFuncSig_RoundReal
function, err = NewFunction(mock.NewContext(), ast.Round, types.NewFieldType(mysql.TypeDouble), realColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// ScalarFuncSig_RoundInt
function, err = NewFunction(mock.NewContext(), ast.Round, types.NewFieldType(mysql.TypeLonglong), intColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// concat
function, err = NewFunction(mock.NewContext(), ast.Concat, types.NewFieldType(mysql.TypeString), stringColumn, intColumn, realColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// UnixTimestampCurrent
function, err = NewFunction(mock.NewContext(), ast.UnixTimestamp, types.NewFieldType(mysql.TypeLonglong))
c.Assert(err, IsNil)
_, ok := function.(*Constant)
c.Assert(ok, IsTrue)

// UnixTimestampInt
datetimeColumn.RetType.Decimal = 0
function, err = NewFunction(mock.NewContext(), ast.UnixTimestamp, types.NewFieldType(mysql.TypeLonglong), datetimeColumn)
c.Assert(err, IsNil)
c.Assert(function.(*ScalarFunction).Function.PbCode(), Equals, tipb.ScalarFuncSig_UnixTimestampInt)
exprs = append(exprs, function)

// UnixTimestampDecimal
datetimeColumn.RetType.Decimal = types.UnspecifiedLength
function, err = NewFunction(mock.NewContext(), ast.UnixTimestamp, types.NewFieldType(mysql.TypeNewDecimal), datetimeColumn)
c.Assert(err, IsNil)
c.Assert(function.(*ScalarFunction).Function.PbCode(), Equals, tipb.ScalarFuncSig_UnixTimestampDec)
exprs = append(exprs, function)

canPush := CanExprsPushDown(sc, exprs, client, kv.TiFlash)
c.Assert(canPush, Equals, true)

Expand Down
3 changes: 2 additions & 1 deletion expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,9 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool {
ast.GE, ast.LE, ast.EQ, ast.NE, ast.LT, ast.GT, ast.In, ast.IsNull, ast.Like,
ast.Plus, ast.Minus, ast.Div, ast.Mul, ast.Abs, /*ast.Mod,*/
ast.If, ast.Ifnull, ast.Case,
ast.Concat,
ast.Month,
ast.TimestampDiff, ast.DateFormat, ast.FromUnixTime,
ast.TimestampDiff, ast.DateFormat, ast.FromUnixTime, ast.UnixTimestamp,
ast.JSONLength:
return true
case ast.Substr, ast.Substring, ast.Left, ast.Right, ast.CharLength:
Expand Down

0 comments on commit 4a1299d

Please sign in to comment.