Skip to content

Commit 7289b84

Browse files
kagamiorifacebook-github-bot
authored andcommitted
Update documentation about JSON cast function (#4436)
Summary: Pull Request resolved: #4436 Update documentation to include examples of casting JSON to ROW type. Reviewed By: pedroerp Differential Revision: D44423674 fbshipit-source-id: ca6fd870e52aefe968429b8ae5dcd57a865bdcf5
1 parent 90b3f4d commit 7289b84

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

velox/docs/functions/presto/json.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ BIGINT, REAL, DOUBLE or VARCHAR is supported. Casting to ARRAY and MAP is
6666
supported when the element type of the array is one of the supported types, or
6767
when the key type of the map is BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT,
6868
REAL, DOUBLE, or VARCHAR and value type of the map is one of the supported types.
69+
When casting from JSON to ROW, both JSON array and JSON object are supported.
6970
Behaviors of the casts are shown with the examples below:
7071

7172
::
@@ -80,6 +81,8 @@ Behaviors of the casts are shown with the examples below:
8081
SELECT CAST(JSON '[1,null,456]' AS ARRAY(INTEGER)); -- [1, NULL, 456]
8182
SELECT CAST(JSON '[[1,23],[456]]' AS ARRAY(ARRAY(INTEGER))); -- [[1, 23], [456]]
8283
SELECT CAST(JSON '{"k1":1,"k2":23,"k3":456}' AS MAP(VARCHAR, INTEGER)); -- {k1=1, k2=23, k3=456}
84+
SELECT CAST(JSON '{"v1":123,"v2":"abc","v3":true}' AS ROW(v1 BIGINT, v2 VARCHAR, v3 BOOLEAN)); -- {v1=123, v2=abc, v3=true}
85+
SELECT CAST(JSON '[123,"abc",true]' AS ROW(v1 BIGINT, v2 VARCHAR, v3 BOOLEAN)); -- {v1=123, v2=abc, v3=true}
8386

8487
Notice that casting a JSON text to VARCHAR does not turn the JSON text into
8588
a plain string as is. Instead, it returns the VARCHAR string represented by
@@ -153,9 +156,8 @@ JSON Functions
153156
SELECT json_size('{"x": [1, 2, 3]}', '$.x'); -- 3
154157
SELECT json_size('{"x": {"a": 1, "b": 2}}', '$.x.a'); -- 0
155158

156-
============
157159
JSON Vectors
158-
============
160+
------------
159161

160162
There are a number of Presto JSON functions expecting JSON-typed inputs or
161163
returning JSON-typed outputs. Hence, developers who use the Velox library may

0 commit comments

Comments
 (0)