From 22615889a75f14730315d9cb4d536c4019ee2fb2 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 29 Apr 2024 06:14:56 +0200 Subject: [PATCH] wip --- lib/logstorage/filter.go | 66 ++-- lib/logstorage/filter_test.go | 694 +++++++++++++++++----------------- lib/logstorage/parser.go | 28 +- lib/logstorage/parser_test.go | 8 +- 4 files changed, 398 insertions(+), 398 deletions(-) diff --git a/lib/logstorage/filter.go b/lib/logstorage/filter.go index 8c48dec4e..576908325 100644 --- a/lib/logstorage/filter.go +++ b/lib/logstorage/filter.go @@ -72,25 +72,25 @@ func (fs *streamFilter) apply(bs *blockSearch, bm *bitmap) { } } -// ipv4RangeFilter matches the given ipv4 range [minValue..maxValue]. +// filterIPv4Range matches the given ipv4 range [minValue..maxValue]. // // Example LogsQL: `fieldName:ipv4_range(127.0.0.1, 127.0.0.255)` -type ipv4RangeFilter struct { +type filterIPv4Range struct { fieldName string minValue uint32 maxValue uint32 } -func (rf *ipv4RangeFilter) String() string { - minValue := string(encoding.MarshalUint32(nil, rf.minValue)) - maxValue := string(encoding.MarshalUint32(nil, rf.maxValue)) - return fmt.Sprintf("%sipv4_range(%s, %s)", quoteFieldNameIfNeeded(rf.fieldName), toIPv4String(nil, minValue), toIPv4String(nil, maxValue)) +func (fr *filterIPv4Range) String() string { + minValue := string(encoding.MarshalUint32(nil, fr.minValue)) + maxValue := string(encoding.MarshalUint32(nil, fr.maxValue)) + return fmt.Sprintf("%sipv4_range(%s, %s)", quoteFieldNameIfNeeded(fr.fieldName), toIPv4String(nil, minValue), toIPv4String(nil, maxValue)) } -func (rf *ipv4RangeFilter) apply(bs *blockSearch, bm *bitmap) { - fieldName := rf.fieldName - minValue := rf.minValue - maxValue := rf.maxValue +func (fr *filterIPv4Range) apply(bs *blockSearch, bm *bitmap) { + fieldName := fr.fieldName + minValue := fr.minValue + maxValue := fr.maxValue if minValue > maxValue { bm.resetBits() @@ -149,14 +149,14 @@ type stringRangeFilter struct { maxValue string } -func (rf *stringRangeFilter) String() string { - return fmt.Sprintf("%sstring_range(%s, %s)", quoteFieldNameIfNeeded(rf.fieldName), quoteTokenIfNeeded(rf.minValue), quoteTokenIfNeeded(rf.maxValue)) +func (fr *stringRangeFilter) String() string { + return fmt.Sprintf("%sstring_range(%s, %s)", quoteFieldNameIfNeeded(fr.fieldName), quoteTokenIfNeeded(fr.minValue), quoteTokenIfNeeded(fr.maxValue)) } -func (rf *stringRangeFilter) apply(bs *blockSearch, bm *bitmap) { - fieldName := rf.fieldName - minValue := rf.minValue - maxValue := rf.maxValue +func (fr *stringRangeFilter) apply(bs *blockSearch, bm *bitmap) { + fieldName := fr.fieldName + minValue := fr.minValue + maxValue := fr.maxValue if minValue > maxValue { bm.resetBits() @@ -215,14 +215,14 @@ type lenRangeFilter struct { stringRepr string } -func (rf *lenRangeFilter) String() string { - return quoteFieldNameIfNeeded(rf.fieldName) + "len_range" + rf.stringRepr +func (fr *lenRangeFilter) String() string { + return quoteFieldNameIfNeeded(fr.fieldName) + "len_range" + fr.stringRepr } -func (rf *lenRangeFilter) apply(bs *blockSearch, bm *bitmap) { - fieldName := rf.fieldName - minLen := rf.minLen - maxLen := rf.maxLen +func (fr *lenRangeFilter) apply(bs *blockSearch, bm *bitmap) { + fieldName := fr.fieldName + minLen := fr.minLen + maxLen := fr.maxLen if minLen > maxLen { bm.resetBits() @@ -282,14 +282,14 @@ type rangeFilter struct { stringRepr string } -func (rf *rangeFilter) String() string { - return quoteFieldNameIfNeeded(rf.fieldName) + "range" + rf.stringRepr +func (fr *rangeFilter) String() string { + return quoteFieldNameIfNeeded(fr.fieldName) + "range" + fr.stringRepr } -func (rf *rangeFilter) apply(bs *blockSearch, bm *bitmap) { - fieldName := rf.fieldName - minValue := rf.minValue - maxValue := rf.maxValue +func (fr *rangeFilter) apply(bs *blockSearch, bm *bitmap) { + fieldName := fr.fieldName + minValue := fr.minValue + maxValue := fr.maxValue if minValue > maxValue { bm.resetBits() @@ -344,13 +344,13 @@ type regexpFilter struct { re *regexp.Regexp } -func (rf *regexpFilter) String() string { - return fmt.Sprintf("%sre(%q)", quoteFieldNameIfNeeded(rf.fieldName), rf.re.String()) +func (fr *regexpFilter) String() string { + return fmt.Sprintf("%sre(%q)", quoteFieldNameIfNeeded(fr.fieldName), fr.re.String()) } -func (rf *regexpFilter) apply(bs *blockSearch, bm *bitmap) { - fieldName := rf.fieldName - re := rf.re +func (fr *regexpFilter) apply(bs *blockSearch, bm *bitmap) { + fieldName := fr.fieldName + re := fr.re // Verify whether filter matches const column v := bs.csh.getConstColumnValue(fieldName) diff --git a/lib/logstorage/filter_test.go b/lib/logstorage/filter_test.go index 0baee038d..c5d9fcbf4 100644 --- a/lib/logstorage/filter_test.go +++ b/lib/logstorage/filter_test.go @@ -505,36 +505,36 @@ func TestRegexpFilter(t *testing.T) { } // match - rf := ®expFilter{ + fr := ®expFilter{ fieldName: "foo", re: regexp.MustCompile("0.0"), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "foo", re: regexp.MustCompile(`^127\.0\.0\.1$`), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "non-existing-column", re: regexp.MustCompile("foo.+bar|"), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) // mismatch - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "foo", re: regexp.MustCompile("foo.+bar"), } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "non-existing-column", re: regexp.MustCompile("foo.+bar"), } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("dict", func(t *testing.T) { @@ -555,24 +555,24 @@ func TestRegexpFilter(t *testing.T) { } // match - rf := ®expFilter{ + fr := ®expFilter{ fieldName: "foo", re: regexp.MustCompile("foo|bar|^$"), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 5, 6}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 5, 6}) - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "foo", re: regexp.MustCompile("27.0"), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{1, 5, 6, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{1, 5, 6, 7}) // mismatch - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "foo", re: regexp.MustCompile("bar.+foo"), } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("strings", func(t *testing.T) { @@ -595,18 +595,18 @@ func TestRegexpFilter(t *testing.T) { } // match - rf := ®expFilter{ + fr := ®expFilter{ fieldName: "foo", re: regexp.MustCompile("(?i)foo|йцу"), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 6, 8}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 6, 8}) // mismatch - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "foo", re: regexp.MustCompile("qwe.+rty|^$"), } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint8", func(t *testing.T) { @@ -630,18 +630,18 @@ func TestRegexpFilter(t *testing.T) { } // match - rf := ®expFilter{ + fr := ®expFilter{ fieldName: "foo", re: regexp.MustCompile("[32][23]?"), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2, 5, 7, 8}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2, 5, 7, 8}) // mismatch - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "foo", re: regexp.MustCompile("foo|bar"), } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint16", func(t *testing.T) { @@ -665,18 +665,18 @@ func TestRegexpFilter(t *testing.T) { } // match - rf := ®expFilter{ + fr := ®expFilter{ fieldName: "foo", re: regexp.MustCompile("[32][23]?"), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2, 5, 7, 8}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2, 5, 7, 8}) // mismatch - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "foo", re: regexp.MustCompile("foo|bar"), } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint32", func(t *testing.T) { @@ -700,18 +700,18 @@ func TestRegexpFilter(t *testing.T) { } // match - rf := ®expFilter{ + fr := ®expFilter{ fieldName: "foo", re: regexp.MustCompile("[32][23]?"), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2, 5, 7, 8}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2, 5, 7, 8}) // mismatch - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "foo", re: regexp.MustCompile("foo|bar"), } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint64", func(t *testing.T) { @@ -735,18 +735,18 @@ func TestRegexpFilter(t *testing.T) { } // match - rf := ®expFilter{ + fr := ®expFilter{ fieldName: "foo", re: regexp.MustCompile("[32][23]?"), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2, 5, 7, 8}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2, 5, 7, 8}) // mismatch - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "foo", re: regexp.MustCompile("foo|bar"), } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("float64", func(t *testing.T) { @@ -770,18 +770,18 @@ func TestRegexpFilter(t *testing.T) { } // match - rf := ®expFilter{ + fr := ®expFilter{ fieldName: "foo", re: regexp.MustCompile("[32][23]?"), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2, 5, 6, 7, 8}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2, 5, 6, 7, 8}) // mismatch - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "foo", re: regexp.MustCompile("foo|bar"), } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("ipv4", func(t *testing.T) { @@ -806,18 +806,18 @@ func TestRegexpFilter(t *testing.T) { } // match - rf := ®expFilter{ + fr := ®expFilter{ fieldName: "foo", re: regexp.MustCompile("127.0.[40].(1|2)"), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{2, 4, 5, 6, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{2, 4, 5, 6, 7}) // mismatch - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "foo", re: regexp.MustCompile("foo|bar|834"), } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("timestamp-iso8601", func(t *testing.T) { @@ -839,18 +839,18 @@ func TestRegexpFilter(t *testing.T) { } // match - rf := ®expFilter{ + fr := ®expFilter{ fieldName: "_msg", re: regexp.MustCompile("2006-[0-9]{2}-.+?(2|5)Z"), } - testFilterMatchForColumns(t, columns, rf, "_msg", []int{1, 4}) + testFilterMatchForColumns(t, columns, fr, "_msg", []int{1, 4}) // mismatch - rf = ®expFilter{ + fr = ®expFilter{ fieldName: "_msg", re: regexp.MustCompile("^01|04$"), } - testFilterMatchForColumns(t, columns, rf, "_msg", nil) + testFilterMatchForColumns(t, columns, fr, "_msg", nil) }) } @@ -868,41 +868,41 @@ func TestStringRangeFilter(t *testing.T) { } // match - rf := &stringRangeFilter{ + fr := &stringRangeFilter{ fieldName: "foo", minValue: "127.0.0.1", maxValue: "255.", } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "127.0.0.1", maxValue: "127.0.0.1", } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) // mismatch - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "", maxValue: "127.0.0.0", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "non-existing-column", minValue: "1", maxValue: "2", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "127.0.0.2", maxValue: "", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("dict", func(t *testing.T) { @@ -923,41 +923,41 @@ func TestStringRangeFilter(t *testing.T) { } // match - rf := &stringRangeFilter{ + fr := &stringRangeFilter{ fieldName: "foo", minValue: "127.0.0.0", maxValue: "128.0.0.0", } - testFilterMatchForColumns(t, columns, rf, "foo", []int{1, 3, 6, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{1, 3, 6, 7}) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "127", maxValue: "127.0.0.1", } - testFilterMatchForColumns(t, columns, rf, "foo", []int{1, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{1, 7}) // mismatch - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "0", maxValue: "10", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "127.0.0.2", maxValue: "127.127.0.0", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "128.0.0.0", maxValue: "127.0.0.0", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("strings", func(t *testing.T) { @@ -980,27 +980,27 @@ func TestStringRangeFilter(t *testing.T) { } // match - rf := &stringRangeFilter{ + fr := &stringRangeFilter{ fieldName: "foo", minValue: "127.0.0.1", maxValue: "255.255.255.255", } - testFilterMatchForColumns(t, columns, rf, "foo", []int{2, 3, 4}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{2, 3, 4}) // mismatch - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "0", maxValue: "10", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "255.255.255.255", maxValue: "127.0.0.1", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint8", func(t *testing.T) { @@ -1024,34 +1024,34 @@ func TestStringRangeFilter(t *testing.T) { } // match - rf := &stringRangeFilter{ + fr := &stringRangeFilter{ fieldName: "foo", minValue: "33", maxValue: "5", } - testFilterMatchForColumns(t, columns, rf, "foo", []int{9, 10}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{9, 10}) // mismatch - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "a", maxValue: "b", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "100", maxValue: "101", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "5", maxValue: "33", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint16", func(t *testing.T) { @@ -1075,34 +1075,34 @@ func TestStringRangeFilter(t *testing.T) { } // match - rf := &stringRangeFilter{ + fr := &stringRangeFilter{ fieldName: "foo", minValue: "33", maxValue: "5", } - testFilterMatchForColumns(t, columns, rf, "foo", []int{9, 10}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{9, 10}) // mismatch - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "a", maxValue: "b", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "100", maxValue: "101", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "5", maxValue: "33", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint32", func(t *testing.T) { @@ -1126,34 +1126,34 @@ func TestStringRangeFilter(t *testing.T) { } // match - rf := &stringRangeFilter{ + fr := &stringRangeFilter{ fieldName: "foo", minValue: "33", maxValue: "5", } - testFilterMatchForColumns(t, columns, rf, "foo", []int{9, 10}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{9, 10}) // mismatch - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "a", maxValue: "b", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "100", maxValue: "101", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "5", maxValue: "33", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint64", func(t *testing.T) { @@ -1177,34 +1177,34 @@ func TestStringRangeFilter(t *testing.T) { } // match - rf := &stringRangeFilter{ + fr := &stringRangeFilter{ fieldName: "foo", minValue: "33", maxValue: "5", } - testFilterMatchForColumns(t, columns, rf, "foo", []int{9, 10}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{9, 10}) // mismatch - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "a", maxValue: "b", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "100", maxValue: "101", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "5", maxValue: "33", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("float64", func(t *testing.T) { columns := []column{ @@ -1227,40 +1227,40 @@ func TestStringRangeFilter(t *testing.T) { } // match - rf := &stringRangeFilter{ + fr := &stringRangeFilter{ fieldName: "foo", minValue: "33", maxValue: "5", } - testFilterMatchForColumns(t, columns, rf, "foo", []int{9, 10}) - rf = &stringRangeFilter{ + testFilterMatchForColumns(t, columns, fr, "foo", []int{9, 10}) + fr = &stringRangeFilter{ fieldName: "foo", minValue: "-0", maxValue: "-1", } - testFilterMatchForColumns(t, columns, rf, "foo", []int{6}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{6}) // mismatch - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "a", maxValue: "b", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "100", maxValue: "101", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "5", maxValue: "33", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("ipv4", func(t *testing.T) { @@ -1285,41 +1285,41 @@ func TestStringRangeFilter(t *testing.T) { } // match - rf := &stringRangeFilter{ + fr := &stringRangeFilter{ fieldName: "foo", minValue: "127.0.0", maxValue: "128.0.0.0", } - testFilterMatchForColumns(t, columns, rf, "foo", []int{2, 4, 5, 6, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{2, 4, 5, 6, 7}) // mismatch - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "a", maxValue: "b", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "128.0.0.0", maxValue: "129.0.0.0", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "255.0.0.0", maxValue: "255.255.255.255", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "foo", minValue: "128.0.0.0", maxValue: "", } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("timestamp-iso8601", func(t *testing.T) { @@ -1341,45 +1341,45 @@ func TestStringRangeFilter(t *testing.T) { } // match - rf := &stringRangeFilter{ + fr := &stringRangeFilter{ fieldName: "_msg", minValue: "2006-01-02", maxValue: "2006-01-03", } - testFilterMatchForColumns(t, columns, rf, "_msg", []int{2, 3}) + testFilterMatchForColumns(t, columns, fr, "_msg", []int{2, 3}) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "_msg", minValue: "", maxValue: "2006", } - testFilterMatchForColumns(t, columns, rf, "_msg", []int{0}) + testFilterMatchForColumns(t, columns, fr, "_msg", []int{0}) // mismatch - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "_msg", minValue: "3", maxValue: "4", } - testFilterMatchForColumns(t, columns, rf, "_msg", nil) + testFilterMatchForColumns(t, columns, fr, "_msg", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "_msg", minValue: "a", maxValue: "b", } - testFilterMatchForColumns(t, columns, rf, "_msg", nil) + testFilterMatchForColumns(t, columns, fr, "_msg", nil) - rf = &stringRangeFilter{ + fr = &stringRangeFilter{ fieldName: "_msg", minValue: "2006-01-03", maxValue: "2006-01-02", } - testFilterMatchForColumns(t, columns, rf, "_msg", nil) + testFilterMatchForColumns(t, columns, fr, "_msg", nil) }) } -func TestIPv4RangeFilter(t *testing.T) { +func TestFilterIPv4Range(t *testing.T) { t.Run("const-column", func(t *testing.T) { columns := []column{ { @@ -1393,41 +1393,41 @@ func TestIPv4RangeFilter(t *testing.T) { } // match - rf := &ipv4RangeFilter{ + fr := &filterIPv4Range{ fieldName: "foo", minValue: 0, maxValue: 0x80000000, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) - rf = &ipv4RangeFilter{ + fr = &filterIPv4Range{ fieldName: "foo", minValue: 0x7f000001, maxValue: 0x7f000001, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) // mismatch - rf = &ipv4RangeFilter{ + fr = &filterIPv4Range{ fieldName: "foo", minValue: 0, maxValue: 0x7f000000, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &ipv4RangeFilter{ + fr = &filterIPv4Range{ fieldName: "non-existing-column", minValue: 0, maxValue: 20000, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &ipv4RangeFilter{ + fr = &filterIPv4Range{ fieldName: "foo", minValue: 0x80000000, maxValue: 0, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("dict", func(t *testing.T) { @@ -1448,41 +1448,41 @@ func TestIPv4RangeFilter(t *testing.T) { } // match - rf := &ipv4RangeFilter{ + fr := &filterIPv4Range{ fieldName: "foo", minValue: 0x7f000000, maxValue: 0x80000000, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{1, 3, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{1, 3, 7}) - rf = &ipv4RangeFilter{ + fr = &filterIPv4Range{ fieldName: "foo", minValue: 0, maxValue: 0x7f000001, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{1, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{1, 7}) // mismatch - rf = &ipv4RangeFilter{ + fr = &filterIPv4Range{ fieldName: "foo", minValue: 0, maxValue: 1000, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &ipv4RangeFilter{ + fr = &filterIPv4Range{ fieldName: "foo", minValue: 0x7f000002, maxValue: 0x7f7f0000, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &ipv4RangeFilter{ + fr = &filterIPv4Range{ fieldName: "foo", minValue: 0x80000000, maxValue: 0x7f000000, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("strings", func(t *testing.T) { @@ -1505,27 +1505,27 @@ func TestIPv4RangeFilter(t *testing.T) { } // match - rf := &ipv4RangeFilter{ + fr := &filterIPv4Range{ fieldName: "foo", minValue: 0x7f000000, maxValue: 0xffffffff, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{2}) // mismatch - rf = &ipv4RangeFilter{ + fr = &filterIPv4Range{ fieldName: "foo", minValue: 0, maxValue: 10000, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &ipv4RangeFilter{ + fr = &filterIPv4Range{ fieldName: "foo", minValue: 0xffffffff, maxValue: 0x7f000000, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint8", func(t *testing.T) { @@ -1549,12 +1549,12 @@ func TestIPv4RangeFilter(t *testing.T) { } // mismatch - rf := &ipv4RangeFilter{ + fr := &filterIPv4Range{ fieldName: "foo", minValue: 0, maxValue: 0xffffffff, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint16", func(t *testing.T) { @@ -1578,12 +1578,12 @@ func TestIPv4RangeFilter(t *testing.T) { } // mismatch - rf := &ipv4RangeFilter{ + fr := &filterIPv4Range{ fieldName: "foo", minValue: 0, maxValue: 0xffffffff, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint32", func(t *testing.T) { @@ -1607,12 +1607,12 @@ func TestIPv4RangeFilter(t *testing.T) { } // mismatch - rf := &ipv4RangeFilter{ + fr := &filterIPv4Range{ fieldName: "foo", minValue: 0, maxValue: 0xffffffff, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint64", func(t *testing.T) { @@ -1636,12 +1636,12 @@ func TestIPv4RangeFilter(t *testing.T) { } // mismatch - rf := &ipv4RangeFilter{ + fr := &filterIPv4Range{ fieldName: "foo", minValue: 0, maxValue: 0xffffffff, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("float64", func(t *testing.T) { @@ -1665,12 +1665,12 @@ func TestIPv4RangeFilter(t *testing.T) { } // mismatch - rf := &ipv4RangeFilter{ + fr := &filterIPv4Range{ fieldName: "foo", minValue: 0, maxValue: 0xffffffff, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("ipv4", func(t *testing.T) { @@ -1695,34 +1695,34 @@ func TestIPv4RangeFilter(t *testing.T) { } // match - rf := &ipv4RangeFilter{ + fr := &filterIPv4Range{ fieldName: "foo", minValue: 0, maxValue: 0x08000000, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 11}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 11}) // mismatch - rf = &ipv4RangeFilter{ + fr = &filterIPv4Range{ fieldName: "foo", minValue: 0x80000000, maxValue: 0x90000000, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &ipv4RangeFilter{ + fr = &filterIPv4Range{ fieldName: "foo", minValue: 0xff000000, maxValue: 0xffffffff, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &ipv4RangeFilter{ + fr = &filterIPv4Range{ fieldName: "foo", minValue: 0x08000000, maxValue: 0, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("timestamp-iso8601", func(t *testing.T) { @@ -1744,12 +1744,12 @@ func TestIPv4RangeFilter(t *testing.T) { } // mismatch - rf := &ipv4RangeFilter{ + fr := &filterIPv4Range{ fieldName: "_msg", minValue: 0, maxValue: 0xffffffff, } - testFilterMatchForColumns(t, columns, rf, "_msg", nil) + testFilterMatchForColumns(t, columns, fr, "_msg", nil) }) } @@ -1767,34 +1767,34 @@ func TestLenRangeFilter(t *testing.T) { } // match - rf := &lenRangeFilter{ + fr := &lenRangeFilter{ fieldName: "foo", minLen: 2, maxLen: 20, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "non-existing-column", minLen: 0, maxLen: 10, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) // mismatch - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 3, maxLen: 20, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "non-existing-column", minLen: 10, maxLen: 20, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("dict", func(t *testing.T) { @@ -1814,27 +1814,27 @@ func TestLenRangeFilter(t *testing.T) { } // match - rf := &lenRangeFilter{ + fr := &lenRangeFilter{ fieldName: "foo", minLen: 2, maxLen: 3, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{1, 2, 3}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{1, 2, 3}) - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 0, maxLen: 1, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0}) // mismatch - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 20, maxLen: 30, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("strings", func(t *testing.T) { @@ -1857,20 +1857,20 @@ func TestLenRangeFilter(t *testing.T) { } // match - rf := &lenRangeFilter{ + fr := &lenRangeFilter{ fieldName: "foo", minLen: 2, maxLen: 3, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{2, 3, 5}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{2, 3, 5}) // mismatch - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 100, maxLen: 200, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint8", func(t *testing.T) { @@ -1894,27 +1894,27 @@ func TestLenRangeFilter(t *testing.T) { } // match - rf := &lenRangeFilter{ + fr := &lenRangeFilter{ fieldName: "foo", minLen: 2, maxLen: 2, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{2, 3, 6}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{2, 3, 6}) // mismatch - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 0, maxLen: 0, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 10, maxLen: 10, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint16", func(t *testing.T) { @@ -1938,27 +1938,27 @@ func TestLenRangeFilter(t *testing.T) { } // match - rf := &lenRangeFilter{ + fr := &lenRangeFilter{ fieldName: "foo", minLen: 2, maxLen: 2, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{2, 3, 6}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{2, 3, 6}) // mismatch - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 0, maxLen: 0, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 10, maxLen: 10, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint32", func(t *testing.T) { @@ -1982,27 +1982,27 @@ func TestLenRangeFilter(t *testing.T) { } // match - rf := &lenRangeFilter{ + fr := &lenRangeFilter{ fieldName: "foo", minLen: 2, maxLen: 2, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{2, 3, 6}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{2, 3, 6}) // mismatch - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 0, maxLen: 0, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 10, maxLen: 10, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint64", func(t *testing.T) { @@ -2026,27 +2026,27 @@ func TestLenRangeFilter(t *testing.T) { } // match - rf := &lenRangeFilter{ + fr := &lenRangeFilter{ fieldName: "foo", minLen: 2, maxLen: 2, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{2, 3, 6}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{2, 3, 6}) // mismatch - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 0, maxLen: 0, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 20, maxLen: 20, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("float64", func(t *testing.T) { @@ -2070,20 +2070,20 @@ func TestLenRangeFilter(t *testing.T) { } // match - rf := &lenRangeFilter{ + fr := &lenRangeFilter{ fieldName: "foo", minLen: 2, maxLen: 2, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{1, 2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{1, 2}) // mismatch - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 100, maxLen: 200, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("ipv4", func(t *testing.T) { @@ -2108,20 +2108,20 @@ func TestLenRangeFilter(t *testing.T) { } // match - rf := &lenRangeFilter{ + fr := &lenRangeFilter{ fieldName: "foo", minLen: 3, maxLen: 7, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 11}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 11}) // mismatch - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "foo", minLen: 20, maxLen: 30, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("timestamp-iso8601", func(t *testing.T) { @@ -2143,20 +2143,20 @@ func TestLenRangeFilter(t *testing.T) { } // match - rf := &lenRangeFilter{ + fr := &lenRangeFilter{ fieldName: "_msg", minLen: 10, maxLen: 30, } - testFilterMatchForColumns(t, columns, rf, "_msg", []int{0, 1, 2, 3, 4, 5, 6, 7, 8}) + testFilterMatchForColumns(t, columns, fr, "_msg", []int{0, 1, 2, 3, 4, 5, 6, 7, 8}) // mismatch - rf = &lenRangeFilter{ + fr = &lenRangeFilter{ fieldName: "_msg", minLen: 10, maxLen: 11, } - testFilterMatchForColumns(t, columns, rf, "_msg", nil) + testFilterMatchForColumns(t, columns, fr, "_msg", nil) }) } @@ -2174,62 +2174,62 @@ func TestRangeFilter(t *testing.T) { } // match - rf := &rangeFilter{ + fr := &rangeFilter{ fieldName: "foo", minValue: -10, maxValue: 20, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 10, maxValue: 10, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 10, maxValue: 20, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{0, 1, 2}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{0, 1, 2}) // mismatch - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -10, maxValue: 9.99, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 20, maxValue: -10, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 10.1, maxValue: 20, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "non-existing-column", minValue: 10, maxValue: 20, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 11, maxValue: 10, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("dict", func(t *testing.T) { @@ -2249,55 +2249,55 @@ func TestRangeFilter(t *testing.T) { } // match - rf := &rangeFilter{ + fr := &rangeFilter{ fieldName: "foo", minValue: -10, maxValue: 20, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{1, 3, 4}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{1, 3, 4}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 10, maxValue: 20, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{1, 3, 4}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{1, 3, 4}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 10.1, maxValue: 19.9, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{4}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{4}) // mismatch - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -11, maxValue: 0, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 11, maxValue: 19, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 20.1, maxValue: 100, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 20, maxValue: 10, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) @@ -2321,48 +2321,48 @@ func TestRangeFilter(t *testing.T) { } // match - rf := &rangeFilter{ + fr := &rangeFilter{ fieldName: "foo", minValue: -100, maxValue: 100, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{2, 3, 4, 5}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{2, 3, 4, 5}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 10, maxValue: 20, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{2, 3, 4}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{2, 3, 4}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -5, maxValue: -5, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{5}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{5}) // mismatch - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -10, maxValue: -5.1, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 20.1, maxValue: 100, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 20, maxValue: 10, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint8", func(t *testing.T) { @@ -2386,48 +2386,48 @@ func TestRangeFilter(t *testing.T) { } // match - rf := &rangeFilter{ + fr := &rangeFilter{ fieldName: "foo", minValue: 0, maxValue: 3, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{3, 4, 6, 7, 8}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7, 8}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 0.1, maxValue: 2.9, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{6, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{6, 7}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -1e18, maxValue: 2.9, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{3, 4, 6, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7}) // mismatch - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -1e18, maxValue: -0.1, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 0.1, maxValue: 0.9, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 2.9, maxValue: 0.1, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) @@ -2452,48 +2452,48 @@ func TestRangeFilter(t *testing.T) { } // match - rf := &rangeFilter{ + fr := &rangeFilter{ fieldName: "foo", minValue: 0, maxValue: 3, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{3, 4, 6, 7, 8}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7, 8}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 0.1, maxValue: 2.9, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{6, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{6, 7}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -1e18, maxValue: 2.9, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{3, 4, 6, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7}) // mismatch - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -1e18, maxValue: -0.1, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 0.1, maxValue: 0.9, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 2.9, maxValue: 0.1, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint32", func(t *testing.T) { @@ -2517,48 +2517,48 @@ func TestRangeFilter(t *testing.T) { } // match - rf := &rangeFilter{ + fr := &rangeFilter{ fieldName: "foo", minValue: 0, maxValue: 3, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{3, 4, 6, 7, 8}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7, 8}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 0.1, maxValue: 2.9, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{6, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{6, 7}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -1e18, maxValue: 2.9, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{3, 4, 6, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7}) // mismatch - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -1e18, maxValue: -0.1, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 0.1, maxValue: 0.9, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 2.9, maxValue: 0.1, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("uint64", func(t *testing.T) { @@ -2582,55 +2582,55 @@ func TestRangeFilter(t *testing.T) { } // match - rf := &rangeFilter{ + fr := &rangeFilter{ fieldName: "foo", minValue: math.Inf(-1), maxValue: 3, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{3, 4, 6, 7, 8}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7, 8}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 0.1, maxValue: 2.9, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{6, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{6, 7}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -1e18, maxValue: 2.9, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{3, 4, 6, 7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 1000, maxValue: math.Inf(1), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{5}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{5}) // mismatch - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -1e18, maxValue: -0.1, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 0.1, maxValue: 0.9, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 2.9, maxValue: 0.1, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("float64", func(t *testing.T) { @@ -2654,55 +2654,55 @@ func TestRangeFilter(t *testing.T) { } // match - rf := &rangeFilter{ + fr := &rangeFilter{ fieldName: "foo", minValue: math.Inf(-1), maxValue: 3, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{3, 4, 6, 7, 8}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 7, 8}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 0.1, maxValue: 2.9, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{7}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{7}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -1e18, maxValue: 1.9, } - testFilterMatchForColumns(t, columns, rf, "foo", []int{3, 4, 6, 8}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{3, 4, 6, 8}) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 1000, maxValue: math.Inf(1), } - testFilterMatchForColumns(t, columns, rf, "foo", []int{5}) + testFilterMatchForColumns(t, columns, fr, "foo", []int{5}) // mismatch - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: -1e18, maxValue: -334.1, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 0.1, maxValue: 0.9, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) - rf = &rangeFilter{ + fr = &rangeFilter{ fieldName: "foo", minValue: 2.9, maxValue: 0.1, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("ipv4", func(t *testing.T) { @@ -2727,12 +2727,12 @@ func TestRangeFilter(t *testing.T) { } // range filter always mismatches ipv4 - rf := &rangeFilter{ + fr := &rangeFilter{ fieldName: "foo", minValue: -100, maxValue: 100, } - testFilterMatchForColumns(t, columns, rf, "foo", nil) + testFilterMatchForColumns(t, columns, fr, "foo", nil) }) t.Run("timestamp-iso8601", func(t *testing.T) { @@ -2754,12 +2754,12 @@ func TestRangeFilter(t *testing.T) { } // range filter always mismatches timestmap - rf := &rangeFilter{ + fr := &rangeFilter{ fieldName: "_msg", minValue: -100, maxValue: 100, } - testFilterMatchForColumns(t, columns, rf, "_msg", nil) + testFilterMatchForColumns(t, columns, fr, "_msg", nil) }) } diff --git a/lib/logstorage/parser.go b/lib/logstorage/parser.go index 0a69636dc..9f2991cef 100644 --- a/lib/logstorage/parser.go +++ b/lib/logstorage/parser.go @@ -328,7 +328,7 @@ func parseGenericFilter(lex *lexer, fieldName string) (filter, error) { case lex.isKeyword("in"): return parseFilterIn(lex, fieldName) case lex.isKeyword("ipv4_range"): - return parseIPv4RangeFilter(lex, fieldName) + return parseFilterIPv4Range(lex, fieldName) case lex.isKeyword("len_range"): return parseLenRangeFilter(lex, fieldName) case lex.isKeyword("range"): @@ -531,14 +531,14 @@ func parseLenRangeFilter(lex *lexer, fieldName string) (filter, error) { return nil, fmt.Errorf("cannot parse maxLen at %s(): %w", funcName, err) } stringRepr := "(" + args[0] + ", " + args[1] + ")" - rf := &lenRangeFilter{ + fr := &lenRangeFilter{ fieldName: fieldName, minLen: minLen, maxLen: maxLen, stringRepr: stringRepr, } - return rf, nil + return fr, nil }) } @@ -548,16 +548,16 @@ func parseStringRangeFilter(lex *lexer, fieldName string) (filter, error) { if len(args) != 2 { return nil, fmt.Errorf("unexpected number of args for %s(); got %d; want 2", funcName, len(args)) } - rf := &stringRangeFilter{ + fr := &stringRangeFilter{ fieldName: fieldName, minValue: args[0], maxValue: args[1], } - return rf, nil + return fr, nil }) } -func parseIPv4RangeFilter(lex *lexer, fieldName string) (filter, error) { +func parseFilterIPv4Range(lex *lexer, fieldName string) (filter, error) { funcName := lex.token return parseFuncArgs(lex, fieldName, func(args []string) (filter, error) { if len(args) == 1 { @@ -565,12 +565,12 @@ func parseIPv4RangeFilter(lex *lexer, fieldName string) (filter, error) { if !ok { return nil, fmt.Errorf("cannot parse IPv4 address or IPv4 CIDR %q at %s()", args[0], funcName) } - rf := &ipv4RangeFilter{ + fr := &filterIPv4Range{ fieldName: fieldName, minValue: minValue, maxValue: maxValue, } - return rf, nil + return fr, nil } if len(args) != 2 { return nil, fmt.Errorf("unexpected number of args for %s(); got %d; want 2", funcName, len(args)) @@ -583,12 +583,12 @@ func parseIPv4RangeFilter(lex *lexer, fieldName string) (filter, error) { if !ok { return nil, fmt.Errorf("cannot parse upper bound ip %q in %s()", funcName, args[1]) } - rf := &ipv4RangeFilter{ + fr := &filterIPv4Range{ fieldName: fieldName, minValue: minValue, maxValue: maxValue, } - return rf, nil + return fr, nil }) } @@ -656,11 +656,11 @@ func parseRegexpFilter(lex *lexer, fieldName string) (filter, error) { if err != nil { return nil, fmt.Errorf("invalid regexp %q for %s(): %w", arg, funcName, err) } - rf := ®expFilter{ + fr := ®expFilter{ fieldName: fieldName, re: re, } - return rf, nil + return fr, nil }) } @@ -726,14 +726,14 @@ func parseRangeFilter(lex *lexer, fieldName string) (filter, error) { maxValue = math.Nextafter(maxValue, math.Inf(-1)) } - rf := &rangeFilter{ + fr := &rangeFilter{ fieldName: fieldName, minValue: minValue, maxValue: maxValue, stringRepr: stringRepr, } - return rf, nil + return fr, nil } func parseFloat64(lex *lexer) (float64, string, error) { diff --git a/lib/logstorage/parser_test.go b/lib/logstorage/parser_test.go index 12fa1e6f0..e1b238f77 100644 --- a/lib/logstorage/parser_test.go +++ b/lib/logstorage/parser_test.go @@ -325,16 +325,16 @@ func TestParseFilterIn(t *testing.T) { f(`foo-bar:in(foo,bar-baz.aa"bb","c,)d")`, `foo-bar`, []string{"foo", `bar-baz.aa"bb"`, "c,)d"}) } -func TestParseIPv4RangeFilter(t *testing.T) { +func TestParseFilterIPv4Range(t *testing.T) { f := func(s, fieldNameExpected string, minValueExpected, maxValueExpected uint32) { t.Helper() q, err := ParseQuery(s) if err != nil { t.Fatalf("unexpected error: %s", err) } - rf, ok := q.f.(*ipv4RangeFilter) + rf, ok := q.f.(*filterIPv4Range) if !ok { - t.Fatalf("unexpected filter type; got %T; want *ipv4RangeFilter; filter: %s", q.f, q.f) + 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) @@ -519,7 +519,7 @@ func TestParseRangeFilter(t *testing.T) { } rf, ok := q.f.(*rangeFilter) if !ok { - t.Fatalf("unexpected filter type; got %T; want *ipv4RangeFilter; filter: %s", q.f, q.f) + 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)