This commit is contained in:
Aliaksandr Valialkin 2024-06-05 02:09:56 +02:00
parent 87174246e5
commit 42359ceecf
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
3 changed files with 29 additions and 25 deletions

View file

@ -207,5 +207,5 @@ func matchUint64ByStringRange(bs *blockSearch, ch *columnHeader, bm *bitmap, min
} }
func matchStringRange(s, minValue, maxValue string) bool { func matchStringRange(s, minValue, maxValue string) bool {
return s >= minValue && s < maxValue return !lessString(s, minValue) && lessString(s, maxValue)
} }

View file

@ -1130,18 +1130,15 @@ func parseFilterGT(lex *lexer, fieldName string) (filter, error) {
op = ">=" op = ">="
} }
if !lex.isNumber() { lexState := lex.backupState()
lexState := lex.backupState() minValue, fStr, err := parseNumber(lex)
fr := tryParseFilterGTString(lex, fieldName, op, includeMinValue)
if fr != nil {
return fr, nil
}
lex.restoreState(lexState)
}
minValue, fStr, err := parseFloat64(lex)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot parse number after '%s': %w", op, err) lex.restoreState(lexState)
fr := tryParseFilterGTString(lex, fieldName, op, includeMinValue)
if fr == nil {
return nil, fmt.Errorf("cannot parse [%s] as number: %w", fStr, err)
}
return fr, nil
} }
if !includeMinValue { if !includeMinValue {
@ -1168,16 +1165,17 @@ func parseFilterLT(lex *lexer, fieldName string) (filter, error) {
op = "<=" op = "<="
} }
if !lex.isNumber() { lexState := lex.backupState()
lexState := lex.backupState() maxValue, fStr, err := parseNumber(lex)
fr := tryParseFilterLTString(lex, fieldName, op, includeMaxValue) if err != nil {
if fr != nil {
return fr, nil
}
lex.restoreState(lexState) lex.restoreState(lexState)
fr := tryParseFilterLTString(lex, fieldName, op, includeMaxValue)
if fr == nil {
return nil, fmt.Errorf("cannot parse [%s] as number: %w", fStr, err)
}
return fr, nil
} }
maxValue, fStr, err := parseFloat64(lex)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot parse number after '%s': %w", op, err) return nil, fmt.Errorf("cannot parse number after '%s': %w", op, err)
} }
@ -1250,7 +1248,7 @@ func parseFilterRange(lex *lexer, fieldName string) (filter, error) {
if !lex.mustNextToken() { if !lex.mustNextToken() {
return nil, fmt.Errorf("missing args for %s()", funcName) return nil, fmt.Errorf("missing args for %s()", funcName)
} }
minValue, minValueStr, err := parseFloat64(lex) minValue, minValueStr, err := parseNumber(lex)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot parse minValue in %s(): %w", funcName, err) return nil, fmt.Errorf("cannot parse minValue in %s(): %w", funcName, err)
} }
@ -1264,7 +1262,7 @@ func parseFilterRange(lex *lexer, fieldName string) (filter, error) {
} }
// Parse maxValue // Parse maxValue
maxValue, maxValueStr, err := parseFloat64(lex) maxValue, maxValueStr, err := parseNumber(lex)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot parse maxValue in %s(): %w", funcName, err) return nil, fmt.Errorf("cannot parse maxValue in %s(): %w", funcName, err)
} }
@ -1304,7 +1302,7 @@ func parseFilterRange(lex *lexer, fieldName string) (filter, error) {
return fr, nil return fr, nil
} }
func parseFloat64(lex *lexer) (float64, string, error) { func parseNumber(lex *lexer) (float64, string, error) {
s, err := getCompoundToken(lex) s, err := getCompoundToken(lex)
if err != nil { if err != nil {
return 0, "", fmt.Errorf("cannot parse float64 from %q: %w", s, err) return 0, "", fmt.Errorf("cannot parse float64 from %q: %w", s, err)

View file

@ -356,7 +356,7 @@ func TestParseFilterStringRange(t *testing.T) {
f(">foo", ``, "foo\x00", maxStringRangeValue) f(">foo", ``, "foo\x00", maxStringRangeValue)
f("x:>=foo", `x`, "foo", maxStringRangeValue) f("x:>=foo", `x`, "foo", maxStringRangeValue)
f("x:<foo", `x`, ``, `foo`) f("x:<foo", `x`, ``, `foo`)
f(`<="123"`, ``, ``, "123\x00") f(`<="123.456.789"`, ``, ``, "123.456.789\x00")
} }
func TestParseFilterRegexp(t *testing.T) { func TestParseFilterRegexp(t *testing.T) {
@ -535,6 +535,12 @@ func TestParseRangeFilter(t *testing.T) {
f(`foo: < -10.43`, `foo`, -inf, nextafter(-10.43, -inf)) f(`foo: < -10.43`, `foo`, -inf, nextafter(-10.43, -inf))
f(`foo:<=10.43ms`, `foo`, -inf, 10_430_000) f(`foo:<=10.43ms`, `foo`, -inf, 10_430_000)
f(`foo: <= 10.43`, `foo`, -inf, 10.43) f(`foo: <= 10.43`, `foo`, -inf, 10.43)
f(`foo:<=1.2.3.4`, `foo`, -inf, 16909060)
f(`foo:<='1.2.3.4'`, `foo`, -inf, 16909060)
f(`foo:>=0xffffffff`, `foo`, (1<<32)-1, inf)
f(`foo:>=1_234e3`, `foo`, 1234000, inf)
f(`foo:>=1_234e-3`, `foo`, 1.234, inf)
} }
func TestParseQuerySuccess(t *testing.T) { func TestParseQuerySuccess(t *testing.T) {
@ -811,10 +817,10 @@ func TestParseQuerySuccess(t *testing.T) {
f(`string_range(foo, bar)`, `string_range(foo, bar)`) f(`string_range(foo, bar)`, `string_range(foo, bar)`)
f(`foo:string_range("foo, bar", baz)`, `foo:string_range("foo, bar", baz)`) f(`foo:string_range("foo, bar", baz)`, `foo:string_range("foo, bar", baz)`)
f(`foo:>bar`, `foo:>bar`) f(`foo:>bar`, `foo:>bar`)
f(`foo:>"1234"`, `foo:>"1234"`) f(`foo:>"1234"`, `foo:>1234`)
f(`>="abc"`, `>=abc`) f(`>="abc"`, `>=abc`)
f(`foo:<bar`, `foo:<bar`) f(`foo:<bar`, `foo:<bar`)
f(`foo:<"-12.34"`, `foo:<"-12.34"`) f(`foo:<"-12.34"`, `foo:<-12.34`)
f(`<="abc < de"`, `<="abc < de"`) f(`<="abc < de"`, `<="abc < de"`)
// reserved field names // reserved field names