diff --git a/docs/_sources/functions/presto/array.rst.txt b/docs/_sources/functions/presto/array.rst.txt index af908ea309b7..ce92411930a6 100644 --- a/docs/_sources/functions/presto/array.rst.txt +++ b/docs/_sources/functions/presto/array.rst.txt @@ -209,6 +209,47 @@ Array Functions SELECT filter(ARRAY [5, -6, NULL, 7], x -> x > 0); -- [5, 7] SELECT filter(ARRAY [5, NULL, 7, NULL], x -> x IS NOT NULL); -- [5, 7] +.. function:: find_first(array(T), function(T,boolean)) -> T + + Returns the first element of ``array`` that matches the predicate. + Returns ``NULL`` if no element matches the predicate. + Throws if the first matching element is NULL to avoid ambiguous results + for no-match and first-match-is-null cases. + +.. function:: find_first(array(T), index, function(T,boolean)) -> E + + Returns the first element of ``array`` that matches the predicate. + Returns ``NULL`` if no element matches the predicate. + Throws if the first matching element is NULL to avoid ambiguous results + for no-match and first-match-is-null cases. + If ``index`` > 0, the search for element starts at position ``index`` + until the end of the array. + If ``index`` < 0, the search for element starts at position ``abs(index)`` + counting from the end of the array, until the start of the array. :: + + SELECT find_first(ARRAY[3, 4, 5, 6], 2, x -> x > 0); -- 4 + SELECT find_first(ARRAY[3, 4, 5, 6], -2, x -> x > 0); -- 5 + SELECT find_first(ARRAY[3, 4, 5, 6], 2, x -> x < 4); -- NULL + SELECT find_first(ARRAY[3, 4, 5, 6], -2, x -> x > 5); -- NULL + +.. function:: find_first_index(array(T), function(T,boolean)) -> BIGINT + + Returns the 1-based index of the first element of ``array`` that matches the predicate. + Returns ``NULL`` if no such element exists. + +.. function:: find_first_index(array(T), index, function(T,boolean)) -> BIGINT + + Returns the 1-based index of the first element of ``array`` that matches the predicate. + Returns ``NULL`` if no such element exists. + If ``index`` > 0, the search for element starts at position ``index`` until the end of the array. + If ``index`` < 0, the search for element starts at position ``abs(index)`` counting from + the end of the array, until the start of the array. :: + + SELECT find_first(ARRAY[3, 4, 5, 6], 2, x -> x > 0); -- 2 + SELECT find_first(ARRAY[3, 4, 5, 6], -2, x -> x > 0); -- 3 + SELECT find_first(ARRAY[3, 4, 5, 6], 2, x -> x < 4); -- NULL + SELECT find_first(ARRAY[3, 4, 5, 6], -2, x -> x > 5); -- NULL + .. function:: flatten(array(array(T))) -> array(T) Flattens an ``array(array(T))`` to an ``array(T)`` by concatenating the contained arrays. diff --git a/docs/functions/presto/array.html b/docs/functions/presto/array.html index 23fe493a7470..339dc05f3dfd 100644 --- a/docs/functions/presto/array.html +++ b/docs/functions/presto/array.html @@ -327,6 +327,57 @@

Array Functions +
+find_first(array(T), function(T, boolean)) T
+

Returns the first element of array that matches the predicate. +Returns NULL if no element matches the predicate. +Throws if the first matching element is NULL to avoid ambiguous results +for no-match and first-match-is-null cases.

+
+ +
+
+find_first(array(T), index, function(T, boolean)) E
+

Returns the first element of array that matches the predicate. +Returns NULL if no element matches the predicate. +Throws if the first matching element is NULL to avoid ambiguous results +for no-match and first-match-is-null cases. +If index > 0, the search for element starts at position index +until the end of the array. +If index < 0, the search for element starts at position abs(index) +counting from the end of the array, until the start of the array.

+
SELECT find_first(ARRAY[3, 4, 5, 6], 2, x -> x > 0); -- 4
+SELECT find_first(ARRAY[3, 4, 5, 6], -2, x -> x > 0); -- 5
+SELECT find_first(ARRAY[3, 4, 5, 6], 2, x -> x < 4); -- NULL
+SELECT find_first(ARRAY[3, 4, 5, 6], -2, x -> x > 5); -- NULL
+
+
+
+ +
+
+find_first_index(array(T), function(T, boolean)) BIGINT
+

Returns the 1-based index of the first element of array that matches the predicate. +Returns NULL if no such element exists.

+
+ +
+
+find_first_index(array(T), index, function(T, boolean)) BIGINT
+

Returns the 1-based index of the first element of array that matches the predicate. +Returns NULL if no such element exists. +If index > 0, the search for element starts at position index until the end of the array. +If index < 0, the search for element starts at position abs(index) counting from +the end of the array, until the start of the array.

+
SELECT find_first(ARRAY[3, 4, 5, 6], 2, x -> x > 0); -- 2
+SELECT find_first(ARRAY[3, 4, 5, 6], -2, x -> x > 0); -- 3
+SELECT find_first(ARRAY[3, 4, 5, 6], 2, x -> x < 4); -- NULL
+SELECT find_first(ARRAY[3, 4, 5, 6], -2, x -> x > 5); -- NULL
+
+
+
+
flatten(array(array(T))) -> array(T)
diff --git a/docs/genindex.html b/docs/genindex.html index d98bae49adb7..c5de0e0da381 100644 --- a/docs/genindex.html +++ b/docs/genindex.html @@ -759,6 +759,10 @@

B

  • f_cdf()
  • filter(), [1] +
  • +
  • find_first(), [1] +
  • +
  • find_first_index(), [1]
  • first()
  • @@ -1646,6 +1650,20 @@

    F

    +
  • + find_first() + +
  • +
  • + find_first_index() + +
  • @@ -1683,6 +1701,8 @@

    F

  • built-in function, [1]
  • + + - -