From aa238329215e4b3bd433ae9bbace1f8e5b0bd5c5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 24 May 2024 19:45:43 +0200 Subject: [PATCH] wip --- docs/VictoriaLogs/CHANGELOG.md | 1 + lib/logstorage/block_result.go | 4 ++-- lib/logstorage/pipe_topk.go | 4 ++-- lib/logstorage/stats_uniq_values_test.go | 22 ++++++++++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/docs/VictoriaLogs/CHANGELOG.md b/docs/VictoriaLogs/CHANGELOG.md index 8058b937a..b162bad8b 100644 --- a/docs/VictoriaLogs/CHANGELOG.md +++ b/docs/VictoriaLogs/CHANGELOG.md @@ -20,6 +20,7 @@ according to [these docs](https://docs.victoriametrics.com/victorialogs/quicksta ## tip * FEATURE: support [comparing](https://docs.victoriametrics.com/victorialogs/logsql/#range-filter) log field values with [special numeric values](https://docs.victoriametrics.com/victorialogs/logsql/#numeric-values). For example, `duration:>1.5s` and `response_size:<15KiB` are valid filters now. +* FEATURE: properly sort [durations](https://docs.victoriametrics.com/victorialogs/logsql/#duration-values) and [short numeric values](https://docs.victoriametrics.com/victorialogs/logsql/#short-numeric-values) in [`sort` pipe](https://docs.victoriametrics.com/victorialogs/logsql/#sort-pipe). For example, `10s` goes in front of `1h`, while `10KB` goes in front of `1GB`. * FEATURE: add an ability to preserve the original non-empty field values when performing [`extract`](https://docs.victoriametrics.com/victorialogs/logsql/#extract-pipe), [`unpack_json`](https://docs.victoriametrics.com/victorialogs/logsql/#unpack_json-pipe), [`unpack_logfmt`](https://docs.victoriametrics.com/victorialogs/logsql/#unpack_logfmt-pipe) and [`format`](https://docs.victoriametrics.com/victorialogs/logsql/#format-pipe) pipes. ## [v0.10.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v0.10.0-victorialogs) diff --git a/lib/logstorage/block_result.go b/lib/logstorage/block_result.go index 097f052b0..9069579d6 100644 --- a/lib/logstorage/block_result.go +++ b/lib/logstorage/block_result.go @@ -1700,7 +1700,7 @@ func (c *blockResultColumn) sumValues(br *blockResult) (float64, int) { values := c.getValuesEncoded(br) for i := range values { if i == 0 || values[i-1] != values[i] { - f, ok = tryParseFloat64(values[i]) + f, ok = tryParseNumber(values[i]) } if ok { sum += f @@ -1713,7 +1713,7 @@ func (c *blockResultColumn) sumValues(br *blockResult) (float64, int) { a := encoding.GetFloat64s(len(dictValues)) dictValuesFloat := a.A for i, v := range dictValues { - f, ok := tryParseFloat64(v) + f, ok := tryParseNumber(v) if !ok { f = nan } diff --git a/lib/logstorage/pipe_topk.go b/lib/logstorage/pipe_topk.go index 6738878a3..b7108a11b 100644 --- a/lib/logstorage/pipe_topk.go +++ b/lib/logstorage/pipe_topk.go @@ -621,8 +621,8 @@ func lessString(a, b string) bool { return nA < nB } - fA, okA := tryParseFloat64(a) - fB, okB := tryParseFloat64(b) + fA, okA := tryParseNumber(a) + fB, okB := tryParseNumber(b) if okA && okB { return fA < fB } diff --git a/lib/logstorage/stats_uniq_values_test.go b/lib/logstorage/stats_uniq_values_test.go index 70d25d200..9f8b9665f 100644 --- a/lib/logstorage/stats_uniq_values_test.go +++ b/lib/logstorage/stats_uniq_values_test.go @@ -1,6 +1,7 @@ package logstorage import ( + "strings" "testing" ) @@ -415,3 +416,24 @@ func TestStatsUniqValues(t *testing.T) { }, }) } + +func TestSortStrings(t *testing.T) { + f := func(s, resultExpected string) { + t.Helper() + + a := strings.Split(s, ",") + sortStrings(a) + result := strings.Join(a, ",") + if result != resultExpected { + t.Fatalf("unexpected sort result\ngot\n%q\nwant\n%q", a, resultExpected) + } + } + + f("", "") + f("1", "1") + f("foo,bar,baz", "bar,baz,foo") + f("100ms,1.5s,1.23s","100ms,1.23s,1.5s") + f("10KiB,10KB,5.34K","5.34K,10KB,10KiB") + f("v1.10.9,v1.10.10,v1.9.0","v1.9.0,v1.10.9,v1.10.10") + f("10s,123,100M","123,100M,10s") +}