ronantakizawa/codereview-bench huggingface dataset:
Repository: pingcap/tidb
File: pkg/types/datum.go (Go)

Code before:
	})
	if err != nil {
		err = errors.Trace(err)
	}
	return err
}

// Check if a string is considered printable
//
// Checks
// 1. Must be valid UTF-8
// 2. Must not contain control characters like NUL (0x0) and backspace (0x8)
func isPrintable(s string) bool {
	if !utf8.ValidString(s) {
		return false
	}
	for _, r := range s {
		if unicode.IsControl(r) {
			return false
		}
	}
	return true
}

// DatumsToString converts several datums to formatted string.
func DatumsToString(datums []Datum, handleSpecialValue bool) (string, error) {
	n := len(datums)
	builder := &strings.Builder{}
	builder.Grow(8 * n)
	if n > 1 {
		builder.WriteString("(")
	}
	for i, datum := range datums {
		if i > 0 {
			builder.WriteString(", ")
		}
		if handleSpecialValue {
			switch datum.Kind() {
			case KindNull:
				builder.WriteString("NULL")
				continue
			case KindMinNotNull:
				builder.WriteString("-inf")
				continue
			case KindMaxValue:
				builder.WriteString("+inf")
				continue
			}
		}
		str, err := datum.ToString()
		if err != nil {

Review comment (performance):
what's the performance penalty introduced by this `isPrintable`

can we have a `binaryAsHex` param(like `--skip-binary-as-hex` of mysql client) to the function? if we use import-into on a datasets with many conflicts, it will record all conflicts as string by calling it, not sure how this can affects performance if most column data are normal strings

Code after:
	})
	if err != nil {
		err = errors.Trace(err)
	}
	return err
}

// Check if a string is considered printable
//
// Checks
// 1. Must be valid UTF-8
// 2. Must not contain control characters like NUL (0x0) and backspace (0x8)
func isPrintable(s string) bool {
	if !utf8.ValidString(s) {
		return false
	}
	for _, r := range s {
		if unicode.IsControl(r) {
			return false
		}
	}
	return true
}

// DatumsToString converts several datums to formatted string.
func DatumsToString(datums []Datum, handleSpecialValue bool) (string, error) {
	return datumsToString(datums, handleSpecialValue, false)
}

// DatumsToStringSmart is like DatumsToString, but with smart detection of non-printable data
func DatumsToStringSmart(datums []Datum, handleSpecialValue bool) (string, error) {
	return datumsToString(datums, handleSpecialValue, true)
}

