From ecef86c6413de7349e269be6a23d87617f826bd4 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 29 Apr 2024 06:37:22 +0200 Subject: [PATCH] wip --- lib/logstorage/filter.go | 8 +-- lib/logstorage/filter_test.go | 112 +++++++++++++++++----------------- lib/logstorage/parser.go | 6 +- lib/logstorage/parser_test.go | 46 +++++++------- 4 files changed, 86 insertions(+), 86 deletions(-) diff --git a/lib/logstorage/filter.go b/lib/logstorage/filter.go index bc786a124..18ead3ddf 100644 --- a/lib/logstorage/filter.go +++ b/lib/logstorage/filter.go @@ -72,10 +72,10 @@ func (fs *streamFilter) apply(bs *blockSearch, bm *bitmap) { } } -// rangeFilter matches the given range [minValue..maxValue]. +// filterRange matches the given range [minValue..maxValue]. // // Example LogsQL: `fieldName:range(minValue, maxValue]` -type rangeFilter struct { +type filterRange struct { fieldName string minValue float64 maxValue float64 @@ -83,11 +83,11 @@ type rangeFilter struct { stringRepr string } -func (fr *rangeFilter) String() string { +func (fr *filterRange) String() string { return quoteFieldNameIfNeeded(fr.fieldName) + "range" + fr.stringRepr } -func (fr *rangeFilter) apply(bs *blockSearch, bm *bitmap) { +func (fr *filterRange) apply(bs *blockSearch, bm *bitmap) { fieldName := fr.fieldName minValue := fr.minValue maxValue := fr.maxValue diff --git a/lib/logstorage/filter_test.go b/lib/logstorage/filter_test.go index 7b552351e..dfbf3b60f 100644 --- a/lib/logstorage/filter_test.go +++ b/lib/logstorage/filter_test.go @@ -697,7 +697,7 @@ func TestRegexpFilter(t *testing.T) { }) } -func TestRangeFilter(t *testing.T) { +func TestFilterRange(t *testing.T) { t.Run("const-column", func(t *testing.T) { columns := []column{ { @@ -711,21 +711,21 @@ func TestRangeFilter(t *testing.T) { } // match - fr := &rangeFilter{ + fr := &filterRange{ fieldName: "foo", minValue: -10, maxValue: 20, } testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 10, maxValue: 10, } testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 10, maxValue: 20, @@ -733,35 +733,35 @@ func TestRangeFilter(t *testing.T) { testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) // mismatch - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -10, maxValue: 9.99, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 20, maxValue: -10, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 10.1, maxValue: 20, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "non-existing-column", minValue: 10, maxValue: 20, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 11, maxValue: 10, @@ -786,21 +786,21 @@ func TestRangeFilter(t *testing.T) { } // match - fr := &rangeFilter{ + fr := &filterRange{ fieldName: "foo", minValue: -10, maxValue: 20, } testFilterMatchForColumns(t, columns, fr, "foo", []int{1, 3, 4}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 10, maxValue: 20, } testFilterMatchForColumns(t, columns, fr, "foo", []int{1, 3, 4}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 10.1, maxValue: 19.9, @@ -808,28 +808,28 @@ func TestRangeFilter(t *testing.T) { testFilterMatchForColumns(t, columns, fr, "foo", []int{4}) // mismatch - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -11, maxValue: 0, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 11, maxValue: 19, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 20.1, maxValue: 100, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 20, maxValue: 10, @@ -858,21 +858,21 @@ func TestRangeFilter(t *testing.T) { } // match - fr := &rangeFilter{ + fr := &filterRange{ fieldName: "foo", minValue: -100, maxValue: 100, } testFilterMatchForColumns(t, columns, fr, "foo", []int{2, 3, 4, 5}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 10, maxValue: 20, } testFilterMatchForColumns(t, columns, fr, "foo", []int{2, 3, 4}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -5, maxValue: -5, @@ -880,21 +880,21 @@ func TestRangeFilter(t *testing.T) { testFilterMatchForColumns(t, columns, fr, "foo", []int{5}) // mismatch - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -10, maxValue: -5.1, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 20.1, maxValue: 100, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 20, maxValue: 10, @@ -923,21 +923,21 @@ func TestRangeFilter(t *testing.T) { } // match - fr := &rangeFilter{ + fr := &filterRange{ fieldName: "foo", minValue: 0, maxValue: 3, } testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7, 8}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 0.1, maxValue: 2.9, } testFilterMatchForColumns(t, columns, fr, "foo", []int{6, 7}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -1e18, maxValue: 2.9, @@ -945,21 +945,21 @@ func TestRangeFilter(t *testing.T) { testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7}) // mismatch - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -1e18, maxValue: -0.1, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 0.1, maxValue: 0.9, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 2.9, maxValue: 0.1, @@ -989,21 +989,21 @@ func TestRangeFilter(t *testing.T) { } // match - fr := &rangeFilter{ + fr := &filterRange{ fieldName: "foo", minValue: 0, maxValue: 3, } testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7, 8}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 0.1, maxValue: 2.9, } testFilterMatchForColumns(t, columns, fr, "foo", []int{6, 7}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -1e18, maxValue: 2.9, @@ -1011,21 +1011,21 @@ func TestRangeFilter(t *testing.T) { testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7}) // mismatch - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -1e18, maxValue: -0.1, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 0.1, maxValue: 0.9, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 2.9, maxValue: 0.1, @@ -1054,21 +1054,21 @@ func TestRangeFilter(t *testing.T) { } // match - fr := &rangeFilter{ + fr := &filterRange{ fieldName: "foo", minValue: 0, maxValue: 3, } testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7, 8}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 0.1, maxValue: 2.9, } testFilterMatchForColumns(t, columns, fr, "foo", []int{6, 7}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -1e18, maxValue: 2.9, @@ -1076,21 +1076,21 @@ func TestRangeFilter(t *testing.T) { testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7}) // mismatch - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -1e18, maxValue: -0.1, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 0.1, maxValue: 0.9, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 2.9, maxValue: 0.1, @@ -1119,28 +1119,28 @@ func TestRangeFilter(t *testing.T) { } // match - fr := &rangeFilter{ + fr := &filterRange{ fieldName: "foo", minValue: math.Inf(-1), maxValue: 3, } testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7, 8}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 0.1, maxValue: 2.9, } testFilterMatchForColumns(t, columns, fr, "foo", []int{6, 7}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -1e18, maxValue: 2.9, } testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 1000, maxValue: math.Inf(1), @@ -1148,21 +1148,21 @@ func TestRangeFilter(t *testing.T) { testFilterMatchForColumns(t, columns, fr, "foo", []int{5}) // mismatch - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -1e18, maxValue: -0.1, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 0.1, maxValue: 0.9, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 2.9, maxValue: 0.1, @@ -1191,28 +1191,28 @@ func TestRangeFilter(t *testing.T) { } // match - fr := &rangeFilter{ + fr := &filterRange{ fieldName: "foo", minValue: math.Inf(-1), maxValue: 3, } testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7, 8}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 0.1, maxValue: 2.9, } testFilterMatchForColumns(t, columns, fr, "foo", []int{7}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -1e18, maxValue: 1.9, } testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 8}) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 1000, maxValue: math.Inf(1), @@ -1220,21 +1220,21 @@ func TestRangeFilter(t *testing.T) { testFilterMatchForColumns(t, columns, fr, "foo", []int{5}) // mismatch - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: -1e18, maxValue: -334.1, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 0.1, maxValue: 0.9, } testFilterMatchForColumns(t, columns, fr, "foo", nil) - fr = &rangeFilter{ + fr = &filterRange{ fieldName: "foo", minValue: 2.9, maxValue: 0.1, @@ -1264,7 +1264,7 @@ func TestRangeFilter(t *testing.T) { } // range filter always mismatches ipv4 - fr := &rangeFilter{ + fr := &filterRange{ fieldName: "foo", minValue: -100, maxValue: 100, @@ -1291,7 +1291,7 @@ func TestRangeFilter(t *testing.T) { } // range filter always mismatches timestmap - fr := &rangeFilter{ + fr := &filterRange{ fieldName: "_msg", minValue: -100, maxValue: 100, diff --git a/lib/logstorage/parser.go b/lib/logstorage/parser.go index a982c18c5..dcd828e99 100644 --- a/lib/logstorage/parser.go +++ b/lib/logstorage/parser.go @@ -332,7 +332,7 @@ func parseGenericFilter(lex *lexer, fieldName string) (filter, error) { case lex.isKeyword("len_range"): return parseFilterLenRange(lex, fieldName) case lex.isKeyword("range"): - return parseRangeFilter(lex, fieldName) + return parseFilterRange(lex, fieldName) case lex.isKeyword("re"): return parseRegexpFilter(lex, fieldName) case lex.isKeyword("seq"): @@ -664,7 +664,7 @@ func parseRegexpFilter(lex *lexer, fieldName string) (filter, error) { }) } -func parseRangeFilter(lex *lexer, fieldName string) (filter, error) { +func parseFilterRange(lex *lexer, fieldName string) (filter, error) { funcName := lex.token lex.nextToken() @@ -726,7 +726,7 @@ func parseRangeFilter(lex *lexer, fieldName string) (filter, error) { maxValue = math.Nextafter(maxValue, math.Inf(-1)) } - fr := &rangeFilter{ + fr := &filterRange{ fieldName: fieldName, minValue: minValue, maxValue: maxValue, diff --git a/lib/logstorage/parser_test.go b/lib/logstorage/parser_test.go index dbcec4b72..441bebd2c 100644 --- a/lib/logstorage/parser_test.go +++ b/lib/logstorage/parser_test.go @@ -332,18 +332,18 @@ func TestParseFilterIPv4Range(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %s", err) } - rf, ok := q.f.(*filterIPv4Range) + fr, ok := q.f.(*filterIPv4Range) if !ok { t.Fatalf("unexpected filter type; got %T; want *filterIPv4Range; filter: %s", q.f, q.f) } - if rf.fieldName != fieldNameExpected { - t.Fatalf("unexpected fieldName; got %q; want %q", rf.fieldName, fieldNameExpected) + if fr.fieldName != fieldNameExpected { + t.Fatalf("unexpected fieldName; got %q; want %q", fr.fieldName, fieldNameExpected) } - if rf.minValue != minValueExpected { - t.Fatalf("unexpected minValue; got %08x; want %08x", rf.minValue, minValueExpected) + if fr.minValue != minValueExpected { + t.Fatalf("unexpected minValue; got %08x; want %08x", fr.minValue, minValueExpected) } - if rf.maxValue != maxValueExpected { - t.Fatalf("unexpected maxValue; got %08x; want %08x", rf.maxValue, maxValueExpected) + if fr.maxValue != maxValueExpected { + t.Fatalf("unexpected maxValue; got %08x; want %08x", fr.maxValue, maxValueExpected) } } @@ -363,18 +363,18 @@ func TestParseFilterStringRange(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %s", err) } - rf, ok := q.f.(*filterStringRange) + fr, ok := q.f.(*filterStringRange) if !ok { t.Fatalf("unexpected filter type; got %T; want *filterStringRange; filter: %s", q.f, q.f) } - if rf.fieldName != fieldNameExpected { - t.Fatalf("unexpected fieldName; got %q; want %q", rf.fieldName, fieldNameExpected) + if fr.fieldName != fieldNameExpected { + t.Fatalf("unexpected fieldName; got %q; want %q", fr.fieldName, fieldNameExpected) } - if rf.minValue != minValueExpected { - t.Fatalf("unexpected minValue; got %q; want %q", rf.minValue, minValueExpected) + if fr.minValue != minValueExpected { + t.Fatalf("unexpected minValue; got %q; want %q", fr.minValue, minValueExpected) } - if rf.maxValue != maxValueExpected { - t.Fatalf("unexpected maxValue; got %q; want %q", rf.maxValue, maxValueExpected) + if fr.maxValue != maxValueExpected { + t.Fatalf("unexpected maxValue; got %q; want %q", fr.maxValue, maxValueExpected) } } @@ -389,11 +389,11 @@ func TestParseRegexpFilter(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %s", err) } - rf, ok := q.f.(*regexpFilter) + fr, ok := q.f.(*regexpFilter) if !ok { t.Fatalf("unexpected filter type; got %T; want *regexpFilter; filter: %s", q.f, q.f) } - if reString := rf.re.String(); reString != reExpected { + if reString := fr.re.String(); reString != reExpected { t.Fatalf("unexpected regexp; got %q; want %q", reString, reExpected) } } @@ -517,18 +517,18 @@ func TestParseRangeFilter(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %s", err) } - rf, ok := q.f.(*rangeFilter) + fr, ok := q.f.(*filterRange) if !ok { t.Fatalf("unexpected filter type; got %T; want *filterIPv4Range; filter: %s", q.f, q.f) } - if rf.fieldName != fieldNameExpected { - t.Fatalf("unexpected fieldName; got %q; want %q", rf.fieldName, fieldNameExpected) + if fr.fieldName != fieldNameExpected { + t.Fatalf("unexpected fieldName; got %q; want %q", fr.fieldName, fieldNameExpected) } - if rf.minValue != minValueExpected { - t.Fatalf("unexpected minValue; got %v; want %v", rf.minValue, minValueExpected) + if fr.minValue != minValueExpected { + t.Fatalf("unexpected minValue; got %v; want %v", fr.minValue, minValueExpected) } - if rf.maxValue != maxValueExpected { - t.Fatalf("unexpected maxValue; got %v; want %v", rf.maxValue, maxValueExpected) + if fr.maxValue != maxValueExpected { + t.Fatalf("unexpected maxValue; got %v; want %v", fr.maxValue, maxValueExpected) } }