From 0dd32f51448d5c978b8b0ec9a86ed8af267d7ab4 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 10 May 2024 15:32:51 +0200 Subject: [PATCH] wip --- lib/logstorage/stats_uniq_values.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/logstorage/stats_uniq_values.go b/lib/logstorage/stats_uniq_values.go index 5602e9415..b2376cb5d 100644 --- a/lib/logstorage/stats_uniq_values.go +++ b/lib/logstorage/stats_uniq_values.go @@ -2,7 +2,6 @@ package logstorage import ( "slices" - "sort" "strconv" "strings" "unsafe" @@ -188,7 +187,7 @@ func (sup *statsUniqValuesProcessor) finalizeStats() string { for k := range sup.m { items = append(items, k) } - sort.Strings(items) + slices.SortFunc(items, compareValues) // Marshal items into JSON array. @@ -212,6 +211,27 @@ func (sup *statsUniqValuesProcessor) finalizeStats() string { return bytesutil.ToUnsafeString(b) } +func compareValues(a, b string) int { + fA, okA := tryParseFloat64(a) + fB, okB := tryParseFloat64(b) + if okA && okB { + if fA == fB { + return 0 + } + if fA < fB { + return -1 + } + return 1 + } + if okA { + return -1 + } + if okB { + return 1 + } + return strings.Compare(a, b) +} + func parseStatsUniqValues(lex *lexer) (*statsUniqValues, error) { fields, err := parseFieldNamesForStatsFunc(lex, "uniq_values") if err != nil {