From 944f4ab01c9e02325fab271fc81bfa42f5cd2208 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 29 Apr 2024 03:56:27 +0200 Subject: [PATCH] wip --- lib/logstorage/filter.go | 16 +++++++------- lib/logstorage/filters_test.go | 36 ++++++++++++++++---------------- lib/logstorage/parser.go | 4 ++-- lib/logstorage/storage_search.go | 6 +++--- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/logstorage/filter.go b/lib/logstorage/filter.go index 7b234cef2..534b22829 100644 --- a/lib/logstorage/filter.go +++ b/lib/logstorage/filter.go @@ -36,15 +36,15 @@ func (fn *filterNoop) apply(_ *blockSearch, _ *bitmap) { // nothing to do } -// orFilter contains filters joined by OR operator. +// filterOr contains filters joined by OR operator. // // It is epxressed as `f1 OR f2 ... OR fN` in LogsQL. -type orFilter struct { +type filterOr struct { filters []filter } -func (of *orFilter) String() string { - filters := of.filters +func (fo *filterOr) String() string { + filters := fo.filters a := make([]string, len(filters)) for i, f := range filters { s := f.String() @@ -53,10 +53,10 @@ func (of *orFilter) String() string { return strings.Join(a, " or ") } -func (of *orFilter) apply(bs *blockSearch, bm *bitmap) { +func (fo *filterOr) apply(bs *blockSearch, bm *bitmap) { bmResult := getBitmap(bm.bitsLen) bmTmp := getBitmap(bm.bitsLen) - for _, f := range of.filters { + for _, f := range fo.filters { // Minimize the number of rows to check by the filter by checking only // the rows, which may change the output bm: // - bm matches them, e.g. the caller wants to get them @@ -92,7 +92,7 @@ func (af *andFilter) String() string { for i, f := range filters { s := f.String() switch f.(type) { - case *orFilter: + case *filterOr: s = "(" + s + ")" } a[i] = s @@ -171,7 +171,7 @@ type notFilter struct { func (fn *notFilter) String() string { s := fn.f.String() switch fn.f.(type) { - case *andFilter, *orFilter: + case *andFilter, *filterOr: s = "(" + s + ")" } return "!" + s diff --git a/lib/logstorage/filters_test.go b/lib/logstorage/filters_test.go index bd0ece61f..4b398598a 100644 --- a/lib/logstorage/filters_test.go +++ b/lib/logstorage/filters_test.go @@ -368,7 +368,7 @@ func TestComplexFilters(t *testing.T) { phrase: "baz", }, }, - &orFilter{ + &filterOr{ filters: []filter{ &phraseFilter{ fieldName: "foo", @@ -397,7 +397,7 @@ func TestComplexFilters(t *testing.T) { phrase: "baz", }, }, - &orFilter{ + &filterOr{ filters: []filter{ &phraseFilter{ fieldName: "foo", @@ -426,7 +426,7 @@ func TestComplexFilters(t *testing.T) { phrase: "baz", }, }, - &orFilter{ + &filterOr{ filters: []filter{ &phraseFilter{ fieldName: "foo", @@ -459,7 +459,7 @@ func TestComplexFilters(t *testing.T) { phrase: "qwert", }, }, - &orFilter{ + &filterOr{ filters: []filter{ &phraseFilter{ fieldName: "foo", @@ -500,7 +500,7 @@ func TestOrFilter(t *testing.T) { } // non-empty union - of := &orFilter{ + fo := &filterOr{ filters: []filter{ &phraseFilter{ fieldName: "foo", @@ -512,10 +512,10 @@ func TestOrFilter(t *testing.T) { }, }, } - testFilterMatchForColumns(t, columns, of, "foo", []int{2, 6, 9}) + testFilterMatchForColumns(t, columns, fo, "foo", []int{2, 6, 9}) // reverse non-empty union - of = &orFilter{ + fo = &filterOr{ filters: []filter{ &prefixFilter{ fieldName: "foo", @@ -527,10 +527,10 @@ func TestOrFilter(t *testing.T) { }, }, } - testFilterMatchForColumns(t, columns, of, "foo", []int{2, 6, 9}) + testFilterMatchForColumns(t, columns, fo, "foo", []int{2, 6, 9}) // first empty result, second non-empty result - of = &orFilter{ + fo = &filterOr{ filters: []filter{ &prefixFilter{ fieldName: "foo", @@ -542,10 +542,10 @@ func TestOrFilter(t *testing.T) { }, }, } - testFilterMatchForColumns(t, columns, of, "foo", []int{9}) + testFilterMatchForColumns(t, columns, fo, "foo", []int{9}) // first non-empty result, second empty result - of = &orFilter{ + fo = &filterOr{ filters: []filter{ &phraseFilter{ fieldName: "foo", @@ -557,10 +557,10 @@ func TestOrFilter(t *testing.T) { }, }, } - testFilterMatchForColumns(t, columns, of, "foo", []int{9}) + testFilterMatchForColumns(t, columns, fo, "foo", []int{9}) // first match all - of = &orFilter{ + fo = &filterOr{ filters: []filter{ &phraseFilter{ fieldName: "foo", @@ -572,10 +572,10 @@ func TestOrFilter(t *testing.T) { }, }, } - testFilterMatchForColumns(t, columns, of, "foo", []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) + testFilterMatchForColumns(t, columns, fo, "foo", []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) // second match all - of = &orFilter{ + fo = &filterOr{ filters: []filter{ &prefixFilter{ fieldName: "foo", @@ -587,10 +587,10 @@ func TestOrFilter(t *testing.T) { }, }, } - testFilterMatchForColumns(t, columns, of, "foo", []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) + testFilterMatchForColumns(t, columns, fo, "foo", []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) // both empty results - of = &orFilter{ + fo = &filterOr{ filters: []filter{ &phraseFilter{ fieldName: "foo", @@ -602,7 +602,7 @@ func TestOrFilter(t *testing.T) { }, }, } - testFilterMatchForColumns(t, columns, of, "foo", nil) + testFilterMatchForColumns(t, columns, fo, "foo", nil) } func TestAndFilter(t *testing.T) { diff --git a/lib/logstorage/parser.go b/lib/logstorage/parser.go index 5f5f1a143..d65ebc226 100644 --- a/lib/logstorage/parser.go +++ b/lib/logstorage/parser.go @@ -262,10 +262,10 @@ func parseOrFilter(lex *lexer, fieldName string) (filter, error) { if len(filters) == 1 { return filters[0], nil } - of := &orFilter{ + fo := &filterOr{ filters: filters, } - return of, nil + return fo, nil case lex.isKeyword("or"): if !lex.mustNextToken() { return nil, fmt.Errorf("missing filter after 'or'") diff --git a/lib/logstorage/storage_search.go b/lib/logstorage/storage_search.go index f67ba754c..f62a6babe 100644 --- a/lib/logstorage/storage_search.go +++ b/lib/logstorage/storage_search.go @@ -341,7 +341,7 @@ func hasStreamFilters(f filter) bool { switch t := f.(type) { case *andFilter: return hasStreamFiltersInList(t.filters) - case *orFilter: + case *filterOr: return hasStreamFiltersInList(t.filters) case *notFilter: return hasStreamFilters(t.f) @@ -367,8 +367,8 @@ func initStreamFilters(tenantIDs []TenantID, idb *indexdb, f filter) filter { return &andFilter{ filters: initStreamFiltersList(tenantIDs, idb, t.filters), } - case *orFilter: - return &orFilter{ + case *filterOr: + return &filterOr{ filters: initStreamFiltersList(tenantIDs, idb, t.filters), } case *notFilter: