This is an automated email from the ASF dual-hosted git repository. luzhijing 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 1db3336200b [doc](json-keys)add json_keys doc (#780) 1db3336200b is described below commit 1db3336200b87ce15a90ed2df4bc83daa70edbc3 Author: amory <wangqian...@selectdb.com> AuthorDate: Tue Jun 25 17:04:01 2024 +0800 [doc](json-keys)add json_keys doc (#780) --- .../sql-functions/json-functions/json-keys.md | 84 +++++++++++++++++++++ .../sql-functions/json-functions/json-keys.md | 85 ++++++++++++++++++++++ sidebars.json | 3 +- 3 files changed, 171 insertions(+), 1 deletion(-) diff --git a/docs/sql-manual/sql-functions/json-functions/json-keys.md b/docs/sql-manual/sql-functions/json-functions/json-keys.md new file mode 100644 index 00000000000..ab7ba758e8a --- /dev/null +++ b/docs/sql-manual/sql-functions/json-functions/json-keys.md @@ -0,0 +1,84 @@ +--- +{ + "title": "JSON_KEYS", + "language": "en" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## Json_keys +### Description +#### Syntax + +`ARRAY<STRING> json_keys(JSON, [VARCHAR path])` + + +Returns the keys from the top-level value of a JSON object as a JSON array, or, if a path argument is given, the top-level keys from the selected path. Returns NULL if any argument is NULL, the json_doc argument is not an object, or path, if given, does not locate an object. An error occurs if the json_doc argument is not a valid JSON document or the path argument is not a valid path expression + +> Note: +> +> The result array is empty if the selected object is empty. If the top-level value has nested subobjects, the return value does not include keys from those subobjects. +### Example + +```sql + +mysql> SELECT JSON_KEYS('{"a": 1, "b": {"c": 30}}'); ++-----------------------------------------------------+ +| json_keys(cast('{"a": 1, "b": {"c": 30}}' as JSON)) | ++-----------------------------------------------------+ +| ["a", "b"] | ++-----------------------------------------------------+ +1 row in set (0.35 sec) + +mysql> SELECT JSON_KEYS('{"a": 1, "b": {"c": 30}}', '$.b'); ++------------------------------------------------------------+ +| json_keys(cast('{"a": 1, "b": {"c": 30}}' as JSON), '$.b') | ++------------------------------------------------------------+ +| ["c"] | ++------------------------------------------------------------+ +1 row in set (0.07 sec) + +mysql> SELECT JSON_KEYS('{}'); ++-------------------------------+ +| json_keys(cast('{}' as JSON)) | ++-------------------------------+ +| [] | ++-------------------------------+ +1 row in set (0.07 sec) + +mysql> SELECT JSON_KEYS('[1,2]'); ++----------------------------------+ +| json_keys(cast('[1,2]' as JSON)) | ++----------------------------------+ +| NULL | ++----------------------------------+ +1 row in set (0.07 sec) + +mysql> SELECT JSON_KEYS('[]'); ++-------------------------------+ +| json_keys(cast('[]' as JSON)) | ++-------------------------------+ +| NULL | ++-------------------------------+ +1 row in set (0.07 sec) +``` +### Keywords +json,json_keys diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/json-functions/json-keys.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/json-functions/json-keys.md new file mode 100644 index 00000000000..2f9bc978c31 --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/json-functions/json-keys.md @@ -0,0 +1,85 @@ +--- +{ + "title": "JSON_KEYS", + "language": "zh-CN" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## Json_keys +### Description +#### Syntax + +`ARRAY<STRING> json_keys(JSON, [VARCHAR path])` + +JSON_KEYS() 函数用于从 JSON 对象的顶级值中返回键。这些键作为数组返回,或者如果给定了路径参数,则返回所选路径的顶级键。您需要将 JSON 文档作为函数的参数提供。您还可以(可选地)提供第二个参数,以指定 JSON 文档中“顶级”路径从何处开始。 +其中,json_doc 是 JSON 文档,path 是一个可选参数,用于确定 JSON 文档中“顶级”路径从何处开始。 + +> 注意: +> +> 如果所选对象为空,则结果数组为空。如果顶级值包含嵌套的子对象,返回值不包括这些子对象的键。 + +### Example + +```sql + +mysql> SELECT JSON_KEYS('{"a": 1, "b": {"c": 30}}'); ++-----------------------------------------------------+ +| json_keys(cast('{"a": 1, "b": {"c": 30}}' as JSON)) | ++-----------------------------------------------------+ +| ["a", "b"] | ++-----------------------------------------------------+ +1 row in set (0.35 sec) + +mysql> SELECT JSON_KEYS('{"a": 1, "b": {"c": 30}}', '$.b'); ++------------------------------------------------------------+ +| json_keys(cast('{"a": 1, "b": {"c": 30}}' as JSON), '$.b') | ++------------------------------------------------------------+ +| ["c"] | ++------------------------------------------------------------+ +1 row in set (0.07 sec) + +mysql> SELECT JSON_KEYS('{}'); ++-------------------------------+ +| json_keys(cast('{}' as JSON)) | ++-------------------------------+ +| [] | ++-------------------------------+ +1 row in set (0.07 sec) + +mysql> SELECT JSON_KEYS('[1,2]'); ++----------------------------------+ +| json_keys(cast('[1,2]' as JSON)) | ++----------------------------------+ +| NULL | ++----------------------------------+ +1 row in set (0.07 sec) + +mysql> SELECT JSON_KEYS('[]'); ++-------------------------------+ +| json_keys(cast('[]' as JSON)) | ++-------------------------------+ +| NULL | ++-------------------------------+ +1 row in set (0.07 sec) +``` +### Keywords +json,json_keys diff --git a/sidebars.json b/sidebars.json index eaad078ae6a..f2312d25c97 100644 --- a/sidebars.json +++ b/sidebars.json @@ -948,7 +948,8 @@ "sql-manual/sql-functions/json-functions/get-json-string", "sql-manual/sql-functions/json-functions/json-insert", "sql-manual/sql-functions/json-functions/json-replace", - "sql-manual/sql-functions/json-functions/json-set" + "sql-manual/sql-functions/json-functions/json-set", + "sql-manual/sql-functions/json-functions/json-keys" ] }, { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org