【发布时间】:2018-08-21 06:02:50
【问题描述】:
我有一个具有以下架构的数据框:
|-- A: map (nullable = true)
| |-- key: string
| |-- value: array (valueContainsNull = true)
| | |-- element: struct (containsNull = true)
| | | |-- id: string (nullable = true)
| | | |-- type: string (nullable = true)
| | | |-- index: boolean (nullable = false)
|-- idkey: string (nullable = true)
由于map中的值是数组类型,所以我需要提取“外”键字段idkey中的id对应的字段索引。
例如,我有以下数据:
{"A":{
"innerkey_1":[{"id":"1","type":"0.01","index":true},
{"id":"6","type":"4.3","index":false}]},
"1"}
由于idkey为1,我们需要输出"id":1所在元素对应的index值,即index应该等于true。我真的不确定如何使用 UDF 或其他方式完成此操作。
预期输出为:
+---------+
| indexout|
+---------+
| true |
+---------+
【问题讨论】:
-
你能澄清一下
i.e. the index should be equal to 0吗?你也可以分享你的预期输出吗 -
那么 1 怎么可能是一个布尔值呢?并且类型 struct 似乎是 double 而不是字符串。 ??
-
我已修正错别字,谢谢指出。
-
index false 的 id 为 6 。他们不将 idkey 与 id 匹配。匹配索引应该为真。
-
这些
Since the idkey is 1, we need to to output the value of index corresponding to the element where "id":1, i.e. the index should be equal to false不是互相矛盾吗?
标签: scala apache-spark apache-spark-sql user-defined-functions