Skip to content

Commit

Permalink
docs(sql): add missing array funcs (#2135)
Browse files Browse the repository at this point in the history
Signed-off-by: Jiyong Huang <[email protected]>
  • Loading branch information
ngjaying authored Jul 28, 2023
1 parent 3e63c4c commit 1f02bdc
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 14 deletions.
56 changes: 54 additions & 2 deletions docs/en_US/sqls/functions/array_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ array_last_position(array, val)
Return a 0-based index of the last occurrence of val if it is found within the array. If val does not exist within the
array, it returns -1.

## ARRAY_CONTAIN_ANY
## ARRAY_CONTAINS_ANY

```text
array_contain_any(array1, array2)
array_contains_any(array1, array2)
```

Returns true if array1 and array2 have any elements in common.
Expand Down Expand Up @@ -124,6 +124,58 @@ sequence(start, stop, step)

Returns an array of integers from start to stop, incrementing by step.

## ARRAY_CARDINALITY

```text
array_cardinality(array)
```

Return the number of elements in the array. The null value will be ignored.

## ARRAY_FLATTEN

```text
array_flatten(array)
```

Return a flattened array, i.e., expand the array elements in the array.

For example, if the input is [[1, 4], [2, 3]], then the output is [1, 4, 2, 3].

## ARRAY_DISTINCT

```text
array_distinct(array)
```

Return a distinct array, i.e., remove the duplicate elements in the array.

## ARRAY_MAP

```text
array_map(function_name, array)
```

Return a new array by applying a function to each element of the array.

## ARRAY_JOIN

```text
array_join(array, delimiter, null_replacement)
```

Return a string that concatenates all elements of the array and uses the delimiter and an optional string to replace null values.

For example, if the input is [1, 2, 3], delimiter is set to comma, then the output is "1,2,3".

## ARRAY_SHUFFLE

```text
array_shuffle(array)
```

Return a shuffled array, i.e., randomly shuffle the elements in the array.

## ARRAY_CONCAT

```text
Expand Down
10 changes: 5 additions & 5 deletions docs/en_US/sqls/functions/object_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Object functions are used to manipulate objects/maps.
## KEYS

```text
keys(map\<string, interface{}>)
keys(obj)
```

Return an array containing the keys of the map.
Expand All @@ -25,7 +25,7 @@ result:
## VALUES

```text
values(map\<string, interface{}>)
values(obj)
```

example:
Expand All @@ -45,7 +45,7 @@ Return an array containing the values of the map.
## OBJECT

```text
object(array\<string>, array\<interface{}>)
object(keys, values)
```

Construct an object from an array of keys and an array of values. Keys must be an array of strings. Values must be an
Expand All @@ -66,7 +66,7 @@ result:
## ZIP

```text
zip(array\<array\<string, interface{}>>)
zip(entries)
```

Construct an object from an array of entries. Each entry must itself be an array of size 2: the first element is the
Expand All @@ -87,7 +87,7 @@ result:
## ITEMS

```text
items(map\<string, interface{}>)
items(obj)
```

Return an array containing the entries of object. Each entry is a 2-element array; the first is the key, the second is
Expand Down
56 changes: 54 additions & 2 deletions docs/zh_CN/sqls/functions/array_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ array_last_position(array, val)

返回第二个参数在列表参数中最后一次出现的下标位置,索引下标从 0 开始,若该元素不存在,则返回 -1。

## ARRAY_CONTAIN_ANY
## ARRAY_CONTAINS_ANY

```text
array_contain_any(array1, array2)
array_contains_any(array1, array2)
```

返回第一个参数中是否存在第二个参数中的任意一个元素,存在则返回 true,否则返回 false。
Expand Down Expand Up @@ -123,6 +123,58 @@ sequence(start, stop[, step])
返回一个从第一个开始参数到第二个结束参数的整数列表,每个元素按照给定的步长递增或递减。若未提供步长,则默认为
1(如果第一个开始参数小于第二个结束参数),或 -1(如果第一个开始参数大于第二个结束参数),且步长不允许为 0。

## ARRAY_CARDINALITY

```text
array_cardinality(array)
```

返回数组中的元素数。数组中的 null 值不计算在内。

## ARRAY_FLATTEN

```text
array_flatten(array)
```

返回一个扁平化的数组,即将数组中的数组元素展开。

例如,传入参数为 [[1, 4], [2, 3]],则返回 [1, 4, 2, 3]

## ARRAY_DISTINCT

```text
array_distinct(array)
```

返回一个去重的数组,即将数组中的重复元素去除。

## ARRAY_MAP

```text
array_map(function_name, array)
```

返回一个新的数组,其中包含对给定数组中的每个元素应用给定函数的结果。

## ARRAY_JOIN

```text
array_join(array, delimiter, null_replacement)
```

返回一个字符串,其中包含给定数组中的所有元素,元素之间用给定的分隔符分隔。如果数组中的元素为 null,则用给定的 null_replacement 替换。

例如,传入参数为 [1, 2, 3],delimiter 设置为逗号,则返回 “1,2,3”。

## ARRAY_SHUFFLE

```text
array_shuffle(array)
```

返回一个随机排序的数组。

## ARRAY_CONCAT

```text
Expand Down
10 changes: 5 additions & 5 deletions docs/zh_CN/sqls/functions/object_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## KEYS

```text
keys(map\<string, any>)
keys(obj)
```

返回的给定的 map 参数中的所有 key 值, 举例如下:
Expand All @@ -23,7 +23,7 @@ keys({"a":1, "b":2})
## VALUES

```text
values(map\<string, any>)
values(obj)
```

返回给定的 map 参数中的所有 value 值,举例如下:
Expand All @@ -41,7 +41,7 @@ values({"a":1, "b":2})
## OBJECT

```text
object(arr1, arr2)
object(keys, values)
```

接受两个 list 参数来构造 map 对象,第一个 list 作为 map 对象的 key,第二个 list 作为 map 对象的 value。两个 list 参数长度必须相等, 举例如下:
Expand All @@ -59,7 +59,7 @@ object(["a","b"],[1,2])
## ZIP

```text
zip([key, value], ......)
zip(entries)
```

接受一组 list 对象来构造 map 对象,每个 list 元素的长度必须为 2,每个 list 元素内的第一个元素将作为 key,第二个元素将作为
Expand All @@ -78,7 +78,7 @@ zip([["a",1],["b":2]])
## ITEMS

```text
items(map\<string, any>)
items(obj)
```

根据给定的 map 参数构造一个 list 对象,每个元素都为一个长度为 2 的 list 对象,其中第一个元素为 key,第二个元素为 value,举例如下:
Expand Down

0 comments on commit 1f02bdc

Please sign in to comment.