From 84631d8c04e750d4a7c060e9b240773154e62d6c Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 29 Apr 2024 07:51:39 +0200 Subject: [PATCH] wip --- lib/logstorage/filter.go | 69 --------------------------------- lib/logstorage/filter_phrase.go | 11 ++++++ lib/logstorage/filter_prefix.go | 42 ++++++++++++++++++++ lib/logstorage/filter_range.go | 16 ++++++++ 4 files changed, 69 insertions(+), 69 deletions(-) diff --git a/lib/logstorage/filter.go b/lib/logstorage/filter.go index de5a4e984..5a525897f 100644 --- a/lib/logstorage/filter.go +++ b/lib/logstorage/filter.go @@ -1,12 +1,9 @@ package logstorage import ( - "math" - "strconv" "sync" "github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil" - "github.com/VictoriaMetrics/VictoriaMetrics/lib/encoding" "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" ) @@ -66,72 +63,6 @@ func (fs *streamFilter) apply(bs *blockSearch, bm *bitmap) { } } -func toUint64Range(minValue, maxValue float64) (uint64, uint64) { - minValue = math.Ceil(minValue) - maxValue = math.Floor(maxValue) - return toUint64Clamp(minValue), toUint64Clamp(maxValue) -} - -func toUint64Clamp(f float64) uint64 { - if f < 0 { - return 0 - } - if f > math.MaxUint64 { - return math.MaxUint64 - } - return uint64(f) -} - -func quoteFieldNameIfNeeded(s string) string { - if isMsgFieldName(s) { - return "" - } - return quoteTokenIfNeeded(s) + ":" -} - -func isMsgFieldName(fieldName string) bool { - return fieldName == "" || fieldName == "_msg" -} - -func toUint8String(bs *blockSearch, bb *bytesutil.ByteBuffer, v string) string { - if len(v) != 1 { - logger.Panicf("FATAL: %s: unexpected length for binary representation of uint8 number: got %d; want 1", bs.partPath(), len(v)) - } - n := uint64(v[0]) - bb.B = strconv.AppendUint(bb.B[:0], n, 10) - return bytesutil.ToUnsafeString(bb.B) -} - -func toUint16String(bs *blockSearch, bb *bytesutil.ByteBuffer, v string) string { - if len(v) != 2 { - logger.Panicf("FATAL: %s: unexpected length for binary representation of uint16 number: got %d; want 2", bs.partPath(), len(v)) - } - b := bytesutil.ToUnsafeBytes(v) - n := uint64(encoding.UnmarshalUint16(b)) - bb.B = strconv.AppendUint(bb.B[:0], n, 10) - return bytesutil.ToUnsafeString(bb.B) -} - -func toUint32String(bs *blockSearch, bb *bytesutil.ByteBuffer, v string) string { - if len(v) != 4 { - logger.Panicf("FATAL: %s: unexpected length for binary representation of uint32 number: got %d; want 4", bs.partPath(), len(v)) - } - b := bytesutil.ToUnsafeBytes(v) - n := uint64(encoding.UnmarshalUint32(b)) - bb.B = strconv.AppendUint(bb.B[:0], n, 10) - return bytesutil.ToUnsafeString(bb.B) -} - -func toUint64String(bs *blockSearch, bb *bytesutil.ByteBuffer, v string) string { - if len(v) != 8 { - logger.Panicf("FATAL: %s: unexpected length for binary representation of uint64 number: got %d; want 8", bs.partPath(), len(v)) - } - b := bytesutil.ToUnsafeBytes(v) - n := encoding.UnmarshalUint64(b) - bb.B = strconv.AppendUint(bb.B[:0], n, 10) - return bytesutil.ToUnsafeString(bb.B) -} - func toFloat64StringExt(bs *blockSearch, bb *bytesutil.ByteBuffer, v string) string { if len(v) != 8 { logger.Panicf("FATAL: %s: unexpected length for binary representation of floating-point number: got %d; want 8", bs.partPath(), len(v)) diff --git a/lib/logstorage/filter_phrase.go b/lib/logstorage/filter_phrase.go index b2f2d5eb1..e34822f2e 100644 --- a/lib/logstorage/filter_phrase.go +++ b/lib/logstorage/filter_phrase.go @@ -281,3 +281,14 @@ func matchBloomFilterAllTokens(bs *blockSearch, ch *columnHeader, tokens []strin bf := bs.getBloomFilterForColumn(ch) return bf.containsAll(tokens) } + +func quoteFieldNameIfNeeded(s string) string { + if isMsgFieldName(s) { + return "" + } + return quoteTokenIfNeeded(s) + ":" +} + +func isMsgFieldName(fieldName string) bool { + return fieldName == "" || fieldName == "_msg" +} diff --git a/lib/logstorage/filter_prefix.go b/lib/logstorage/filter_prefix.go index 9a9693c29..ca61ddebf 100644 --- a/lib/logstorage/filter_prefix.go +++ b/lib/logstorage/filter_prefix.go @@ -2,10 +2,13 @@ package logstorage import ( "fmt" + "strconv" "strings" "sync" "unicode/utf8" + "github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil" + "github.com/VictoriaMetrics/VictoriaMetrics/lib/encoding" "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" ) @@ -314,3 +317,42 @@ func getTokensSkipLast(s string) []string { } return tokenizeStrings(nil, []string{s}) } + +func toUint8String(bs *blockSearch, bb *bytesutil.ByteBuffer, v string) string { + if len(v) != 1 { + logger.Panicf("FATAL: %s: unexpected length for binary representation of uint8 number: got %d; want 1", bs.partPath(), len(v)) + } + n := uint64(v[0]) + bb.B = strconv.AppendUint(bb.B[:0], n, 10) + return bytesutil.ToUnsafeString(bb.B) +} + +func toUint16String(bs *blockSearch, bb *bytesutil.ByteBuffer, v string) string { + if len(v) != 2 { + logger.Panicf("FATAL: %s: unexpected length for binary representation of uint16 number: got %d; want 2", bs.partPath(), len(v)) + } + b := bytesutil.ToUnsafeBytes(v) + n := uint64(encoding.UnmarshalUint16(b)) + bb.B = strconv.AppendUint(bb.B[:0], n, 10) + return bytesutil.ToUnsafeString(bb.B) +} + +func toUint32String(bs *blockSearch, bb *bytesutil.ByteBuffer, v string) string { + if len(v) != 4 { + logger.Panicf("FATAL: %s: unexpected length for binary representation of uint32 number: got %d; want 4", bs.partPath(), len(v)) + } + b := bytesutil.ToUnsafeBytes(v) + n := uint64(encoding.UnmarshalUint32(b)) + bb.B = strconv.AppendUint(bb.B[:0], n, 10) + return bytesutil.ToUnsafeString(bb.B) +} + +func toUint64String(bs *blockSearch, bb *bytesutil.ByteBuffer, v string) string { + if len(v) != 8 { + logger.Panicf("FATAL: %s: unexpected length for binary representation of uint64 number: got %d; want 8", bs.partPath(), len(v)) + } + b := bytesutil.ToUnsafeBytes(v) + n := encoding.UnmarshalUint64(b) + bb.B = strconv.AppendUint(bb.B[:0], n, 10) + return bytesutil.ToUnsafeString(bb.B) +} diff --git a/lib/logstorage/filter_range.go b/lib/logstorage/filter_range.go index bd7c0045b..66b3bc692 100644 --- a/lib/logstorage/filter_range.go +++ b/lib/logstorage/filter_range.go @@ -185,3 +185,19 @@ func matchRange(s string, minValue, maxValue float64) bool { } return f >= minValue && f <= maxValue } + +func toUint64Range(minValue, maxValue float64) (uint64, uint64) { + minValue = math.Ceil(minValue) + maxValue = math.Floor(maxValue) + return toUint64Clamp(minValue), toUint64Clamp(maxValue) +} + +func toUint64Clamp(f float64) uint64 { + if f < 0 { + return 0 + } + if f > math.MaxUint64 { + return math.MaxUint64 + } + return uint64(f) +}