数组中的java 2值与我的数据帧中的2列对应
使用Java中的Apache Spark,我有:
root
|-- datasetid: string (nullable = true)
|-- fields: struct (nullable = true)
...
| |-- latlon: array (nullable = true)
| | |-- element: double (containsNull = true)
这基于此JSON片段:
"fields":{
"latlon":[
35.9543748,
-78.9944911
],
我试图使用以下方法将数据提取到列中:
df = df.withColumn("lat", df.col("fields.latlon[0]"));
df = df.withColumn("lon", df.col("fields.latlon[1]"));
(我希望您能欣赏语法的简洁)。然而,我必须承认,这并没有真正起作用:
No such struct field latlon[1] in
我尝试了其他一些事情,但运气不好
# 1 楼答案
使用代码
使用sql