From 827984faa226b3c250525483c7f0c801d1d680ab Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 5 Jun 2024 03:10:32 +0200 Subject: [PATCH] wip --- lib/logstorage/block_result.go | 18 +++++++++++++++++- lib/logstorage/parser_test.go | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/logstorage/block_result.go b/lib/logstorage/block_result.go index 97acfab74..033dcac48 100644 --- a/lib/logstorage/block_result.go +++ b/lib/logstorage/block_result.go @@ -4,6 +4,7 @@ import ( "math" "slices" "strconv" + "strings" "sync/atomic" "time" "unsafe" @@ -1933,7 +1934,7 @@ func tryParseNumber(s string) (float64, bool) { if ok { return float64(bytes), true } - if isNumberPrefix(s) { + if isLikelyNumber(s) { f, err := strconv.ParseFloat(s, 64) if err == nil { return f, true @@ -1946,5 +1947,20 @@ func tryParseNumber(s string) (float64, bool) { return 0, false } +func isLikelyNumber(s string) bool { + if !isNumberPrefix(s) { + return false + } + if strings.Count(s, ".") > 1 { + // This is likely IP address + return false + } + if strings.IndexByte(s, ':') >= 0 || strings.Count(s, "-") > 2 { + // This is likely a timestamp + return false + } + return true +} + var nan = math.NaN() var inf = math.Inf(1) diff --git a/lib/logstorage/parser_test.go b/lib/logstorage/parser_test.go index 9afddc17d..ff603be33 100644 --- a/lib/logstorage/parser_test.go +++ b/lib/logstorage/parser_test.go @@ -496,7 +496,7 @@ func TestParseRangeFilter(t *testing.T) { } fr, ok := q.f.(*filterRange) if !ok { - t.Fatalf("unexpected filter type; got %T; want *filterIPv4Range; filter: %s", q.f, q.f) + t.Fatalf("unexpected filter type; got %T; want *filterRange; filter: %s", q.f, q.f) } if fr.fieldName != fieldNameExpected { t.Fatalf("unexpected fieldName; got %q; want %q", fr.fieldName, fieldNameExpected)