func CastFuncFactory(tp *types.FieldType) (BuiltinFunc, error) {
	switch tp.Tp {
	// Parser has restricted this.
	case mysql.TypeString, mysql.TypeDuration, mysql.TypeDatetime,
		mysql.TypeDate, mysql.TypeLonglong, mysql.TypeNewDecimal:
		return func(args []types.Datum, ctx context.Context) (d types.Datum, err error) {
			d = args[0]
			if d.IsNull() {
				return
			}
			return d.ConvertTo(ctx.GetSessionVars().StmtCtx, tp)
		}, nil
	}
	return nil, errors.Errorf("unknown cast type - %v", tp)
}
// CastFuncFactory produces builtin function according to field types.
// See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html
CastFuncFactory produces builtin function according to field types.
// CastFuncFactory produces builtin function according to field types . // See https : // dev . mysql . com / doc / refman / 5 . 7 / en / cast - functions . html
func CastFuncFactory(tp *types.FieldType) (BuiltinFunc, error) {
	switch tp.Tp {
	case mysql.TypeString, mysql.TypeDuration, mysql.TypeDatetime,
		mysql.TypeDate, mysql.TypeLonglong, mysql.TypeNewDecimal:
		return func(args []types.Datum, ctx context.Context) (d types.Datum, err error) {
			d = args[0]
			if d.IsNull() {
				return
			}
			return d.ConvertTo(ctx.GetSessionVars().StmtCtx, tp)
		}, nil
	}
	return nil, errors.Errorf("unknown cast type - %v", tp)
}
func CastFuncFactory ( tp * types . FieldType ) ( BuiltinFunc , error ) { switch tp . Tp { case mysql . TypeString , mysql . TypeDuration , mysql . TypeDatetime , mysql . TypeDate , mysql . TypeLonglong , mysql . TypeNewDecimal : return func ( args [ ] types . Datum , ctx context . Context ) ( d types . Datum , err error ) { d = args [ 0 ] if d . IsNull ( ) { return } return d . ConvertTo ( ctx . GetSessionVars ( ) . StmtCtx , tp ) } , nil } return nil , errors . Errorf ( " " , tp ) }
CastFuncFactory produces builtin function according to field types.
CastFuncFactory produces builtin function according to field types .
// Parser has restricted this.