mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-20 15:16:42 +00:00
wip
This commit is contained in:
parent
2a1cede9f7
commit
22615889a7
4 changed files with 398 additions and 398 deletions
|
@ -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)`
|
// Example LogsQL: `fieldName:ipv4_range(127.0.0.1, 127.0.0.255)`
|
||||||
type ipv4RangeFilter struct {
|
type filterIPv4Range struct {
|
||||||
fieldName string
|
fieldName string
|
||||||
minValue uint32
|
minValue uint32
|
||||||
maxValue uint32
|
maxValue uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rf *ipv4RangeFilter) String() string {
|
func (fr *filterIPv4Range) String() string {
|
||||||
minValue := string(encoding.MarshalUint32(nil, rf.minValue))
|
minValue := string(encoding.MarshalUint32(nil, fr.minValue))
|
||||||
maxValue := string(encoding.MarshalUint32(nil, rf.maxValue))
|
maxValue := string(encoding.MarshalUint32(nil, fr.maxValue))
|
||||||
return fmt.Sprintf("%sipv4_range(%s, %s)", quoteFieldNameIfNeeded(rf.fieldName), toIPv4String(nil, minValue), toIPv4String(nil, 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) {
|
func (fr *filterIPv4Range) apply(bs *blockSearch, bm *bitmap) {
|
||||||
fieldName := rf.fieldName
|
fieldName := fr.fieldName
|
||||||
minValue := rf.minValue
|
minValue := fr.minValue
|
||||||
maxValue := rf.maxValue
|
maxValue := fr.maxValue
|
||||||
|
|
||||||
if minValue > maxValue {
|
if minValue > maxValue {
|
||||||
bm.resetBits()
|
bm.resetBits()
|
||||||
|
@ -149,14 +149,14 @@ type stringRangeFilter struct {
|
||||||
maxValue string
|
maxValue string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rf *stringRangeFilter) String() string {
|
func (fr *stringRangeFilter) String() string {
|
||||||
return fmt.Sprintf("%sstring_range(%s, %s)", quoteFieldNameIfNeeded(rf.fieldName), quoteTokenIfNeeded(rf.minValue), quoteTokenIfNeeded(rf.maxValue))
|
return fmt.Sprintf("%sstring_range(%s, %s)", quoteFieldNameIfNeeded(fr.fieldName), quoteTokenIfNeeded(fr.minValue), quoteTokenIfNeeded(fr.maxValue))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rf *stringRangeFilter) apply(bs *blockSearch, bm *bitmap) {
|
func (fr *stringRangeFilter) apply(bs *blockSearch, bm *bitmap) {
|
||||||
fieldName := rf.fieldName
|
fieldName := fr.fieldName
|
||||||
minValue := rf.minValue
|
minValue := fr.minValue
|
||||||
maxValue := rf.maxValue
|
maxValue := fr.maxValue
|
||||||
|
|
||||||
if minValue > maxValue {
|
if minValue > maxValue {
|
||||||
bm.resetBits()
|
bm.resetBits()
|
||||||
|
@ -215,14 +215,14 @@ type lenRangeFilter struct {
|
||||||
stringRepr string
|
stringRepr string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rf *lenRangeFilter) String() string {
|
func (fr *lenRangeFilter) String() string {
|
||||||
return quoteFieldNameIfNeeded(rf.fieldName) + "len_range" + rf.stringRepr
|
return quoteFieldNameIfNeeded(fr.fieldName) + "len_range" + fr.stringRepr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rf *lenRangeFilter) apply(bs *blockSearch, bm *bitmap) {
|
func (fr *lenRangeFilter) apply(bs *blockSearch, bm *bitmap) {
|
||||||
fieldName := rf.fieldName
|
fieldName := fr.fieldName
|
||||||
minLen := rf.minLen
|
minLen := fr.minLen
|
||||||
maxLen := rf.maxLen
|
maxLen := fr.maxLen
|
||||||
|
|
||||||
if minLen > maxLen {
|
if minLen > maxLen {
|
||||||
bm.resetBits()
|
bm.resetBits()
|
||||||
|
@ -282,14 +282,14 @@ type rangeFilter struct {
|
||||||
stringRepr string
|
stringRepr string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rf *rangeFilter) String() string {
|
func (fr *rangeFilter) String() string {
|
||||||
return quoteFieldNameIfNeeded(rf.fieldName) + "range" + rf.stringRepr
|
return quoteFieldNameIfNeeded(fr.fieldName) + "range" + fr.stringRepr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rf *rangeFilter) apply(bs *blockSearch, bm *bitmap) {
|
func (fr *rangeFilter) apply(bs *blockSearch, bm *bitmap) {
|
||||||
fieldName := rf.fieldName
|
fieldName := fr.fieldName
|
||||||
minValue := rf.minValue
|
minValue := fr.minValue
|
||||||
maxValue := rf.maxValue
|
maxValue := fr.maxValue
|
||||||
|
|
||||||
if minValue > maxValue {
|
if minValue > maxValue {
|
||||||
bm.resetBits()
|
bm.resetBits()
|
||||||
|
@ -344,13 +344,13 @@ type regexpFilter struct {
|
||||||
re *regexp.Regexp
|
re *regexp.Regexp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rf *regexpFilter) String() string {
|
func (fr *regexpFilter) String() string {
|
||||||
return fmt.Sprintf("%sre(%q)", quoteFieldNameIfNeeded(rf.fieldName), rf.re.String())
|
return fmt.Sprintf("%sre(%q)", quoteFieldNameIfNeeded(fr.fieldName), fr.re.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rf *regexpFilter) apply(bs *blockSearch, bm *bitmap) {
|
func (fr *regexpFilter) apply(bs *blockSearch, bm *bitmap) {
|
||||||
fieldName := rf.fieldName
|
fieldName := fr.fieldName
|
||||||
re := rf.re
|
re := fr.re
|
||||||
|
|
||||||
// Verify whether filter matches const column
|
// Verify whether filter matches const column
|
||||||
v := bs.csh.getConstColumnValue(fieldName)
|
v := bs.csh.getConstColumnValue(fieldName)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -328,7 +328,7 @@ func parseGenericFilter(lex *lexer, fieldName string) (filter, error) {
|
||||||
case lex.isKeyword("in"):
|
case lex.isKeyword("in"):
|
||||||
return parseFilterIn(lex, fieldName)
|
return parseFilterIn(lex, fieldName)
|
||||||
case lex.isKeyword("ipv4_range"):
|
case lex.isKeyword("ipv4_range"):
|
||||||
return parseIPv4RangeFilter(lex, fieldName)
|
return parseFilterIPv4Range(lex, fieldName)
|
||||||
case lex.isKeyword("len_range"):
|
case lex.isKeyword("len_range"):
|
||||||
return parseLenRangeFilter(lex, fieldName)
|
return parseLenRangeFilter(lex, fieldName)
|
||||||
case lex.isKeyword("range"):
|
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)
|
return nil, fmt.Errorf("cannot parse maxLen at %s(): %w", funcName, err)
|
||||||
}
|
}
|
||||||
stringRepr := "(" + args[0] + ", " + args[1] + ")"
|
stringRepr := "(" + args[0] + ", " + args[1] + ")"
|
||||||
rf := &lenRangeFilter{
|
fr := &lenRangeFilter{
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
minLen: minLen,
|
minLen: minLen,
|
||||||
maxLen: maxLen,
|
maxLen: maxLen,
|
||||||
|
|
||||||
stringRepr: stringRepr,
|
stringRepr: stringRepr,
|
||||||
}
|
}
|
||||||
return rf, nil
|
return fr, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -548,16 +548,16 @@ func parseStringRangeFilter(lex *lexer, fieldName string) (filter, error) {
|
||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
return nil, fmt.Errorf("unexpected number of args for %s(); got %d; want 2", funcName, len(args))
|
return nil, fmt.Errorf("unexpected number of args for %s(); got %d; want 2", funcName, len(args))
|
||||||
}
|
}
|
||||||
rf := &stringRangeFilter{
|
fr := &stringRangeFilter{
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
minValue: args[0],
|
minValue: args[0],
|
||||||
maxValue: args[1],
|
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
|
funcName := lex.token
|
||||||
return parseFuncArgs(lex, fieldName, func(args []string) (filter, error) {
|
return parseFuncArgs(lex, fieldName, func(args []string) (filter, error) {
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
|
@ -565,12 +565,12 @@ func parseIPv4RangeFilter(lex *lexer, fieldName string) (filter, error) {
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("cannot parse IPv4 address or IPv4 CIDR %q at %s()", args[0], funcName)
|
return nil, fmt.Errorf("cannot parse IPv4 address or IPv4 CIDR %q at %s()", args[0], funcName)
|
||||||
}
|
}
|
||||||
rf := &ipv4RangeFilter{
|
fr := &filterIPv4Range{
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
minValue: minValue,
|
minValue: minValue,
|
||||||
maxValue: maxValue,
|
maxValue: maxValue,
|
||||||
}
|
}
|
||||||
return rf, nil
|
return fr, nil
|
||||||
}
|
}
|
||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
return nil, fmt.Errorf("unexpected number of args for %s(); got %d; want 2", funcName, len(args))
|
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 {
|
if !ok {
|
||||||
return nil, fmt.Errorf("cannot parse upper bound ip %q in %s()", funcName, args[1])
|
return nil, fmt.Errorf("cannot parse upper bound ip %q in %s()", funcName, args[1])
|
||||||
}
|
}
|
||||||
rf := &ipv4RangeFilter{
|
fr := &filterIPv4Range{
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
minValue: minValue,
|
minValue: minValue,
|
||||||
maxValue: maxValue,
|
maxValue: maxValue,
|
||||||
}
|
}
|
||||||
return rf, nil
|
return fr, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -656,11 +656,11 @@ func parseRegexpFilter(lex *lexer, fieldName string) (filter, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid regexp %q for %s(): %w", arg, funcName, err)
|
return nil, fmt.Errorf("invalid regexp %q for %s(): %w", arg, funcName, err)
|
||||||
}
|
}
|
||||||
rf := ®expFilter{
|
fr := ®expFilter{
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
re: re,
|
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))
|
maxValue = math.Nextafter(maxValue, math.Inf(-1))
|
||||||
}
|
}
|
||||||
|
|
||||||
rf := &rangeFilter{
|
fr := &rangeFilter{
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
minValue: minValue,
|
minValue: minValue,
|
||||||
maxValue: maxValue,
|
maxValue: maxValue,
|
||||||
|
|
||||||
stringRepr: stringRepr,
|
stringRepr: stringRepr,
|
||||||
}
|
}
|
||||||
return rf, nil
|
return fr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseFloat64(lex *lexer) (float64, string, error) {
|
func parseFloat64(lex *lexer) (float64, string, error) {
|
||||||
|
|
|
@ -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"})
|
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) {
|
f := func(s, fieldNameExpected string, minValueExpected, maxValueExpected uint32) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
q, err := ParseQuery(s)
|
q, err := ParseQuery(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %s", err)
|
t.Fatalf("unexpected error: %s", err)
|
||||||
}
|
}
|
||||||
rf, ok := q.f.(*ipv4RangeFilter)
|
rf, ok := q.f.(*filterIPv4Range)
|
||||||
if !ok {
|
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 {
|
if rf.fieldName != fieldNameExpected {
|
||||||
t.Fatalf("unexpected fieldName; got %q; want %q", 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)
|
rf, ok := q.f.(*rangeFilter)
|
||||||
if !ok {
|
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 {
|
if rf.fieldName != fieldNameExpected {
|
||||||
t.Fatalf("unexpected fieldName; got %q; want %q", rf.fieldName, fieldNameExpected)
|
t.Fatalf("unexpected fieldName; got %q; want %q", rf.fieldName, fieldNameExpected)
|
||||||
|
|
Loading…
Reference in a new issue