elasticsearch/docs/reference/esql/functions/mv-functions.asciidoc
Iván Cea Fontenla fc2760cfd4
ESQL: mv_median_absolute_deviation function (#112055)
- Added mv_median_absolute_deviation function
- Added possibility of having a fixed param in Multivalue "ascending" functions
- Add surrogate to MedianAbsoluteDeviation

### Calculations used to avoid overflows
First, a quick recap of how the MAD is calculated:
1. Sort values, and get the median
2. Calculate the difference between each value with the median (`abs(median - value)`)
3. Sort the differences, and get their median

Calculating a MAD may overflow when calculating the differences (Step 2), given the type is a signed number, as the difference is a positive value, with potentially the same value as `POSITIVE_MAX - NEGATIVE_MIN`.
To solve this, some types are up-casted as follow:
- Int: Stored as longs, simple approach
- Long: Stored as longs, but switched to unsigned long representation when calculating the differences
- Unsigned long: No effect; the resulting range is the same
- Doubles: Nothing. If the values overflow to +/-infinity, they're left that way, as we'll just use those outliers to sort

Closes https://github.com/elastic/elasticsearch/issues/111590
2024-09-09 10:04:25 +02:00

44 lines
1.1 KiB
Text

[[esql-mv-functions]]
==== {esql} multivalue functions
++++
<titleabbrev>Multivalue functions</titleabbrev>
++++
{esql} supports these multivalue functions:
// tag::mv_list[]
* <<esql-mv_append>>
* <<esql-mv_avg>>
* <<esql-mv_concat>>
* <<esql-mv_count>>
* <<esql-mv_dedupe>>
* <<esql-mv_first>>
* <<esql-mv_last>>
* <<esql-mv_max>>
* <<esql-mv_median>>
* <<esql-mv_median_absolute_deviation>>
* <<esql-mv_min>>
* <<esql-mv_pseries_weighted_sum>>
* <<esql-mv_sort>>
* <<esql-mv_slice>>
* <<esql-mv_sum>>
* <<esql-mv_zip>>
// end::mv_list[]
include::layout/mv_append.asciidoc[]
include::layout/mv_avg.asciidoc[]
include::layout/mv_concat.asciidoc[]
include::layout/mv_count.asciidoc[]
include::layout/mv_dedupe.asciidoc[]
include::layout/mv_first.asciidoc[]
include::layout/mv_last.asciidoc[]
include::layout/mv_max.asciidoc[]
include::layout/mv_median.asciidoc[]
include::layout/mv_median_absolute_deviation.asciidoc[]
include::layout/mv_min.asciidoc[]
include::layout/mv_pseries_weighted_sum.asciidoc[]
include::layout/mv_slice.asciidoc[]
include::layout/mv_sort.asciidoc[]
include::layout/mv_sum.asciidoc[]
include::layout/mv_zip.asciidoc[]