【发布时间】:2021-03-12 19:55:21
【问题描述】:
您好,我有一个嵌套的 JSON 有效负载,我试图在一个 select 语句中从数组中选择一个字段,字段的结构如下: 但我想知道我是否可以在一个选择语句中做到这一点
|-- payload: struct (nullable = true)
| |-- detail: struct (nullable = true)
| | |-- data: struct (nullable = true)
| | | |-- object: struct (nullable = true)
| | | | |-- items: struct (nullable = true)
| | | | | |-- data: array (nullable = true)
| | | | | | |-- element: struct (containsNull = true)
| | | | | | | |-- billing_thresholds: string (nullable = true)
| | | | | | | |-- created: long (nullable = true)
| | | | | | | |-- id: string (nullable = true)
| | | | | | | |-- object: string (nullable = true)
| | | | | | | |-- plan: struct (nullable = true)
| | | | | | | | |-- amount: long (nullable = true)
我知道我可以做这样的事情,这会给我我需要的领域:
display(sT_customer_subscription_events
.select($"payload.detail.data.object.items.data".getItems(0) as "item_data")
.select($"item_data.plan.amount"
)
但我试图在第一个 select 语句中这样做,这对我下面不起作用
display(sT_customer_subscription_events.select($"payload.detail.data.object.items.data".getItems(0)."plan.month" )
【问题讨论】:
标签: arrays json scala dataframe apache-spark-sql