Skip to content

Commit aa4c3a0

Browse files
committed
docs/victorialogs/logsql.md: document how to filter out empty field values when calculating min, max, median and quantile
The min, max, median and quantile functions work with string field values, since strings can be sorted. So there is min, max, median and quantile across string values. Empty field fields equal to non-existing values according to VictoriaLogs data model (see https://docs.victoriametrics.com/victorialogs/keyconcepts/#data-model ). If some log has missing field requested in the min, max, median or quantile functions, then these functions receive an empty value. Such an empty value can affect function results in unexpected ways. So it is recommended removing empty results if needed with the conditional stats functionality ( https://docs.victoriametrics.com/victorialogs/logsql/#stats-with-additional-filters ): min(some_field) if (some_field:*) The `some_field:*` filter skips empty values ( see https://docs.victoriametrics.com/victorialogs/logsql/#any-value-filter ) Updates #95
1 parent d85fca8 commit aa4c3a0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/victorialogs/logsql.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4532,6 +4532,11 @@ over logs for the last 5 minutes:
45324532
_time:5m | stats max(duration) max_duration
45334533
```
45344534

4535+
The `max(some_field)` function works with string values for the `some_field`, so it returns an empty string value if `some_field`
4536+
is missing in some of the processed logs according to [VictoriaLogs data model](https://docs.victoriametrics.com/victorialogs/keyconcepts/#data-model).
4537+
Use `max(some_field) if (some_field:*) as min_value_without_empty_string` syntax for filtering out empty string values.
4538+
See [conditional stats docs](https://docs.victoriametrics.com/victorialogs/logsql/#stats-with-additional-filters) for more details.
4539+
45354540
It is possible to calculate the maximum value across all the fields with common prefix via `max(prefix*)` syntax.
45364541

45374542
[`row_max`](https://docs.victoriametrics.com/victorialogs/logsql/#row_max-stats) function can be used for obtaining other fields with the maximum duration.
@@ -4555,6 +4560,11 @@ over logs for the last 5 minutes:
45554560
_time:5m | stats median(duration) median_duration
45564561
```
45574562

4563+
The `median(some_field)` function works with string values for the `some_field`, so it returns an empty string value if `some_field`
4564+
is missing in some of the processed logs according to [VictoriaLogs data model](https://docs.victoriametrics.com/victorialogs/keyconcepts/#data-model).
4565+
Use `median(some_field) if (some_field:*) as min_value_without_empty_string` syntax for filtering out empty string values.
4566+
See [conditional stats docs](https://docs.victoriametrics.com/victorialogs/logsql/#stats-with-additional-filters) for more details.
4567+
45584568
It is possible to calculate the median across all the fields with common prefix via `median(prefix*)` syntax.
45594569

45604570
See also:
@@ -4574,6 +4584,11 @@ over logs for the last 5 minutes:
45744584
_time:5m | stats min(duration) min_duration
45754585
```
45764586

4587+
The `min(some_field)` function works with string values for the `some_field`, so it returns an empty string value if `some_field`
4588+
is missing in some of the processed logs according to [VictoriaLogs data model](https://docs.victoriametrics.com/victorialogs/keyconcepts/#data-model).
4589+
Use `min(some_field) if (some_field:*) as min_value_without_empty_string` syntax for filtering out empty string values.
4590+
See [conditional stats docs](https://docs.victoriametrics.com/victorialogs/logsql/#stats-with-additional-filters) for more details.
4591+
45774592
It is possible to find the minimum across all the fields with common prefix via `min(prefix*)` syntax.
45784593

45794594
[`row_min`](https://docs.victoriametrics.com/victorialogs/logsql/#row_min-stats) function can be used for obtaining other fields with the minimum duration.
@@ -4601,6 +4616,11 @@ _time:5m | stats
46014616
quantile(0.99, request_duration_seconds) p99
46024617
```
46034618

4619+
The `quantile(phi, some_field)` function works with string values for the `some_field`, so it returns an empty string value if `some_field`
4620+
is missing in some of the processed logs according to [VictoriaLogs data model](https://docs.victoriametrics.com/victorialogs/keyconcepts/#data-model).
4621+
Use `quantile(phi, some_field) if (some_field:*) as min_value_without_empty_string` syntax for filtering out empty string values.
4622+
See [conditional stats docs](https://docs.victoriametrics.com/victorialogs/logsql/#stats-with-additional-filters) for more details.
4623+
46044624
It is possible to calculate the quantile across all the fields with common prefix via `quantile(phi, prefix*)` syntax.
46054625

46064626
See also:

0 commit comments

Comments
 (0)