mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/logstorage: allow using eval
keyword instead of math
keyword in math
pipe
This commit is contained in:
parent
868c4c0253
commit
80a7c65ab7
5 changed files with 21 additions and 4 deletions
|
@ -19,6 +19,8 @@ according to [these docs](https://docs.victoriametrics.com/victorialogs/quicksta
|
||||||
|
|
||||||
## tip
|
## tip
|
||||||
|
|
||||||
|
* FEATURE: allow using `eval` instead of `math` keyword in [`math` pipe](https://docs.victoriametrics.com/victorialogs/logsql/#math-pipe).
|
||||||
|
|
||||||
## [v0.17.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v0.17.0-victorialogs)
|
## [v0.17.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v0.17.0-victorialogs)
|
||||||
|
|
||||||
Released at 2024-06-05
|
Released at 2024-06-05
|
||||||
|
|
|
@ -1681,10 +1681,25 @@ Every `argX` argument in every mathematical operation can contain one of the fol
|
||||||
- Any [supported numeric value](#numeric-values), [rfc3339 time](https://www.rfc-editor.org/rfc/rfc3339) or IPv4 address. For example, `1MiB`, `"2024-05-15T10:20:30.934324Z"` or `"12.34.56.78"`.
|
- Any [supported numeric value](#numeric-values), [rfc3339 time](https://www.rfc-editor.org/rfc/rfc3339) or IPv4 address. For example, `1MiB`, `"2024-05-15T10:20:30.934324Z"` or `"12.34.56.78"`.
|
||||||
- Another mathematical expression, which can be put inside `(...)`. For example, `(a + b) * c`.
|
- Another mathematical expression, which can be put inside `(...)`. For example, `(a + b) * c`.
|
||||||
|
|
||||||
|
The parsed time, duration and IPv4 address can be converted back to string representation after math transformations with the help of [`format` pipe](#format-pipe). For example,
|
||||||
|
the following query rounds the `request_duration` [field](https://docs.victoriametrics.com/victorialogs/keyconcepts/#data-model) to seconds before converting it back to string representation:
|
||||||
|
|
||||||
|
```logsql
|
||||||
|
_time:5m | math round(request_duration, 1e9) as request_duration_nsecs | format '<duration:request_duration_nsecs>' as request_duration
|
||||||
|
```
|
||||||
|
|
||||||
|
The `eval` keyword can be used instead of `math` for convenince. For example, the following query calculates `duration_msecs` field
|
||||||
|
by multiplying `duration_secs` [field](https://docs.victoriametrics.com/victorialogs/keyconcepts/#data-model) to `1000`:
|
||||||
|
|
||||||
|
```logsql
|
||||||
|
_time:5m | eval (duration_secs * 1000) as duration_msecs
|
||||||
|
```
|
||||||
|
|
||||||
See also:
|
See also:
|
||||||
|
|
||||||
- [`stats` pipe](#stats-pipe)
|
- [`stats` pipe](#stats-pipe)
|
||||||
- [`extract` pipe](#extract-pipe)
|
- [`extract` pipe](#extract-pipe)
|
||||||
|
- [`format` pipe](#format-pipe)
|
||||||
|
|
||||||
|
|
||||||
### offset pipe
|
### offset pipe
|
||||||
|
|
|
@ -160,7 +160,7 @@ func parsePipe(lex *lexer) (pipe, error) {
|
||||||
return nil, fmt.Errorf("cannot parse 'limit' pipe: %w", err)
|
return nil, fmt.Errorf("cannot parse 'limit' pipe: %w", err)
|
||||||
}
|
}
|
||||||
return pl, nil
|
return pl, nil
|
||||||
case lex.isKeyword("math"):
|
case lex.isKeyword("math", "eval"):
|
||||||
pm, err := parsePipeMath(lex)
|
pm, err := parsePipeMath(lex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot parse 'math' pipe: %w", err)
|
return nil, fmt.Errorf("cannot parse 'math' pipe: %w", err)
|
||||||
|
|
|
@ -356,8 +356,8 @@ func (pmp *pipeMathProcessor) flush() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func parsePipeMath(lex *lexer) (*pipeMath, error) {
|
func parsePipeMath(lex *lexer) (*pipeMath, error) {
|
||||||
if !lex.isKeyword("math") {
|
if !lex.isKeyword("math", "eval") {
|
||||||
return nil, fmt.Errorf("unexpected token: %q; want %q", lex.token, "math")
|
return nil, fmt.Errorf("unexpected token: %q; want 'math' or 'eval'", lex.token)
|
||||||
}
|
}
|
||||||
lex.nextToken()
|
lex.nextToken()
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ func TestPipeMath(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
f("math b+1 as a, a*2 as b, b-10.5+c as c", [][]Field{
|
f("eval b+1 as a, a*2 as b, b-10.5+c as c", [][]Field{
|
||||||
{
|
{
|
||||||
{"a", "v1"},
|
{"a", "v1"},
|
||||||
{"b", "2"},
|
{"b", "2"},
|
||||||
|
|
Loading…
Reference in a new issue