explode_json_array_int
功能描述
explode_json_array_string 表函数,接受一个 JSON 数组,其实现逻辑是将 JSON 数组转换为数组类型然后再调用 explode 函数处理。需配合 LATERAL VIEW 使用。
语法
EXPLODE_JSON_ARRAY_INT(<json>)
参数说明
<json> JSON 类型,其内容应该是数组
返回结果
- 返回由
<json> 所有元素组成的单列多行数据,列类型为 Nullable<JSON>。
- 如果
<json> 为 NULL 或者为空数组(元素个数为 0),返回 0 行数据。
- 如果 JSON 数组的元素不是 INT 类型,会尝试将其转换为 INT,无法转换为 INT 类型的被转换为 NULL。
使用示例
CREATE TABLE test_explode_json(id int, j json);
INSERT INTO test_explode_json VALUES
(1, parse_json('{"a": 1, "b": "hello", "c": [1,2,3]}')),
(2, parse_json('[1, 2, "three", 4.5, null]')),
(3, parse_json('null')),
(4, null),
(5, parse_json('[]')),
(6, parse_json('{}')),
(7, parse_json('[{"x":1},{"y":2}]')),
(8, parse_json('{"nested": {"a": 1}, "arr": [1,2]}'));
SELECT id, col FROM test_explode_json LATERAL VIEW explode_json_array_int(j) lv AS col ORDER BY id;