func datumsToString(datums []Datum, handleSpecialValue bool, binaryAsHex bool) (string, error) {
	n := len(datums)
	builder := &strings.Builder{}
	builder.Grow(8 * n)
	if n > 1 {
		builder.WriteString("(")
	}
	for i, datum := range datums {
		if i > 0 {
			builder.WriteString(", ")
		}
		if handleSpecialValue {
			switch datum.Kind() {
			case KindNull:
				builder.WriteString("NULL")
				continue
			case KindMinNotNull:
Repository: pingcap/tidb
File: pkg/statistics/handle/usage/session_stats_collect.go (Go)

Code before:

// NewTableDelta creates a new TableDelta.
func NewTableDelta() *TableDelta {
	return &TableDelta{
		delta: make(map[int64]variable.TableDelta),
	}
}

// Reset resets the TableDelta.
func (m *TableDelta) Reset() {
	m.lock.Lock()
	defer m.lock.Unlock()
	m.delta = make(map[int64]variable.TableDelta)
}

// GetDeltaAndReset gets the delta and resets the TableDelta.
func (m *TableDelta) GetDeltaAndReset() map[int64]variable.TableDelta {
	m.lock.Lock()
	defer m.lock.Unlock()
	ret := m.delta
	m.delta = make(map[int64]variable.TableDelta)
	return ret
}

// Update updates the delta of the table.
func (m *TableDelta) Update(id int64, delta int64, count int64) {
	m.lock.Lock()
	defer m.lock.Unlock()
	item := m.delta[id]
	item.Delta += delta
	item.Count += count
	m.delta[id] = item
}

// Merge merges the deltaMap into the TableDelta.
func (m *TableDelta) Merge(deltaMap map[int64]variable.TableDelta) {
	if len(deltaMap) == 0 {
		return
	}
	m.lock.Lock()
	defer m.lock.Unlock()
	for id, incoming := range deltaMap {
		item := m.delta[id]
		item.MergeFrom(incoming)
		m.delta[id] = item
	}
}

// StatsUsage maps (tableID, columnID) to the last time when the column stats are used(needed).
// All methods of it are thread-safe.
type StatsUsage struct {

Review comment (suggestion):
Not really part of this PR, but a bit confusing that the TableDelta is containing a map of `variable.TableDelta`, would be less confusing if it was TableDeltaMap or something else... Not the same name... :)

Code after:

// NewTableDelta creates a new TableDelta.
func NewTableDelta() *TableDelta {
	return &TableDelta{
		delta: make(map[int64]variable.TableDelta),
	}
}

// Reset resets the TableDelta.
func (m *TableDelta) Reset() {
	m.lock.Lock()
	defer m.lock.Unlock()
	m.delta = make(map[int64]variable.TableDelta)
}

// GetDeltaAndReset gets the delta and resets the TableDelta.
func (m *TableDelta) GetDeltaAndReset() map[int64]variable.TableDelta {
	m.lock.Lock()
	defer m.lock.Unlock()
	ret := m.delta
	m.delta = make(map[int64]variable.TableDelta)
	return ret
}

// Update updates the delta of the table.
func (m *TableDelta) Update(id int64, delta int64, count int64) {
	intest.Assert(id > 0, "table ID should be greater than 0")
	m.lock.Lock()
	defer m.lock.Unlock()
	item := m.delta[id]
	item.Delta += delta
	item.Count += count
	m.delta[id] = item
}

// Merge merges the deltaMap into the TableDelta.
func (m *TableDelta) Merge(deltaMap map[int64]variable.TableDelta) {
	if len(deltaMap) == 0 {
		return
	}
	m.lock.Lock()
	defer m.lock.Unlock()
	for id, incoming := range deltaMap {
		item := m.delta[id]
		item.MergeFrom(incoming)
		m.delta[id] = item
	}
}

// StatsUsage maps (tableID, columnID) to the last time when the column stats are used(needed).
// All methods of it are thread-safe.
Repository: pingcap/tidb
File: pkg/executor/plan_replayer.go (Go)

Code before:
func loadStats(ctx sessionctx.Context, f *zip.File) error {
	jsonTbl := &util.JSONTable{}
	r, err := f.Open()
	if err != nil {
		return errors.AddStack(err)
	}
	//nolint: errcheck
	defer r.Close()
	buf := new(bytes.Buffer)
	_, err = buf.ReadFrom(r)
	if err != nil {
		if f == nil || f.Name == "" {
			ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Join(errors.New("fail to read stats file"), err))
		} else {
			ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Join(fmt.Errorf("fail to read stats file %s", f.Name), err))
		}
		return nil
	}
	if err := json.Unmarshal(buf.Bytes(), jsonTbl); err != nil {
		ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Join(fmt.Errorf("fail to unmarshal stats JSON for file %s", f.Name), err))
		return nil
	}
	do := domain.GetDomain(ctx)
	h := do.StatsHandle()
	if h == nil {
		return errors.New("plan replayer: hanlde is nil")
	}
	return h.LoadStatsFromJSON(context.Background(), ctx.GetInfoSchema().(infoschema.InfoSchema), jsonTbl, 1)
}

// Update updates the data of the corresponding table.
func (e *PlanReplayerLoadInfo) Update(data []byte) error {
	b := bytes.NewReader(data)
	z, err := zip.NewReader(b, int64(len(data)))
	if err != nil {
		return errors.AddStack(err)
	}

	// load variable
	err = loadVariables(e.Ctx, z)
	if err != nil {
		return err
	}

	// build schema and table first
	var databaseSets map[string]struct{}
	databaseSets, err = e.createTable(z)
	if err != nil {
		return err
	}


Review comment (suggestion):
There is a spelling error in the error message. "hanlde" should be "handle".
```suggestion
		return errors.New("plan replayer: handle is nil")
```

Code after:
func loadStats(ctx sessionctx.Context, f *zip.File) error {
	jsonTbl := &util.JSONTable{}
	r, err := f.Open()
	if err != nil {
		return errors.AddStack(err)
	}
	//nolint: errcheck
	defer r.Close()
	buf := new(bytes.Buffer)
	_, err = buf.ReadFrom(r)
	if err != nil {
		if f == nil || f.Name == "" {
			ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Join(errors.New("fail to read stats file"), err))
		} else {
			ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Join(fmt.Errorf("fail to read stats file %s", f.Name), err))
		}
		return nil
	}
	if err := json.Unmarshal(buf.Bytes(), jsonTbl); err != nil {
		ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Join(fmt.Errorf("fail to unmarshal stats JSON for file %s", f.Name), err))
		return nil
	}
	do := domain.GetDomain(ctx)
	h := do.StatsHandle()
	if h == nil {
		return errors.New("plan replayer: handle is nil")
	}
	return h.LoadStatsFromJSON(context.Background(), ctx.GetInfoSchema().(infoschema.InfoSchema), jsonTbl, 0)
}

