我有如下所示的示例数据,我想提取仅具有名称及其完整键而不是 dep_names 及其完整键的元素。
我正在尝试如下所示,
WITH dataset AS
(
SELECT '{"name": "Bob Smith",
"org": "engineering",
"projects": [{"dep_namename":"project1", "completed":none},{"name":"project2", "completed":false},{"name":"project3", "completed":true}]}'
AS myblob
)
SELECT get_json_object(myblob, '$.projects[*]?(exists(@.name))' AS project_name
FROM dataset
我期待如下的输出
[false,true]
请在下面找到
Spark SQL
SELECT
FILTER(
FROM_JSON(
input,
'projects array<struct<dep_namename:string, completed:string, name:string>>'
).projects,
mp -> mp.name IS NOT NULL
).completed as output
FROM VALUES
('{"name": "Bob Smith","org": "engineering","projects": [{"dep_namename":"project1", "completed":"none"},{"name":"project2", "completed":false},{"name":"project3", "completed":true}]}')
AS (input)
+-------------+
|output |
+-------------+
|[false, true]|
+-------------+