This is an automated email from the ASF dual-hosted git repository. kassiez pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push: new 3bb70095209 [improve](json_funcs)improve json_object functions usage (#2008) 3bb70095209 is described below commit 3bb7009520971fa198e44156995a836e244d57a0 Author: amory <wangqian...@selectdb.com> AuthorDate: Tue May 27 16:24:36 2025 +0800 [improve](json_funcs)improve json_object functions usage (#2008) ## Versions - [ ] dev - [x] 3.0 - [x] 2.1 - [ ] 2.0 ## Languages - [x] Chinese - [x] English ## Docs Checklist - [ ] Checked by AI - [ ] Test Cases Built --- .../scalar-functions/json-functions/json-object.md | 51 +++++++++++++++++++++ .../scalar-functions/json-functions/json-object.md | 50 ++++++++++++++++++++ .../scalar-functions/json-functions/json-object.md | 53 +++++++++++++++++++++- .../scalar-functions/json-functions/json-object.md | 50 ++++++++++++++++++++ .../scalar-functions/json-functions/json-object.md | 51 +++++++++++++++++++++ .../scalar-functions/json-functions/json-object.md | 52 +++++++++++++++++++++ 6 files changed, 305 insertions(+), 2 deletions(-) diff --git a/docs/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md b/docs/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md index 4437b915882..d1ef7dc3fd0 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md +++ b/docs/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md @@ -40,6 +40,12 @@ JSON_OBJECT (<key>, <value>[,<key>, <value>, ...]) | `<key>` | The Key value in the Key-Value of the generated json object. | | `<value>` | The Value value in the Key-Value of the generated json object. | | +## Usage Notes + +- By convention, the argument list consists of alternating keys and values. +- Key arguments are coerced to text. +- Value arguments are converted as per can convert to json, now we support array/struct/map/json as value. + ## Return Values Return a json object. Special cases are as follows: * If no parameters are passed, return an empty json object. @@ -96,3 +102,48 @@ select json_object(null,null); ERROR 1105 (HY000): errCode = 2, detailMessage = json_object key can't be NULL: json_object(NULL) ``` +```sql +-- support array as object value +SELECT json_object('id', 1, 'level', array('"aaa"','"bbb"')); +``` +```text ++------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(array('"aaa"', '"bbb"') as JSON), '6267') | ++------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":["\"aaa\"","\"bbb\""]} | ++------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support map as object value +SELECT json_object('id', 1, 'level', map('a', 'b', 'c', 'd')); +``` +```text ++------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(map('a', 'b', 'c', 'd') as JSON), '6267') | ++------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"a":"b","c":"d"}} | ++------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support struct as object value +SELECT json_object('id', 1, 'level', named_struct('name', 'a', 'age', 1)); +``` +```text ++------------------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(named_struct('name', 'a', 'age', 1) as JSON), '6267') | ++------------------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"name":"a","age":1}} | ++------------------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support json as object value +SELECT json_object('id', 1, 'level', cast('{\"a\":\"b\"}' as JSON)); +``` +```text ++------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast('{"a":"b"}' as JSON), '6267') | ++------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"a":"b"}} | ++------------------------------------------------------------------------------------------+ +``` + diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md index 82d9dfa36e3..4476fd6110b 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md @@ -41,6 +41,12 @@ JSON_OBJECT (<key>, <value>[,<key>, <value>, ...]) | `<key>` | 指定生成的 json object 的 Key-Value 中的 Key 值 | | `<value>` | 指定生成的 json object 的 Key-Value 中的 Value 值 | +## 注意事项 + +- 按照惯例,参数列表由交替的键和值组成。 +- Key 按照JSON 定义强制转换为文本。 +- Value 参数按照可以转换为 json 的方式进行转换,现在我们支持 array/struct/map/json 作为值 + ## 返回值 返回一个 json object。特殊情况如下: @@ -97,3 +103,47 @@ select json_object(null,null); ```text ERROR 1105 (HY000): errCode = 2, detailMessage = json_object key can't be NULL: json_object(NULL) ``` +```sql +-- support array as object value +SELECT json_object('id', 1, 'level', array('"aaa"','"bbb"')); +``` +```text ++------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(array('"aaa"', '"bbb"') as JSON), '6267') | ++------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":["\"aaa\"","\"bbb\""]} | ++------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support map as object value +SELECT json_object('id', 1, 'level', map('a', 'b', 'c', 'd')); +``` +```text ++------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(map('a', 'b', 'c', 'd') as JSON), '6267') | ++------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"a":"b","c":"d"}} | ++------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support struct as object value +SELECT json_object('id', 1, 'level', named_struct('name', 'a', 'age', 1)); +``` +```text ++------------------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(named_struct('name', 'a', 'age', 1) as JSON), '6267') | ++------------------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"name":"a","age":1}} | ++------------------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support json as object value +SELECT json_object('id', 1, 'level', cast('{\"a\":\"b\"}' as JSON)); +``` +```text ++------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast('{"a":"b"}' as JSON), '6267') | ++------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"a":"b"}} | ++------------------------------------------------------------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md index bfe2ba6aa4e..4476fd6110b 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md @@ -24,7 +24,6 @@ specific language governing permissions and limitations under the License. --> - ## 描述 生成一个或者多个包含指定 Key-Value 对的 json object, 当 Key 值为 NULL 或者传入参数为奇数个时,返回异常错误。 @@ -42,6 +41,12 @@ JSON_OBJECT (<key>, <value>[,<key>, <value>, ...]) | `<key>` | 指定生成的 json object 的 Key-Value 中的 Key 值 | | `<value>` | 指定生成的 json object 的 Key-Value 中的 Value 值 | +## 注意事项 + +- 按照惯例,参数列表由交替的键和值组成。 +- Key 按照JSON 定义强制转换为文本。 +- Value 参数按照可以转换为 json 的方式进行转换,现在我们支持 array/struct/map/json 作为值 + ## 返回值 返回一个 json object。特殊情况如下: @@ -97,4 +102,48 @@ select json_object(null,null); ``` ```text ERROR 1105 (HY000): errCode = 2, detailMessage = json_object key can't be NULL: json_object(NULL) -``` \ No newline at end of file +``` +```sql +-- support array as object value +SELECT json_object('id', 1, 'level', array('"aaa"','"bbb"')); +``` +```text ++------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(array('"aaa"', '"bbb"') as JSON), '6267') | ++------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":["\"aaa\"","\"bbb\""]} | ++------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support map as object value +SELECT json_object('id', 1, 'level', map('a', 'b', 'c', 'd')); +``` +```text ++------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(map('a', 'b', 'c', 'd') as JSON), '6267') | ++------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"a":"b","c":"d"}} | ++------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support struct as object value +SELECT json_object('id', 1, 'level', named_struct('name', 'a', 'age', 1)); +``` +```text ++------------------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(named_struct('name', 'a', 'age', 1) as JSON), '6267') | ++------------------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"name":"a","age":1}} | ++------------------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support json as object value +SELECT json_object('id', 1, 'level', cast('{\"a\":\"b\"}' as JSON)); +``` +```text ++------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast('{"a":"b"}' as JSON), '6267') | ++------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"a":"b"}} | ++------------------------------------------------------------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md index 82d9dfa36e3..4476fd6110b 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md @@ -41,6 +41,12 @@ JSON_OBJECT (<key>, <value>[,<key>, <value>, ...]) | `<key>` | 指定生成的 json object 的 Key-Value 中的 Key 值 | | `<value>` | 指定生成的 json object 的 Key-Value 中的 Value 值 | +## 注意事项 + +- 按照惯例,参数列表由交替的键和值组成。 +- Key 按照JSON 定义强制转换为文本。 +- Value 参数按照可以转换为 json 的方式进行转换,现在我们支持 array/struct/map/json 作为值 + ## 返回值 返回一个 json object。特殊情况如下: @@ -97,3 +103,47 @@ select json_object(null,null); ```text ERROR 1105 (HY000): errCode = 2, detailMessage = json_object key can't be NULL: json_object(NULL) ``` +```sql +-- support array as object value +SELECT json_object('id', 1, 'level', array('"aaa"','"bbb"')); +``` +```text ++------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(array('"aaa"', '"bbb"') as JSON), '6267') | ++------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":["\"aaa\"","\"bbb\""]} | ++------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support map as object value +SELECT json_object('id', 1, 'level', map('a', 'b', 'c', 'd')); +``` +```text ++------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(map('a', 'b', 'c', 'd') as JSON), '6267') | ++------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"a":"b","c":"d"}} | ++------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support struct as object value +SELECT json_object('id', 1, 'level', named_struct('name', 'a', 'age', 1)); +``` +```text ++------------------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(named_struct('name', 'a', 'age', 1) as JSON), '6267') | ++------------------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"name":"a","age":1}} | ++------------------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support json as object value +SELECT json_object('id', 1, 'level', cast('{\"a\":\"b\"}' as JSON)); +``` +```text ++------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast('{"a":"b"}' as JSON), '6267') | ++------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"a":"b"}} | ++------------------------------------------------------------------------------------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md index 4437b915882..d1ef7dc3fd0 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md @@ -40,6 +40,12 @@ JSON_OBJECT (<key>, <value>[,<key>, <value>, ...]) | `<key>` | The Key value in the Key-Value of the generated json object. | | `<value>` | The Value value in the Key-Value of the generated json object. | | +## Usage Notes + +- By convention, the argument list consists of alternating keys and values. +- Key arguments are coerced to text. +- Value arguments are converted as per can convert to json, now we support array/struct/map/json as value. + ## Return Values Return a json object. Special cases are as follows: * If no parameters are passed, return an empty json object. @@ -96,3 +102,48 @@ select json_object(null,null); ERROR 1105 (HY000): errCode = 2, detailMessage = json_object key can't be NULL: json_object(NULL) ``` +```sql +-- support array as object value +SELECT json_object('id', 1, 'level', array('"aaa"','"bbb"')); +``` +```text ++------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(array('"aaa"', '"bbb"') as JSON), '6267') | ++------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":["\"aaa\"","\"bbb\""]} | ++------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support map as object value +SELECT json_object('id', 1, 'level', map('a', 'b', 'c', 'd')); +``` +```text ++------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(map('a', 'b', 'c', 'd') as JSON), '6267') | ++------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"a":"b","c":"d"}} | ++------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support struct as object value +SELECT json_object('id', 1, 'level', named_struct('name', 'a', 'age', 1)); +``` +```text ++------------------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(named_struct('name', 'a', 'age', 1) as JSON), '6267') | ++------------------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"name":"a","age":1}} | ++------------------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support json as object value +SELECT json_object('id', 1, 'level', cast('{\"a\":\"b\"}' as JSON)); +``` +```text ++------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast('{"a":"b"}' as JSON), '6267') | ++------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"a":"b"}} | ++------------------------------------------------------------------------------------------+ +``` + diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md index 23084e66722..d1ef7dc3fd0 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/json-functions/json-object.md @@ -40,6 +40,12 @@ JSON_OBJECT (<key>, <value>[,<key>, <value>, ...]) | `<key>` | The Key value in the Key-Value of the generated json object. | | `<value>` | The Value value in the Key-Value of the generated json object. | | +## Usage Notes + +- By convention, the argument list consists of alternating keys and values. +- Key arguments are coerced to text. +- Value arguments are converted as per can convert to json, now we support array/struct/map/json as value. + ## Return Values Return a json object. Special cases are as follows: * If no parameters are passed, return an empty json object. @@ -95,3 +101,49 @@ select json_object(null,null); ```text ERROR 1105 (HY000): errCode = 2, detailMessage = json_object key can't be NULL: json_object(NULL) ``` + +```sql +-- support array as object value +SELECT json_object('id', 1, 'level', array('"aaa"','"bbb"')); +``` +```text ++------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(array('"aaa"', '"bbb"') as JSON), '6267') | ++------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":["\"aaa\"","\"bbb\""]} | ++------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support map as object value +SELECT json_object('id', 1, 'level', map('a', 'b', 'c', 'd')); +``` +```text ++------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(map('a', 'b', 'c', 'd') as JSON), '6267') | ++------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"a":"b","c":"d"}} | ++------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support struct as object value +SELECT json_object('id', 1, 'level', named_struct('name', 'a', 'age', 1)); +``` +```text ++------------------------------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast(named_struct('name', 'a', 'age', 1) as JSON), '6267') | ++------------------------------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"name":"a","age":1}} | ++------------------------------------------------------------------------------------------------------------------+ +``` +```sql +-- support json as object value +SELECT json_object('id', 1, 'level', cast('{\"a\":\"b\"}' as JSON)); +``` +```text ++------------------------------------------------------------------------------------------+ +| json_object('id', cast(1 as VARCHAR(65533)), 'level', cast('{"a":"b"}' as JSON), '6267') | ++------------------------------------------------------------------------------------------+ +| {"id":1,"level":{"a":"b"}} | ++------------------------------------------------------------------------------------------+ +``` + --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org