// Update updates the data of the corresponding table.
func (e *PlanReplayerLoadInfo) Update(data []byte) error {
	b := bytes.NewReader(data)
	z, err := zip.NewReader(b, int64(len(data)))
	if err != nil {
		return errors.AddStack(err)
	}

	// load variable
	err = loadVariables(e.Ctx, z)
	if err != nil {
		return err
	}

	// build schema and table first
	var databaseSets map[string]struct{}
	databaseSets, err = e.createTable(z)
	if err != nil {
		return err
	}
Repository: pingcap/tidb
File: pkg/util/httputil/http.go (Go)

Code before:
//	}
//	fmt.Println(resp.IP)
func GetJSON(ctx context.Context, client *http.Client, url string, v any) error {
	body, err := doGet(ctx, client, url)
	if err != nil {
		return errors.Trace(err)
	}
	defer body.Close()
	return errors.Trace(json.NewDecoder(body).Decode(v))
}

// GetText gets a page and returns its content as a string.
func GetText(client *http.Client, url string) (string, error) {
	body, err := doGet(context.Background(), client, url)
	if err != nil {
		return "", errors.Trace(err)
	}
	defer body.Close()
	data, err := io.ReadAll(body)
	if err != nil {
		return "", errors.Trace(err)
	}
	return string(data), nil
}

func doGet(ctx context.Context, client *http.Client, url string) (io.ReadCloser, error) {
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
	if err != nil {
		return nil, errors.Trace(err)
	}
	resp, err := client.Do(req)
	if err != nil {
		return nil, errors.Trace(err)
	}

	if resp.StatusCode != http.StatusOK {
		defer resp.Body.Close()
		body, err := io.ReadAll(resp.Body)
		if err != nil {
			return nil, errors.Trace(err)
		}
		return nil, errors.Errorf("get %s http status code != 200, message %s", url, string(body))
	}

	return resp.Body, nil
}


Review comment (suggestion):
The GetText function doesn't accept a context parameter, unlike GetJSON. This is inconsistent and prevents callers from controlling timeouts or cancellation for GetText operations. Consider adding a context parameter for consistency and to allow proper timeout/cancellation control.
```suggestion
func GetText(ctx context.Context, client *http.Client, url string) (string, error) {
	body, err := doGet(ctx, client, url)
```

Code after:
}

// GetJSON fetches a page and parses it as JSON. The parsed result will be
// stored into the `v`. The variable `v` must be a pointer to a type that can be
// unmarshalled from JSON.
//
// Example:
//
//	client := &http.Client{}
//	var resp struct { IP string }
//	if err := util.GetJSON(client, "http://api.ipify.org/?format=json", &resp); err != nil {
//		return errors.Trace(err)
//	}
//	fmt.Println(resp.IP)
func GetJSON(ctx context.Context, client *http.Client, url string, v any) error {
	body, err := doGet(ctx, client, url)
	if err != nil {
		return errors.Trace(err)
	}
	defer body.Close()
	return errors.Trace(json.NewDecoder(body).Decode(v))
}

// GetText gets a page and returns its content as a string.
func GetText(client *http.Client, url string) (string, error) {
	body, err := doGet(context.Background(), client, url)
	if err != nil {
		return "", errors.Trace(err)
	}
	defer body.Close()
	data, err := io.ReadAll(body)
	if err != nil {
		return "", errors.Trace(err)
	}
	return string(data), nil
}

