From c5badeea08943bbffb3fabe96274c374b287aab2 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 6 Sep 2024 22:40:53 +0200 Subject: [PATCH] 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. --- docs/VictoriaLogs/LogsQL.md | 2 +- lib/logstorage/pipe_math.go | 2 +- lib/logstorage/pipe_math_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/VictoriaLogs/LogsQL.md b/docs/VictoriaLogs/LogsQL.md index 974ba9c242..0bac580af4 100644 --- a/docs/VictoriaLogs/LogsQL.md +++ b/docs/VictoriaLogs/LogsQL.md @@ -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 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 `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 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` diff --git a/lib/logstorage/pipe_math.go b/lib/logstorage/pipe_math.go index a9b86f453c..7ce50bfb13 100644 --- a/lib/logstorage/pipe_math.go +++ b/lib/logstorage/pipe_math.go @@ -173,7 +173,7 @@ var mathBinaryOps = map[string]mathBinaryOp{ priority: 5, f: mathFuncXor, }, - "|": { + "or": { priority: 6, f: mathFuncOr, }, diff --git a/lib/logstorage/pipe_math_test.go b/lib/logstorage/pipe_math_test.go index 40b7dee50c..0425ff405e 100644 --- a/lib/logstorage/pipe_math_test.go +++ b/lib/logstorage/pipe_math_test.go @@ -56,7 +56,7 @@ func TestPipeMath(t *testing.T) { '123.45.67.89' + 1000 as ip, time - time % time_step as time_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{ { {"time_step", "30m"},