code: func CastValues(ctx sessionctx.Context, rec []types.Datum, cols []*Column) (err error) {
  	sc := ctx.GetSessionVars().StmtCtx
  	for _, c := range cols {
  		var converted types.Datum
  		converted, err = CastValue(ctx, rec[c.Offset], c.ToInfo())
  		if err != nil {
  			if sc.DupKeyAsWarning {
  				sc.AppendWarning(err)
  				logutil.Logger(context.Background()).Warn("CastValues failed", zap.Error(err))
  			} else {
  				return err
  			}
  		}
  		rec[c.Offset] = converted
  	}
  	return nil
  }
docs: // CastValues casts values based on columns type.