func doGet(ctx context.Context, client *http.Client, url string) (io.ReadCloser, error) {
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
	if err != nil {
		return nil, errors.Trace(err)
	}
	resp, err := client.Do(req)
	if err != nil {
		return nil, errors.Trace(err)
	}

	if resp.StatusCode != http.StatusOK {
		defer resp.Body.Close()
		body, err := io.ReadAll(resp.Body)
		if err != nil {
Repository: pingcap/tidb
File: br/pkg/utils/register.go (Go)

Code before:
					}
					log.Warn("failed to put new kv", zap.Error(reputErr))
					tr.sleepRetryInterval(RegisterRetryInternal)
					continue
				}
				needReputKV = false
			}
			// recreate keepalive
			ch, err = tr.client.Lease.KeepAlive(ctx, tr.curLeaseID)
			if err != nil {
				select {
				case <-ctx.Done():
					return
				default:
				}
				log.Warn("failed to create new kv", zap.Error(err))
				tr.sleepRetryInterval(RegisterRetryInternal)
				continue
			}

			break RECREATE
		}
	}
}

func (tr *taskRegister) sleepRetryInterval(defaultInterval time.Duration) {
	interval := defaultInterval
	failpoint.Inject("brie-task-register-retry-interval", func(val failpoint.Value) {
		switch v := val.(type) {
		case int:
			if v > 0 {
				interval = time.Duration(v) * time.Millisecond
			}
		case int64:
			if v > 0 {
				interval = time.Duration(v) * time.Millisecond
			}
		case float64:
			if v > 0 {
				interval = time.Duration(v) * time.Millisecond
			}
		}
	})
	time.Sleep(interval)
}

// RegisterTask saves the task's information
type RegisterTask struct {
	Key     string
	LeaseID int64
	TTL     int64

Review comment (refactor):
Consider remove this argument as it is always `RegisterRetryInternal`.

Code after:
					}
					log.Warn("failed to put new kv", zap.Error(reputErr))
					tr.sleepRetryInterval()
					continue
				}
				needReputKV = false
			}
			// recreate keepalive
			ch, err = tr.client.Lease.KeepAlive(ctx, tr.curLeaseID)
			if err != nil {
				select {
				case <-ctx.Done():
					return
				default:
				}
				log.Warn("failed to create new kv", zap.Error(err))
				tr.sleepRetryInterval()
				continue
			}

			break RECREATE
		}
	}
}

func (tr *taskRegister) sleepRetryInterval() {
	interval := RegisterRetryInternal
	failpoint.Inject("brie-task-register-retry-interval", func(val failpoint.Value) {
		v, ok := val.(int)
		if ok && v > 0 {
			interval = time.Duration(v) * time.Millisecond
		}
	})
	time.Sleep(interval)
}

// RegisterTask saves the task's information
type RegisterTask struct {
	Key     string
	LeaseID int64
	TTL     int64
}

// MessageToUser marshal the task to user message
func (task RegisterTask) MessageToUser() string {
	return fmt.Sprintf("[ key: %s, lease-id: %x, ttl: %ds ]", task.Key, task.LeaseID, task.TTL)
}

type RegisterTasksList struct {
	Tasks []RegisterTask
}
Repository: pingcap/tidb
File: br/pkg/utils/register.go (Go)

Code before:
				tr.sleepRetryInterval(RegisterRetryInternal)
				continue
			}

			break RECREATE
		}
	}
}

func (tr *taskRegister) sleepRetryInterval(defaultInterval time.Duration) {
	interval := defaultInterval
	failpoint.Inject("brie-task-register-retry-interval", func(val failpoint.Value) {
		switch v := val.(type) {
		case int:
			if v > 0 {
				interval = time.Duration(v) * time.Millisecond
			}
		case int64:
			if v > 0 {
				interval = time.Duration(v) * time.Millisecond
			}
		case float64:
			if v > 0 {
				interval = time.Duration(v) * time.Millisecond
			}
		}
	})
	time.Sleep(interval)
}

// RegisterTask saves the task's information
type RegisterTask struct {
	Key     string
	LeaseID int64
	TTL     int64
}

// MessageToUser marshal the task to user message
func (task RegisterTask) MessageToUser() string {
	return fmt.Sprintf("[ key: %s, lease-id: %x, ttl: %ds ]", task.Key, task.LeaseID, task.TTL)
}

