Browse Source

docs: add example for object funtion (#2062)

* add doc

Signed-off-by: yisaer <disxiaofei@163.com>

* add doc

Signed-off-by: yisaer <disxiaofei@163.com>

* fix lint

Signed-off-by: yisaer <disxiaofei@163.com>

---------

Signed-off-by: yisaer <disxiaofei@163.com>
Song Gao 1 year atrás
parent
commit
ead575f767

+ 78 - 6
docs/en_US/sqls/functions/object_functions.md

@@ -5,15 +5,39 @@ Object functions are used to manipulate objects/maps.
 ## KEYS
 
 ```text
-keys(map<string, interface{}>) -> array<string>
+keys(map\<string, interface{}>)
 ```
 
 Return an array containing the keys of the map.
 
+example:
+
+```sql
+keys({"a":1, "b":2})
+```
+
+result:
+
+```sql
+["a","b"]
+```
+
 ## VALUES
 
 ```text
-values(map<string, interface{}>) -> array<interface{}>
+values(map\<string, interface{}>)
+```
+
+example:
+
+```sql
+values({"a":1, "b":2})
+```
+
+result:
+
+```sql
+[1,2]
 ```
 
 Return an array containing the values of the map.
@@ -21,36 +45,84 @@ Return an array containing the values of the map.
 ## OBJECT
 
 ```text
-object(array<string>, array<interface{}>) -> map<string, interface{}>
+object(array\<string>, array\<interface{}>)
 ```
 
 Construct an object from an array of keys and an array of values. Keys must be an array of strings. Values must be an
 arbitrary array of the same length as keys.
 
+example:
+
+```sql
+object(["a","b"],[1,2])
+```
+
+result:
+
+```sql
+{"a":1, "b":2}
+```
+
 ## ZIP
 
 ```text
-zip(array<array<string, interface{}>>) -> map<string, interface{}>
+zip(array\<array\<string, interface{}>>)
 ```
 
 Construct an object from an array of entries. Each entry must itself be an array of size 2: the first element is the
 key (and must be a string), and the second element is the value.
 
+example:
+
+```sql
+zip([["a",1],["b":2]])
+```
+
+result:
+
+```sql
+{"a":1, "b":2}
+```
+
 ## ITEMS
 
 ```text
-items(map<string, interface{}>) -> array<array<string, interface{}>>
+items(map\<string, interface{}>)
 ```
 
 Return an array containing the entries of object. Each entry is a 2-element array; the first is the key, the second is
 the value.
 
+example:
+
+```sql
+items({"a":1, "b":2})
+```
+
+result:
+
+```sql
+[["a",1],["b":2]]
+```
+
 ## OBJECT_CONSTRUCT
 
 ```text
-object_construct(key1, col1, key2, col2, ...) -> map<string, interface{}>
+object_construct(key1, col1, key2, col2, ...)
 ```
 
 Return a struct type object/map constructed by the arguments. The arguments are a series of key value pairs, thus the
 arguments count must be an odd number. The key must be a string, and the value can be of any type. If the value is null,
 the key/value pair will not present in the final object.
+
+example:
+
+```sql
+object_construct("a", 1, "b", 2)
+```
+
+result:
+
+```sql
+{"a":1, "b":2}
+```

+ 70 - 10
docs/zh_CN/sqls/functions/object_functions.md

@@ -5,18 +5,38 @@
 ## KEYS
 
 ```text
-keys(map<string, any>)
+keys(map\<string, any>)
 ```
 
-返回的给定的 map 参数中的所有 key 值。
+返回的给定的 map 参数中的所有 key 值, 举例如下:
+
+```sql
+keys({"a":1, "b":2})
+```
+
+得到如下结果:
+
+```sql
+["a","b"]
+```
 
 ## VALUES
 
 ```text
-values(map<string, any>)
+values(map\<string, any>)
+```
+
+返回给定的 map 参数中的所有 value 值,举例如下:
+
+```sql
+values({"a":1, "b":2})
 ```
 
-返回给定的 map 参数中的所有 value 值。
+得到如下结果:
+
+```sql
+[1,2]
+```
 
 ## OBJECT
 
@@ -24,24 +44,54 @@ values(map<string, any>)
 object(arr1, arr2)
 ```
 
-接受两个 list 参数来构造 map 对象,第一个 list 作为 map 对象的 key,第二个 list 作为 map 对象的 value。两个 list 参数长度必须相等。
+接受两个 list 参数来构造 map 对象,第一个 list 作为 map 对象的 key,第二个 list 作为 map 对象的 value。两个 list 参数长度必须相等, 举例如下:
+
+```sql
+object(["a","b"],[1,2])
+```
+
+得到如下结果:
+
+```sql
+{"a":1, "b":2}
+```
 
 ## ZIP
 
 ```text
-zip([arr1, arr2], ......)
+zip([key, value], ......)
 ```
 
 接受一组 list 对象来构造 map 对象,每个 list 元素的长度必须为 2,每个 list 元素内的第一个元素将作为 key,第二个元素将作为
-value。
+value, 举例如下:
+
+```sql
+zip([["a",1],["b":2]])
+```
+
+得到如下结果:
+
+```sql
+{"a":1, "b":2}
+```
 
 ## ITEMS
 
 ```text
-items(map<string, any>)
+items(map\<string, any>)
+```
+
+根据给定的 map 参数构造一个 list 对象,每个元素都为一个长度为 2 的 list 对象,其中第一个元素为 key,第二个元素为 value,举例如下:
+
+```sql
+items({"a":1, "b":2})
 ```
 
-根据给定的 map 参数构造一个 list 对象,每个元素都为一个长度为 2 的 list 对象,其中第一个元素为 key,第二个元素为 value。
+得到如下结果:
+
+```sql
+[["a",1],["b":2]]
+```
 
 ## OBJECT_CONSTRUCT
 
@@ -49,4 +99,14 @@ items(map<string, any>)
 object_construct(key1, col, ...)
 ```
 
-返回由参数构建的 object/map 。参数为一系列的键值对,因此必须为偶数个。键必须为 string 类型,值可以为任意类型。如果值为空,则该键值对不会出现在最终的对象中。
+返回由参数构建的 object/map 。参数为一系列的键值对,因此必须为偶数个。键必须为 string 类型,值可以为任意类型。如果值为空,则该键值对不会出现在最终的对象中,举例如下:
+
+```sql
+object_construct("a", 1, "b", 2)
+```
+
+得到如下结果:
+
+```sql
+{"a":1, "b":2}
+```