Browse Source

Docs for remaining mv functions (ESQL-1114)

This adds docs for all of the remaining `mv_*` functions that have been
implemented at this point.
Nik Everett 2 years ago
parent
commit
555781a8a0

+ 6 - 0
docs/reference/esql/esql-functions.asciidoc

@@ -15,7 +15,10 @@ these functions:
 * <<esql-is_nan>>
 * <<esql-is_null>>
 * <<esql-length>>
+* <<esql-mv_avg>>
+* <<esql-mv_max>>
 * <<esql-mv_min>>
+* <<esql-mv_sum>>
 * <<esql-pow>>
 * <<esql-round>>
 * <<esql-split>>
@@ -162,7 +165,10 @@ FROM employees
 | EVAL fn_length = LENGTH(first_name)
 ----
 
+include::functions/mv_avg.asciidoc[]
+include::functions/mv_max.asciidoc[]
 include::functions/mv_min.asciidoc[]
+include::functions/mv_sum.asciidoc[]
 
 [[esql-pow]]
 === `POW`

+ 12 - 0
docs/reference/esql/functions/mv_avg.asciidoc

@@ -0,0 +1,12 @@
+[[esql-mv_avg]]
+=== `MV_AVG`
+Converts a multivalued field into a single valued field containing the average
+of all of the values. For example:
+
+[source,esql]
+----
+include::{esql-specs}/math.csv-spec[tag=mv_avg]
+include::{esql-specs}/math.csv-spec[tag=mv_avg-result]
+----
+
+NOTE: The output type is always a `double` and the input type can be any number.

+ 18 - 0
docs/reference/esql/functions/mv_max.asciidoc

@@ -0,0 +1,18 @@
+[[esql-mv_max]]
+=== `MV_MAX`
+Converts a multivalued field into a single valued field containing the maximum value. For example:
+
+[source,esql]
+----
+include::{esql-specs}/math.csv-spec[tag=mv_max]
+include::{esql-specs}/math.csv-spec[tag=mv_max-result]
+----
+
+It can be used by any field type, including `keyword` fields. In that case picks the
+last string, comparing their utf-8 representation byte by byte:
+
+[source,esql]
+----
+include::{esql-specs}/string.csv-spec[tag=mv_max]
+include::{esql-specs}/string.csv-spec[tag=mv_max-result]
+----

+ 12 - 0
docs/reference/esql/functions/mv_sum.asciidoc

@@ -0,0 +1,12 @@
+[[esql-mv_sum]]
+=== `MV_SUM`
+Converts a multivalued field into a single valued field containing the sum
+of all of the values. For example:
+
+[source,esql]
+----
+include::{esql-specs}/math.csv-spec[tag=mv_sum]
+include::{esql-specs}/math.csv-spec[tag=mv_sum-result]
+----
+
+NOTE: The input type can be any number and the output type is the same as the input type.

+ 40 - 0
x-pack/plugin/esql/qa/testFixtures/src/main/resources/math.csv-spec

@@ -200,6 +200,20 @@ emp_no:integer | salary_change.int:integer | salary_change:double
 10015          | [12, 14]                  | 13.325
 ;
 
+mvAvgSimple
+// tag::mv_avg[]
+ROW a=[3, 5, 1, 6]
+| EVAL avg_a = MV_AVG(a)
+// end::mv_avg[]
+;
+
+// tag::mv_avg-result[]
+   a:integer | avg_a:double
+[3, 5, 1, 6] | 3.75
+// end::mv_avg-result[]
+;
+
+
 mvMax
 from employees | where emp_no > 10008 | eval salary_change = mv_max(salary_change.int) | sort emp_no | project emp_no, salary_change.int, salary_change | limit 7;
 
@@ -213,6 +227,19 @@ emp_no:integer | salary_change.int:integer | salary_change:integer
 10015          | [12, 14]                  | 14
 ;
 
+mvMaxSimple
+// tag::mv_max[]
+ROW a=[3, 5, 1]
+| EVAL max_a = MV_MAX(a)
+// end::mv_max[]
+;
+
+// tag::mv_max-result[]
+a:integer | max_a:integer
+[3, 5, 1] | 5
+// end::mv_max-result[]
+;
+
 mvMin
 from employees | where emp_no > 10008 | eval salary_change = mv_min(salary_change.int) | sort emp_no | project emp_no, salary_change.int, salary_change | limit 7;
 
@@ -251,3 +278,16 @@ emp_no:integer | salary_change.int:integer | salary_change:integer
 10014          | [-1, 9]                   | 8
 10015          | [12, 14]                  | 26
 ;
+
+mvSumSimple
+// tag::mv_sum[]
+ROW a=[3, 5, 6]
+| EVAL sum_a = MV_SUM(a)
+// end::mv_sum[]
+;
+
+// tag::mv_sum-result[]
+a:integer | sum_a:integer
+[3, 5, 6] | 14
+// end::mv_sum-result[]
+;

+ 13 - 0
x-pack/plugin/esql/qa/testFixtures/src/main/resources/string.csv-spec

@@ -210,6 +210,19 @@ foo;bar;baz;qux;quux;corge | [foo,bar,baz,qux,quux,corge]
 // end::split-result[]
 ;
 
+mvMax
+// tag::mv_max[]
+ROW a=["foo", "zoo", "bar"]
+| EVAL max_a = MV_MAX(a)
+// end::mv_max[]
+;
+
+// tag::mv_max-result[]
+            a:keyword | max_a:keyword
+["foo", "zoo", "bar"] | "zoo"
+// end::mv_max-result[]
+;
+
 mvMin
 // tag::mv_min[]
 ROW a=["foo", "bar"]