type RegisterTasksList struct {
	Tasks []RegisterTask
}

func (list RegisterTasksList) MessageToUser() string {
	var tasksMsgBuf strings.Builder
	for _, task := range list.Tasks {
		tasksMsgBuf.WriteString(task.MessageToUser())
		tasksMsgBuf.WriteString(", ")

Review comment (bug):
It seems `go-failpoint` won't generate `int64` or `float64` `Value`s.

https://github.com/pingcap/failpoint/blob/master/terms.go#L264-L297

Code after:
				tr.sleepRetryInterval()
				continue
			}

			break RECREATE
		}
	}
}

func (tr *taskRegister) sleepRetryInterval() {
	interval := RegisterRetryInternal
	failpoint.Inject("brie-task-register-retry-interval", func(val failpoint.Value) {
		v, ok := val.(int)
		if ok && v > 0 {
			interval = time.Duration(v) * time.Millisecond
		}
	})
	time.Sleep(interval)
}

// RegisterTask saves the task's information
type RegisterTask struct {
	Key     string
	LeaseID int64
	TTL     int64
}

// MessageToUser marshal the task to user message
func (task RegisterTask) MessageToUser() string {
	return fmt.Sprintf("[ key: %s, lease-id: %x, ttl: %ds ]", task.Key, task.LeaseID, task.TTL)
}

type RegisterTasksList struct {
	Tasks []RegisterTask
}

func (list RegisterTasksList) MessageToUser() string {
	var tasksMsgBuf strings.Builder
	for _, task := range list.Tasks {
		tasksMsgBuf.WriteString(task.MessageToUser())
		tasksMsgBuf.WriteString(", ")
	}
	return tasksMsgBuf.String()
}

func (list RegisterTasksList) Empty() bool {
	return len(list.Tasks) == 0
}

// GetImportTasksFrom try to get all the import tasks with prefix `RegisterTaskPrefix`
func GetImportTasksFrom(ctx context.Context, client *clientv3.Client) (RegisterTasksList, error) {
Repository: pingcap/tidb
File: br/pkg/utils/register_test.go (Go)

Code before:
		failpoint.Disable("github.com/pingcap/tidb/br/pkg/utils/brie-task-register-failed-to-reput")
		failpoint.Disable("github.com/pingcap/tidb/br/pkg/utils/brie-task-register-always-grant")
		failpoint.Disable("github.com/pingcap/tidb/br/pkg/utils/brie-task-register-keepalive-stop")
		failpoint.Disable("github.com/pingcap/tidb/br/pkg/utils/brie-task-register-retry-interval")
	}()
	err := register.RegisterTask(ctx)
	require.NoError(t, err)

	require.Eventually(t, func() bool {
		list, err := GetImportTasksFrom(ctx, client)
		return err == nil && len(list.Tasks) == 0
	}, 5*time.Second, 50*time.Millisecond)

	failpoint.Disable("github.com/pingcap/tidb/br/pkg/utils/brie-task-register-keepalive-stop")
	failpoint.Disable("github.com/pingcap/tidb/br/pkg/utils/brie-task-register-failed-to-reput")
	require.Eventually(t, func() bool {
		list, err := GetImportTasksFrom(ctx, client)
		return err == nil && len(list.Tasks) > 0
	}, 5*time.Second, 50*time.Millisecond)
	list, err := GetImportTasksFrom(ctx, client)
	require.NoError(t, err)
	for _, task := range list.Tasks {
		t.Log(task.MessageToUser())
		require.Equal(t, "/tidb/brie/import/restore/test", task.Key)
	}
	require.True(t, len(list.Tasks) > 0)
}


Review comment (refactor):
After the `require.Eventually` call on lines 161-164 already confirmed that `len(list.Tasks) > 0`, the code here fetches the task list again and checks `len(list.Tasks) > 0` on line 171. This redundant check can be removed since the Eventually already ensures this condition is met. Consider removing line 171 as it duplicates the Eventually condition.
```suggestion

```

