From aea67a7c9c9711c8f61c22f6040481fad282eec0 Mon Sep 17 00:00:00 2001 From: SeaRise Date: Mon, 13 Nov 2023 16:05:10 +0800 Subject: [PATCH 1/2] pushdown cast --- pkg/expression/expr_to_pb_test.go | 38 +++++++++++++++++++++++++++++++ pkg/expression/expression.go | 3 +++ 2 files changed, 41 insertions(+) diff --git a/pkg/expression/expr_to_pb_test.go b/pkg/expression/expr_to_pb_test.go index c07f4bfa3d05a..9e980bd2885bc 100644 --- a/pkg/expression/expr_to_pb_test.go +++ b/pkg/expression/expr_to_pb_test.go @@ -1294,6 +1294,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) + + // CastDurationAsJson + function, err = NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeJSON), jsonColumn) + require.NoError(t, err) + exprs = append(exprs, function) + pushed, remained = PushDownExprs(sc, exprs, client, kv.TiFlash) require.Len(t, pushed, len(exprs)) require.Len(t, remained, 0) diff --git a/pkg/expression/expression.go b/pkg/expression/expression.go index 63bf687a1c712..86482e4b9aa5b 100644 --- a/pkg/expression/expression.go +++ b/pkg/expression/expression.go @@ -1226,6 +1226,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() { From ffa2478e3ecd06070f4e0ce1d31ba8d8beae16fe Mon Sep 17 00:00:00 2001 From: SeaRise Date: Tue, 28 Nov 2023 08:22:08 +0800 Subject: [PATCH 2/2] Update pkg/expression/expr_to_pb_test.go Co-authored-by: xufei --- pkg/expression/expr_to_pb_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/expression/expr_to_pb_test.go b/pkg/expression/expr_to_pb_test.go index 9e980bd2885bc..1d112923d1eeb 100644 --- a/pkg/expression/expr_to_pb_test.go +++ b/pkg/expression/expr_to_pb_test.go @@ -1327,7 +1327,7 @@ func TestExprPushDownToFlash(t *testing.T) { require.NoError(t, err) exprs = append(exprs, function) - // CastDurationAsJson + // CastJsonAsJson function, err = NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeJSON), jsonColumn) require.NoError(t, err) exprs = append(exprs, function)