Skip to content

Commit

Permalink
expression: Add cast as json push down support for tiflash (#48550)
Browse files Browse the repository at this point in the history
close #48551
  • Loading branch information
SeaRise authored Nov 28, 2023
1 parent ccbd1b5 commit d0feede
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pkg/expression/expr_to_pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,44 @@ func TestExprPushDownToFlash(t *testing.T) {
require.NoError(t, err)
exprs = append(exprs, function)

// CastIntAsJson
function, err = NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeJSON), intColumn)
require.NoError(t, err)
exprs = append(exprs, function)

// CastRealAsJson
function, err = NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeJSON), realColumn)
require.NoError(t, err)
exprs = append(exprs, function)

// CastDecimalAsJson
function, err = NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeJSON), decimalColumn)
require.NoError(t, err)
exprs = append(exprs, function)

// CastStringAsJson
function, err = NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeJSON), stringColumn)
require.NoError(t, err)
exprs = append(exprs, function)
function, err = NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeJSON), binaryStringColumn)
require.NoError(t, err)
exprs = append(exprs, function)

// CastTimeAsJson
function, err = NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeJSON), datetimeColumn)
require.NoError(t, err)
exprs = append(exprs, function)

// CastDurationAsJson
function, err = NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeJSON), durationColumn)
require.NoError(t, err)
exprs = append(exprs, function)

// CastJsonAsJson
function, err = NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeJSON), jsonColumn)
require.NoError(t, err)
exprs = append(exprs, function)

pushed, remained = PushDownExprs(ctx, exprs, client, kv.TiFlash)
require.Len(t, pushed, len(exprs))
require.Len(t, remained, 0)
Expand Down
3 changes: 3 additions & 0 deletions pkg/expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,9 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool {
return function.GetArgs()[0].GetType().GetType() != mysql.TypeYear
case tipb.ScalarFuncSig_CastTimeAsDuration:
return retType.GetType() == mysql.TypeDuration
case tipb.ScalarFuncSig_CastIntAsJson, tipb.ScalarFuncSig_CastRealAsJson, tipb.ScalarFuncSig_CastDecimalAsJson, tipb.ScalarFuncSig_CastStringAsJson,
tipb.ScalarFuncSig_CastTimeAsJson, tipb.ScalarFuncSig_CastDurationAsJson, tipb.ScalarFuncSig_CastJsonAsJson:
return true
}
case ast.DateAdd, ast.AddDate:
switch function.Function.PbCode() {
Expand Down

0 comments on commit d0feede

Please sign in to comment.