Code after:
		failpoint.Disable("github.com/pingcap/tidb/br/pkg/utils/brie-task-register-always-grant")
		failpoint.Disable("github.com/pingcap/tidb/br/pkg/utils/brie-task-register-keepalive-stop")
		failpoint.Disable("github.com/pingcap/tidb/br/pkg/utils/brie-task-register-retry-interval")
	}()
	err := register.RegisterTask(ctx)
	require.NoError(t, err)

	require.Eventually(t, func() bool {
		list, err := GetImportTasksFrom(ctx, client)
		return err == nil && len(list.Tasks) == 0
	}, 5*time.Second, 50*time.Millisecond)

	failpoint.Disable("github.com/pingcap/tidb/br/pkg/utils/brie-task-register-keepalive-stop")
	failpoint.Disable("github.com/pingcap/tidb/br/pkg/utils/brie-task-register-failed-to-reput")
	var list RegisterTasksList
	require.Eventually(t, func() bool {
		var err error
		list, err = GetImportTasksFrom(ctx, client)
		return err == nil && len(list.Tasks) > 0
	}, 5*time.Second, 50*time.Millisecond)
	for _, task := range list.Tasks {
		t.Log(task.MessageToUser())
		require.Equal(t, "/tidb/brie/import/restore/test", task.Key)
	}
}
Repository: pingcap/tidb
File: pkg/sessionctx/variable/slow_log.go (Go)

Code before:
// MatchEqual compares a value `v` with a threshold and returns true if they are equal.
func MatchEqual[T comparable](threshold any, v T) bool {
	tv, ok := threshold.(T)
	return ok && v == tv
}

func matchGE[T numericComparable](threshold any, v T) bool {
	tv, ok := threshold.(T)
	return ok && v >= tv
}

func matchZero(threshold any) bool {
	switch v := threshold.(type) {
	case int:
		return v == 0
	case uint64:
		return v == 0
	case int64:
		return v == 0
	case float64:
		return v == 0
	default:
		return false
	}
}

// ParseString converts the input string to lowercase and returns it.
func ParseString(v string) (any, error) { return v, nil }
func parseInt64(v string) (any, error) {
	n, err := strconv.ParseInt(v, 10, 64)
	if err != nil {
		return nil, err
	}
	if n < 0 {
		return nil, fmt.Errorf("threshold value must be non-negative, got %d", n)
	}
	return n, nil
}
func parseUint64(v string) (any, error) { return strconv.ParseUint(v, 10, 64) }
func parseFloat64(v string) (any, error) {
	f, err := strconv.ParseFloat(v, 64)
	if err != nil {
		return nil, err
	}
	if f < 0 {
		return nil, fmt.Errorf("threshold value must be non-negative, got %v", f)
	}
	return f, nil
}
func parseBool(v string) (any, error) { return strconv.ParseBool(v) }


Review comment (security):
**Suggestion:** The comment for `ParseString` says it converts input to lowercase, but the function currently returns the string as-is.

To avoid confusion, either update the comment to match the behavior, or actually lowercase here (but note other string fields may be intended case-sensitive).

Code after:

// MatchEqual compares a value `v` with a threshold and returns true if they are equal.
func MatchEqual[T comparable](threshold any, v T) bool {
	tv, ok := threshold.(T)
	return ok && v == tv
}

func matchGE[T numericComparable](threshold any, v T) bool {
	tv, ok := threshold.(T)
	return ok && v >= tv
}

func matchZero(threshold any) bool {
	switch v := threshold.(type) {
	case int:
		return v == 0
	case uint64:
		return v == 0
	case int64:
		return v == 0
	case float64:
		return v == 0
	default:
		return false
	}
}

// ParseString returns the input string as-is.
func ParseString(v string) (any, error) { return v, nil }
func parseInt64(v string) (any, error) {
	n, err := strconv.ParseInt(v, 10, 64)
	if err != nil {
		return nil, err
	}
	if n < 0 {
		return nil, fmt.Errorf("threshold value must be non-negative, got %d", n)
	}
	return n, nil
}
func parseUint64(v string) (any, error) { return strconv.ParseUint(v, 10, 64) }
func parseFloat64(v string) (any, error) {
	f, err := strconv.ParseFloat(v, 64)
	if err != nil {
		return nil, err
	}
	if math.IsNaN(f) || math.IsInf(f, 0) {
		return nil, fmt.Errorf("threshold value must be finite, got %v", f)
	}
	if f < 0 {
		return nil, fmt.Errorf("threshold value must be non-negative, got %v", f)
	}