From 99b2109c64dbc796bfcea0beeeadb28e4b4298bc Mon Sep 17 00:00:00 2001 From: aceforeverd Date: Wed, 21 Feb 2024 06:20:49 +0000 Subject: [PATCH] docs(udf): upgrade udf list --- docs/en/reference/sql/udfs_8h.md | 622 +++++++++++++++++-------------- docs/zh/openmldb_sql/udfs_8h.md | 622 +++++++++++++++++-------------- 2 files changed, 676 insertions(+), 568 deletions(-) diff --git a/docs/en/reference/sql/udfs_8h.md b/docs/en/reference/sql/udfs_8h.md index 9cfab05977f..9fc3d807470 100644 --- a/docs/en/reference/sql/udfs_8h.md +++ b/docs/en/reference/sql/udfs_8h.md @@ -86,6 +86,8 @@ title: udfs/udfs.h | **[log2](/openmldb_sql/Files/udfs_8h.md#function-log2)**()|
Return the base-2 logarithm of expr. | | **[lower](/openmldb_sql/Files/udfs_8h.md#function-lower)**()| | | **[make_tuple](/openmldb_sql/Files/udfs_8h.md#function-make-tuple)**()| | +| **[map](/openmldb_sql/Files/udfs_8h.md#function-map)**()|
map(key1, value1, key2, value2, ...) - Creates a map with the given key/value pairs. | +| **[map_keys](/openmldb_sql/Files/udfs_8h.md#function-map-keys)**()|
map_keys(map) - Returns an unordered array containing the keys of the map. | | **[max](/openmldb_sql/Files/udfs_8h.md#function-max)**()|
Compute maximum of values. | | **[max_cate](/openmldb_sql/Files/udfs_8h.md#function-max-cate)**()|
Compute maximum of values grouped by category key and output string. Each group is represented as 'K:V' and separated by comma in outputs and are sorted by key in ascend order. | | **[max_cate_where](/openmldb_sql/Files/udfs_8h.md#function-max-cate-where)**()|
Compute maximum of values matching specified condition grouped by category key and output string. Each group is represented as 'K:V' and separated by comma in outputs and are sorted by key in ascend order. | @@ -501,13 +503,13 @@ Compute average of values. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -541,13 +543,13 @@ Compute average of values grouped by category key and output string. Each group Example: -| value | catagory | +| value | catagory | | -------- | -------- | -| 0 | x | -| 1 | y | -| 2 | x | -| 3 | y | -| 4 | x | +| 0 | x | +| 1 | y | +| 2 | x | +| 3 | y | +| 4 | x | ```sql @@ -586,13 +588,13 @@ Compute average of values matching specified condition grouped by category key a Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | ```sql @@ -634,13 +636,13 @@ Compute average of values match specified condition. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -946,13 +948,13 @@ Compute number of values. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -987,13 +989,13 @@ Compute count of values grouped by category key and output string. Each group is Example: -| value | catagory | +| value | catagory | | -------- | -------- | -| 0 | x | -| 1 | y | -| 2 | x | -| 3 | y | -| 4 | x | +| 0 | x | +| 1 | y | +| 2 | x | +| 3 | y | +| 4 | x | ```sql @@ -1032,13 +1034,13 @@ Compute count of values matching specified condition grouped by category key and Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | ```sql @@ -1080,13 +1082,13 @@ Compute number of values match specified condition. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -1374,13 +1376,13 @@ Compute number of distinct values. Example: -| value | +| value | | -------- | -| 0 | -| 0 | -| 2 | -| 2 | -| 4 | +| 0 | +| 0 | +| 2 | +| 2 | +| 4 | ```sql @@ -1450,14 +1452,14 @@ It requires that all values are non-negative. Negative values will be ignored. Example: -| value | +| value | | -------- | -| 1 | -| 8 | -| 5 | -| 2 | -| 10 | -| 4 | +| 1 | +| 8 | +| 5 | +| 2 | +| 10 | +| 4 | ```sql @@ -1568,13 +1570,13 @@ It requires that values are ordered so that it can only be used with WINDOW (PAR Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -1652,11 +1654,11 @@ window w as (partition by gp order by ts rows between 3 preceding and current ro ``` -| id | gp | ts | agg | +| id | gp | ts | agg | | -------- | -------- | -------- | -------- | -| 1 | 100 | 98 | 98 | -| 2 | 100 | 99 | 99 | -| 3 | 100 | 100 | 100 | +| 1 | 100 | 98 | 98 | +| 2 | 100 | 99 | 99 | +| 3 | 100 | 100 | 100 | @@ -2259,13 +2261,13 @@ The offset in window is `nth_value()`, not `[lag()](/openmldb_sql/Files/udfs_8h. Example: -| c1 | c2 | +| c1 | c2 | | -------- | -------- | -| 0 | 1 | -| 1 | 1 | -| 2 | 2 | -| 3 | 2 | -| 4 | 2 | +| 0 | 1 | +| 1 | 1 | +| 2 | 2 | +| 3 | 2 | +| 4 | 2 | ```sql @@ -2630,6 +2632,58 @@ make_tuple() * [...] +### function map + +```cpp +map() +``` + +**Description**: + +map(key1, value1, key2, value2, ...) - Creates a map with the given key/value pairs. + +**Since**: +0.9.0 + + +Example: + +```sql + +select map(1, '1', 2, '2'); +-- {1: "1", 2: "2"} +``` + + +**Supported Types**: + +* [...] + +### function map_keys + +```cpp +map_keys() +``` + +**Description**: + +map_keys(map) - Returns an unordered array containing the keys of the map. + +**Since**: +0.9.0 + + +Example: + +```sql + +select map_keys(map(1, '2', 3, '4')); +-- [1, 3] +``` + + +**Supported Types**: + ### function max ```cpp @@ -2653,13 +2707,13 @@ Compute maximum of values. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -2696,13 +2750,13 @@ Compute maximum of values grouped by category key and output string. Each group Example: -| value | catagory | +| value | catagory | | -------- | -------- | -| 0 | x | -| 1 | y | -| 2 | x | -| 3 | y | -| 4 | x | +| 0 | x | +| 1 | y | +| 2 | x | +| 3 | y | +| 4 | x | ```sql @@ -2741,13 +2795,13 @@ Compute maximum of values matching specified condition grouped by category key a Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | ```sql @@ -2789,13 +2843,13 @@ Compute maximum of values match specified condition. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -2861,12 +2915,12 @@ Compute the median of values. Example: -| value | +| value | | -------- | -| 1 | -| 2 | -| 3 | -| 4 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -2903,13 +2957,13 @@ Compute minimum of values. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -2946,13 +3000,13 @@ Compute minimum of values grouped by category key and output string. Each group Example: -| value | catagory | +| value | catagory | | -------- | -------- | -| 0 | x | -| 1 | y | -| 2 | x | -| 3 | y | -| 4 | x | +| 0 | x | +| 1 | y | +| 2 | x | +| 3 | y | +| 4 | x | ```sql @@ -2991,14 +3045,14 @@ Compute minimum of values matching specified condition grouped by category key a Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 1 | true | y | -| 4 | true | x | -| 3 | true | y | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 1 | true | y | +| 4 | true | x | +| 3 | true | y | ```sql @@ -3040,13 +3094,13 @@ Compute minimum of values match specified condition. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -3176,12 +3230,12 @@ select col1, cond, gp, nth_value_where(col1, 2, cond) over (partition by gp orde ``` -| col1 | cond | gp | agg | +| col1 | cond | gp | agg | | -------- | -------- | -------- | -------- | -| 1 | true | 100 | NULL | -| 2 | false | 100 | NULL | -| 3 | NULL | 100 | NULL | -| 4 | true | 100 | 4 | +| 1 | true | 100 | NULL | +| 2 | false | 100 | NULL | +| 3 | NULL | 100 | NULL | +| 4 | true | 100 | 4 | @@ -3810,12 +3864,12 @@ Alias function: `std`, `stddev_samp` Example: -| value | +| value | | -------- | -| 1 | -| 2 | -| 3 | -| 4 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -3852,12 +3906,12 @@ Compute population standard deviation of values, i.e., `sqrt( sum((x_i - avg)^2) Example: -| value | +| value | | -------- | -| 1 | -| 2 | -| 3 | -| 4 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -4013,13 +4067,13 @@ Compute sum of values. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -4053,13 +4107,13 @@ Compute sum of values grouped by category key and output string. Each group is r Example: -| value | catagory | +| value | catagory | | -------- | -------- | -| 0 | x | -| 1 | y | -| 2 | x | -| 3 | y | -| 4 | x | +| 0 | x | +| 1 | y | +| 2 | x | +| 3 | y | +| 4 | x | ```sql @@ -4098,13 +4152,13 @@ Compute sum of values matching specified condition grouped by category key and o Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | ```sql @@ -4146,13 +4200,13 @@ Compute sum of values match specified condition. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -4262,13 +4316,13 @@ Compute top k of values and output string separated by comma. The outputs are so Example: -| value | +| value | | -------- | -| 1 | -| 2 | -| 3 | -| 4 | -| 4 | +| 1 | +| 2 | +| 3 | +| 4 | +| 4 | ```sql @@ -4319,11 +4373,11 @@ SELECT key, top1_ratio(key) over () as ratio FROM t1; ``` -| key | ratio | +| key | ratio | | -------- | -------- | -| 1 | 1.0 | -| 2 | 0.5 | -| NULL | 0.5 | +| 1 | 1.0 | +| 2 | 0.5 | +| NULL | 0.5 | @@ -4360,15 +4414,15 @@ Compute average of values matching specified condition grouped by category key. Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | -| 5 | true | z | -| 6 | false | z | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | +| 5 | true | z | +| 6 | false | z | ```sql @@ -4420,15 +4474,15 @@ Compute count of values matching specified condition grouped by category key. Ou Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | true | y | -| 2 | false | x | -| 3 | true | y | -| 4 | false | x | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 1 | true | y | +| 2 | false | x | +| 3 | true | y | +| 4 | false | x | +| 5 | true | z | +| 6 | true | z | ```sql @@ -4480,15 +4534,15 @@ Compute maximum of values matching specified condition grouped by category key. Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | -| 5 | true | z | -| 6 | false | z | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | +| 5 | true | z | +| 6 | false | z | ```sql @@ -4540,15 +4594,15 @@ Compute minimum of values matching specified condition grouped by category key. Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | true | y | -| 2 | false | x | -| 3 | true | y | -| 4 | false | x | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 1 | true | y | +| 2 | false | x | +| 3 | true | y | +| 4 | false | x | +| 5 | true | z | +| 6 | true | z | ```sql @@ -4602,15 +4656,15 @@ For each group, ratio value is `value` expr count matches condtion divide total Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 2 | true | x | -| 4 | true | x | -| 1 | true | y | -| 3 | false | y | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 2 | true | x | +| 4 | true | x | +| 1 | true | y | +| 3 | false | y | +| 5 | true | z | +| 6 | true | z | ```sql @@ -4661,15 +4715,15 @@ Compute sum of values matching specified condition grouped by category key. Outp Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | true | y | -| 2 | false | x | -| 3 | true | y | -| 4 | false | x | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 1 | true | y | +| 2 | false | x | +| 3 | true | y | +| 4 | false | x | +| 5 | true | z | +| 6 | true | z | ```sql @@ -4721,15 +4775,15 @@ Compute average of values matching specified condition grouped by category key. Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | false | y | -| 4 | true | x | -| 5 | true | z | -| 6 | false | z | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | false | y | +| 4 | true | x | +| 5 | true | z | +| 6 | false | z | ```sql @@ -4781,15 +4835,15 @@ Compute count of values matching specified condition grouped by category key. Ou Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | true | y | -| 2 | true | x | -| 3 | false | y | -| 4 | true | x | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 1 | true | y | +| 2 | true | x | +| 3 | false | y | +| 4 | true | x | +| 5 | true | z | +| 6 | true | z | ```sql @@ -4841,15 +4895,15 @@ Compute maximum of values matching specified condition grouped by category key. Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | -| 5 | true | z | -| 6 | false | z | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | +| 5 | true | z | +| 6 | false | z | ```sql @@ -4901,15 +4955,15 @@ Compute minimum of values matching specified condition grouped by category key. Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | true | y | -| 2 | true | x | -| 3 | true | y | -| 4 | false | x | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 1 | true | y | +| 2 | true | x | +| 3 | true | y | +| 4 | false | x | +| 5 | true | z | +| 6 | true | z | ```sql @@ -4963,15 +5017,15 @@ For each group, ratio value is `value` expr count matches condtion divide total Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 2 | true | x | -| 4 | true | x | -| 1 | true | y | -| 3 | false | y | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 2 | true | x | +| 4 | true | x | +| 1 | true | y | +| 3 | false | y | +| 5 | true | z | +| 6 | true | z | ```sql @@ -5022,15 +5076,15 @@ Compute sum of values matching specified condition grouped by category key. Outp Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | true | y | -| 2 | false | x | -| 3 | false | y | -| 4 | true | x | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 1 | true | y | +| 2 | false | x | +| 3 | false | y | +| 4 | true | x | +| 5 | true | z | +| 6 | true | z | ```sql @@ -5245,11 +5299,11 @@ Compute population variance of values, i.e., `sum((x_i - avg)^2) / n` Example: -| value | +| value | | -------- | -| 0 | -| 3 | -| 6 | +| 0 | +| 3 | +| 6 | ```sql @@ -5286,11 +5340,11 @@ Compute population variance of values, i.e., `sum((x_i - avg)^2) / (n-1)` Example: -| value | +| value | | -------- | -| 0 | -| 3 | -| 6 | +| 0 | +| 3 | +| 6 | ```sql diff --git a/docs/zh/openmldb_sql/udfs_8h.md b/docs/zh/openmldb_sql/udfs_8h.md index 9cfab05977f..9fc3d807470 100644 --- a/docs/zh/openmldb_sql/udfs_8h.md +++ b/docs/zh/openmldb_sql/udfs_8h.md @@ -86,6 +86,8 @@ title: udfs/udfs.h | **[log2](/openmldb_sql/Files/udfs_8h.md#function-log2)**()|
Return the base-2 logarithm of expr. | | **[lower](/openmldb_sql/Files/udfs_8h.md#function-lower)**()| | | **[make_tuple](/openmldb_sql/Files/udfs_8h.md#function-make-tuple)**()| | +| **[map](/openmldb_sql/Files/udfs_8h.md#function-map)**()|
map(key1, value1, key2, value2, ...) - Creates a map with the given key/value pairs. | +| **[map_keys](/openmldb_sql/Files/udfs_8h.md#function-map-keys)**()|
map_keys(map) - Returns an unordered array containing the keys of the map. | | **[max](/openmldb_sql/Files/udfs_8h.md#function-max)**()|
Compute maximum of values. | | **[max_cate](/openmldb_sql/Files/udfs_8h.md#function-max-cate)**()|
Compute maximum of values grouped by category key and output string. Each group is represented as 'K:V' and separated by comma in outputs and are sorted by key in ascend order. | | **[max_cate_where](/openmldb_sql/Files/udfs_8h.md#function-max-cate-where)**()|
Compute maximum of values matching specified condition grouped by category key and output string. Each group is represented as 'K:V' and separated by comma in outputs and are sorted by key in ascend order. | @@ -501,13 +503,13 @@ Compute average of values. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -541,13 +543,13 @@ Compute average of values grouped by category key and output string. Each group Example: -| value | catagory | +| value | catagory | | -------- | -------- | -| 0 | x | -| 1 | y | -| 2 | x | -| 3 | y | -| 4 | x | +| 0 | x | +| 1 | y | +| 2 | x | +| 3 | y | +| 4 | x | ```sql @@ -586,13 +588,13 @@ Compute average of values matching specified condition grouped by category key a Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | ```sql @@ -634,13 +636,13 @@ Compute average of values match specified condition. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -946,13 +948,13 @@ Compute number of values. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -987,13 +989,13 @@ Compute count of values grouped by category key and output string. Each group is Example: -| value | catagory | +| value | catagory | | -------- | -------- | -| 0 | x | -| 1 | y | -| 2 | x | -| 3 | y | -| 4 | x | +| 0 | x | +| 1 | y | +| 2 | x | +| 3 | y | +| 4 | x | ```sql @@ -1032,13 +1034,13 @@ Compute count of values matching specified condition grouped by category key and Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | ```sql @@ -1080,13 +1082,13 @@ Compute number of values match specified condition. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -1374,13 +1376,13 @@ Compute number of distinct values. Example: -| value | +| value | | -------- | -| 0 | -| 0 | -| 2 | -| 2 | -| 4 | +| 0 | +| 0 | +| 2 | +| 2 | +| 4 | ```sql @@ -1450,14 +1452,14 @@ It requires that all values are non-negative. Negative values will be ignored. Example: -| value | +| value | | -------- | -| 1 | -| 8 | -| 5 | -| 2 | -| 10 | -| 4 | +| 1 | +| 8 | +| 5 | +| 2 | +| 10 | +| 4 | ```sql @@ -1568,13 +1570,13 @@ It requires that values are ordered so that it can only be used with WINDOW (PAR Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -1652,11 +1654,11 @@ window w as (partition by gp order by ts rows between 3 preceding and current ro ``` -| id | gp | ts | agg | +| id | gp | ts | agg | | -------- | -------- | -------- | -------- | -| 1 | 100 | 98 | 98 | -| 2 | 100 | 99 | 99 | -| 3 | 100 | 100 | 100 | +| 1 | 100 | 98 | 98 | +| 2 | 100 | 99 | 99 | +| 3 | 100 | 100 | 100 | @@ -2259,13 +2261,13 @@ The offset in window is `nth_value()`, not `[lag()](/openmldb_sql/Files/udfs_8h. Example: -| c1 | c2 | +| c1 | c2 | | -------- | -------- | -| 0 | 1 | -| 1 | 1 | -| 2 | 2 | -| 3 | 2 | -| 4 | 2 | +| 0 | 1 | +| 1 | 1 | +| 2 | 2 | +| 3 | 2 | +| 4 | 2 | ```sql @@ -2630,6 +2632,58 @@ make_tuple() * [...] +### function map + +```cpp +map() +``` + +**Description**: + +map(key1, value1, key2, value2, ...) - Creates a map with the given key/value pairs. + +**Since**: +0.9.0 + + +Example: + +```sql + +select map(1, '1', 2, '2'); +-- {1: "1", 2: "2"} +``` + + +**Supported Types**: + +* [...] + +### function map_keys + +```cpp +map_keys() +``` + +**Description**: + +map_keys(map) - Returns an unordered array containing the keys of the map. + +**Since**: +0.9.0 + + +Example: + +```sql + +select map_keys(map(1, '2', 3, '4')); +-- [1, 3] +``` + + +**Supported Types**: + ### function max ```cpp @@ -2653,13 +2707,13 @@ Compute maximum of values. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -2696,13 +2750,13 @@ Compute maximum of values grouped by category key and output string. Each group Example: -| value | catagory | +| value | catagory | | -------- | -------- | -| 0 | x | -| 1 | y | -| 2 | x | -| 3 | y | -| 4 | x | +| 0 | x | +| 1 | y | +| 2 | x | +| 3 | y | +| 4 | x | ```sql @@ -2741,13 +2795,13 @@ Compute maximum of values matching specified condition grouped by category key a Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | ```sql @@ -2789,13 +2843,13 @@ Compute maximum of values match specified condition. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -2861,12 +2915,12 @@ Compute the median of values. Example: -| value | +| value | | -------- | -| 1 | -| 2 | -| 3 | -| 4 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -2903,13 +2957,13 @@ Compute minimum of values. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -2946,13 +3000,13 @@ Compute minimum of values grouped by category key and output string. Each group Example: -| value | catagory | +| value | catagory | | -------- | -------- | -| 0 | x | -| 1 | y | -| 2 | x | -| 3 | y | -| 4 | x | +| 0 | x | +| 1 | y | +| 2 | x | +| 3 | y | +| 4 | x | ```sql @@ -2991,14 +3045,14 @@ Compute minimum of values matching specified condition grouped by category key a Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 1 | true | y | -| 4 | true | x | -| 3 | true | y | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 1 | true | y | +| 4 | true | x | +| 3 | true | y | ```sql @@ -3040,13 +3094,13 @@ Compute minimum of values match specified condition. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -3176,12 +3230,12 @@ select col1, cond, gp, nth_value_where(col1, 2, cond) over (partition by gp orde ``` -| col1 | cond | gp | agg | +| col1 | cond | gp | agg | | -------- | -------- | -------- | -------- | -| 1 | true | 100 | NULL | -| 2 | false | 100 | NULL | -| 3 | NULL | 100 | NULL | -| 4 | true | 100 | 4 | +| 1 | true | 100 | NULL | +| 2 | false | 100 | NULL | +| 3 | NULL | 100 | NULL | +| 4 | true | 100 | 4 | @@ -3810,12 +3864,12 @@ Alias function: `std`, `stddev_samp` Example: -| value | +| value | | -------- | -| 1 | -| 2 | -| 3 | -| 4 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -3852,12 +3906,12 @@ Compute population standard deviation of values, i.e., `sqrt( sum((x_i - avg)^2) Example: -| value | +| value | | -------- | -| 1 | -| 2 | -| 3 | -| 4 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -4013,13 +4067,13 @@ Compute sum of values. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -4053,13 +4107,13 @@ Compute sum of values grouped by category key and output string. Each group is r Example: -| value | catagory | +| value | catagory | | -------- | -------- | -| 0 | x | -| 1 | y | -| 2 | x | -| 3 | y | -| 4 | x | +| 0 | x | +| 1 | y | +| 2 | x | +| 3 | y | +| 4 | x | ```sql @@ -4098,13 +4152,13 @@ Compute sum of values matching specified condition grouped by category key and o Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | ```sql @@ -4146,13 +4200,13 @@ Compute sum of values match specified condition. Example: -| value | +| value | | -------- | -| 0 | -| 1 | -| 2 | -| 3 | -| 4 | +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ```sql @@ -4262,13 +4316,13 @@ Compute top k of values and output string separated by comma. The outputs are so Example: -| value | +| value | | -------- | -| 1 | -| 2 | -| 3 | -| 4 | -| 4 | +| 1 | +| 2 | +| 3 | +| 4 | +| 4 | ```sql @@ -4319,11 +4373,11 @@ SELECT key, top1_ratio(key) over () as ratio FROM t1; ``` -| key | ratio | +| key | ratio | | -------- | -------- | -| 1 | 1.0 | -| 2 | 0.5 | -| NULL | 0.5 | +| 1 | 1.0 | +| 2 | 0.5 | +| NULL | 0.5 | @@ -4360,15 +4414,15 @@ Compute average of values matching specified condition grouped by category key. Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | -| 5 | true | z | -| 6 | false | z | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | +| 5 | true | z | +| 6 | false | z | ```sql @@ -4420,15 +4474,15 @@ Compute count of values matching specified condition grouped by category key. Ou Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | true | y | -| 2 | false | x | -| 3 | true | y | -| 4 | false | x | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 1 | true | y | +| 2 | false | x | +| 3 | true | y | +| 4 | false | x | +| 5 | true | z | +| 6 | true | z | ```sql @@ -4480,15 +4534,15 @@ Compute maximum of values matching specified condition grouped by category key. Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | -| 5 | true | z | -| 6 | false | z | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | +| 5 | true | z | +| 6 | false | z | ```sql @@ -4540,15 +4594,15 @@ Compute minimum of values matching specified condition grouped by category key. Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | true | y | -| 2 | false | x | -| 3 | true | y | -| 4 | false | x | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 1 | true | y | +| 2 | false | x | +| 3 | true | y | +| 4 | false | x | +| 5 | true | z | +| 6 | true | z | ```sql @@ -4602,15 +4656,15 @@ For each group, ratio value is `value` expr count matches condtion divide total Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 2 | true | x | -| 4 | true | x | -| 1 | true | y | -| 3 | false | y | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 2 | true | x | +| 4 | true | x | +| 1 | true | y | +| 3 | false | y | +| 5 | true | z | +| 6 | true | z | ```sql @@ -4661,15 +4715,15 @@ Compute sum of values matching specified condition grouped by category key. Outp Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | true | y | -| 2 | false | x | -| 3 | true | y | -| 4 | false | x | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 1 | true | y | +| 2 | false | x | +| 3 | true | y | +| 4 | false | x | +| 5 | true | z | +| 6 | true | z | ```sql @@ -4721,15 +4775,15 @@ Compute average of values matching specified condition grouped by category key. Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | false | y | -| 4 | true | x | -| 5 | true | z | -| 6 | false | z | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | false | y | +| 4 | true | x | +| 5 | true | z | +| 6 | false | z | ```sql @@ -4781,15 +4835,15 @@ Compute count of values matching specified condition grouped by category key. Ou Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | true | y | -| 2 | true | x | -| 3 | false | y | -| 4 | true | x | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 1 | true | y | +| 2 | true | x | +| 3 | false | y | +| 4 | true | x | +| 5 | true | z | +| 6 | true | z | ```sql @@ -4841,15 +4895,15 @@ Compute maximum of values matching specified condition grouped by category key. Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | false | y | -| 2 | false | x | -| 3 | true | y | -| 4 | true | x | -| 5 | true | z | -| 6 | false | z | +| 0 | true | x | +| 1 | false | y | +| 2 | false | x | +| 3 | true | y | +| 4 | true | x | +| 5 | true | z | +| 6 | false | z | ```sql @@ -4901,15 +4955,15 @@ Compute minimum of values matching specified condition grouped by category key. Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | true | y | -| 2 | true | x | -| 3 | true | y | -| 4 | false | x | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 1 | true | y | +| 2 | true | x | +| 3 | true | y | +| 4 | false | x | +| 5 | true | z | +| 6 | true | z | ```sql @@ -4963,15 +5017,15 @@ For each group, ratio value is `value` expr count matches condtion divide total Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 2 | true | x | -| 4 | true | x | -| 1 | true | y | -| 3 | false | y | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 2 | true | x | +| 4 | true | x | +| 1 | true | y | +| 3 | false | y | +| 5 | true | z | +| 6 | true | z | ```sql @@ -5022,15 +5076,15 @@ Compute sum of values matching specified condition grouped by category key. Outp Example: -| value | condition | catagory | +| value | condition | catagory | | -------- | -------- | -------- | -| 0 | true | x | -| 1 | true | y | -| 2 | false | x | -| 3 | false | y | -| 4 | true | x | -| 5 | true | z | -| 6 | true | z | +| 0 | true | x | +| 1 | true | y | +| 2 | false | x | +| 3 | false | y | +| 4 | true | x | +| 5 | true | z | +| 6 | true | z | ```sql @@ -5245,11 +5299,11 @@ Compute population variance of values, i.e., `sum((x_i - avg)^2) / n` Example: -| value | +| value | | -------- | -| 0 | -| 3 | -| 6 | +| 0 | +| 3 | +| 6 | ```sql @@ -5286,11 +5340,11 @@ Compute population variance of values, i.e., `sum((x_i - avg)^2) / (n-1)` Example: -| value | +| value | | -------- | -| 0 | -| 3 | -| 6 | +| 0 | +| 3 | +| 6 | ```sql