lib/logstorage: substitute | operator with or operator at math pipe

This is needed for avoiding confusion between the `|` operator at `math` pipe and `|` pipe delimiter.
For example, the following query was parsed unexpectedly:

   * | math foo / bar | fields x

as

   * | math foo / (bar | fields) as x

Substituting `|` with `or` inside `math` pipe fixes this ambiguity.
This commit is contained in:
Aliaksandr Valialkin 2024-09-06 22:40:53 +02:00
parent 95acca6b52
commit 00e7d5add3
No known key found for this signature in database
GPG Key ID: 52C003EE2BCDB9EB
3 changed files with 3 additions and 3 deletions

View File

@ -1799,7 +1799,7 @@ The following mathematical operations are supported by `math` pipe:
- `arg1 % arg2` - returns the remainder of the division of `arg1` by `arg2` - `arg1 % arg2` - returns the remainder of the division of `arg1` by `arg2`
- `arg1 ^ arg2` - returns the power of `arg1` by `arg2` - `arg1 ^ arg2` - returns the power of `arg1` by `arg2`
- `arg1 & arg2` - returns bitwise `and` for `arg1` and `arg2`. It is expected that `arg1` and `arg2` are in the range `[0 .. 2^53-1]` - `arg1 & arg2` - returns bitwise `and` for `arg1` and `arg2`. It is expected that `arg1` and `arg2` are in the range `[0 .. 2^53-1]`
- `arg1 | arg2` - returns bitwise `or` for `arg1` and `arg2`. It is expected that `arg1` and `arg2` are in the range `[0 .. 2^53-1]` - `arg1 or arg2` - returns bitwise `or` for `arg1` and `arg2`. It is expected that `arg1` and `arg2` are in the range `[0 .. 2^53-1]`
- `arg1 xor arg2` - returns bitwise `xor` for `arg1` and `arg2`. It is expected that `arg1` and `arg2` are in the range `[0 .. 2^53-1]` - `arg1 xor arg2` - returns bitwise `xor` for `arg1` and `arg2`. It is expected that `arg1` and `arg2` are in the range `[0 .. 2^53-1]`
- `arg1 default arg2` - returns `arg2` if `arg1` is non-[numeric](#numeric-values) or equals to `NaN` - `arg1 default arg2` - returns `arg2` if `arg1` is non-[numeric](#numeric-values) or equals to `NaN`
- `abs(arg)` - returns an absolute value for the given `arg` - `abs(arg)` - returns an absolute value for the given `arg`

View File

@ -173,7 +173,7 @@ var mathBinaryOps = map[string]mathBinaryOp{
priority: 5, priority: 5,
f: mathFuncXor, f: mathFuncXor,
}, },
"|": { "or": {
priority: 6, priority: 6,
f: mathFuncOr, f: mathFuncOr,
}, },

View File

@ -56,7 +56,7 @@ func TestPipeMath(t *testing.T) {
'123.45.67.89' + 1000 as ip, '123.45.67.89' + 1000 as ip,
time - time % time_step as time_rounded, time - time % time_step as time_rounded,
duration - duration % duration_step as duration_rounded, duration - duration % duration_step as duration_rounded,
(ip & ip_mask | 0x1234) xor 5678 as subnet (ip & ip_mask or 0x1234) xor 5678 as subnet
`, [][]Field{ `, [][]Field{
{ {
{"time_step", "30m"}, {"time_step", "30m"},