Repository: pingcap/tidb (Go)

Issue:
Support from_days/to_days in TiFlash
https://github.com/pingcap/tiflash/issues/4678

## Feature Request

**Is your feature request related to a problem? Please describe:**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->

**Describe the feature you'd like:**
<!-- A clear and concise description of what you want to happen. -->
Support `from_days` in TiFlash
MySQL doc:
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_from-days
TiDB implementation:
https://github.com/pingcap/tidb/blob/5889d4c4e9357a515c472fcf12bb3624fbb00f9e/expression/builtin_time.go#L887
Support `to_days` in TiFlash
MySQL doc:
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_to-days
TiDB implementation:
https://github.com/pingcap/tidb/blob/5889d4c4e9357a515c472fcf12bb3624fbb00f9e/expression/builtin_time.go#L7027
**Describe alternatives you've considered:**
<!-- A clear and concise description of any alternative solutions or features you've considered. -->

**Teachability, Documentation, Adoption, Migration Strategy:**
<!-- If you can, explain some scenarios how users might use this, situations it would be helpful in. Any API designs, mockups, or diagrams are also helpful. -->



Discussion:

Patch:
diff --git a/expression/expression.go b/expression/expression.go
index 7ed4c007420ea..586b876719fd2 100644
--- a/expression/expression.go
+++ b/expression/expression.go
@@ -1057,6 +1057,7 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool {
 		ast.Date, ast.Year, ast.Month, ast.Day, ast.Quarter, ast.DayName, ast.MonthName,
 		ast.DateDiff, ast.TimestampDiff, ast.DateFormat, ast.FromUnixTime,
 		ast.DayOfWeek, ast.DayOfMonth, ast.DayOfYear, ast.LastDay, ast.WeekOfYear, ast.ToSeconds,
+		ast.FromDays, ast.ToDays,
 
 		ast.Sqrt, ast.Log, ast.Log2, ast.Log10, ast.Ln, ast.Exp, ast.Pow, ast.Sign,
 		ast.Radians, ast.Degrees, ast.Conv, ast.CRC32,


Test patch:
diff --git a/expression/expr_to_pb_test.go b/expression/expr_to_pb_test.go
index a6f4fc0534193..509f75a6c736d 100644
--- a/expression/expr_to_pb_test.go
+++ b/expression/expr_to_pb_test.go
@@ -882,6 +882,16 @@ func TestExprPushDownToFlash(t *testing.T) {
 	require.Equal(t, tipb.ScalarFuncSig_ConcatWS, function.(*ScalarFunction).Function.PbCode())
 	exprs = append(exprs, function)
 
+	function, err = NewFunction(mock.NewContext(), ast.FromDays, types.NewFieldType(mysql.TypeDate), intColumn)
+	require.NoError(t, err)
+	require.Equal(t, tipb.ScalarFuncSig_FromDays, function.(*ScalarFunction).Function.PbCode())
+	exprs = append(exprs, function)
+
+	function, err = NewFunction(mock.NewContext(), ast.ToDays, types.NewFieldType(mysql.TypeLonglong), datetimeColumn)
+	require.NoError(t, err)
+	require.Equal(t, tipb.ScalarFuncSig_ToDays, function.(*ScalarFunction).Function.PbCode())
+	exprs = append(exprs, function)
+
 	// StrToDateDateTime
 	function, err = NewFunction(mock.NewContext(), ast.StrToDate, types.NewFieldType(mysql.TypeDatetime), stringColumn, stringColumn)
 	require.NoError(t, err)
@@ -1368,7 +1378,7 @@ func TestExprOnlyPushDownToTiKV(t *testing.T) {
 	sc := new(stmtctx.StatementContext)
 	client := new(mock.Client)
 
-	function, err := NewFunction(mock.NewContext(), "from_days", types.NewFieldType(mysql.TypeLonglong), genColumn(mysql.TypeDatetime, 1))
+	function, err := NewFunction(mock.NewContext(), "uuid", types.NewFieldType(mysql.TypeLonglong))
 	require.NoError(t, err)
 	var exprs = make([]Expression, 0)
 	exprs = append(exprs, function)