【发布时间】:2017-02-23 07:41:59
【问题描述】:
我创建了一个包含 3 列的数据框:zip、lat、lng
我想选择 zip = 00650 的 lat 和 lng 值
所以,我尝试使用:
sqlContext.sql("select lat,lng from census where zip=00650").show()
但它返回 ArrayOutOfBound 异常,因为它没有任何值。 如果我删除 where 子句,它运行良好。
有人可以解释我做错了什么吗?
更新:
数据框架构:
root
|-- zip: string (nullable = true)
|-- lat: string (nullable = true)
|-- lng: string (nullable = true)
前 10 行是:
+-----+---------+-----------+
| zip| lat| lng|
+-----+---------+-----------+
|00601|18.180555| -66.749961|
|00602|18.361945| -67.175597|
|00603|18.455183| -67.119887|
|00606|18.158345| -66.932911|
|00610|18.295366| -67.125135|
|00612|18.402253| -66.711397|
|00616|18.420412| -66.671979|
|00617|18.445147| -66.559696|
|00622|17.991245| -67.153993|
|00623|18.083361| -67.153897|
|00624|18.064919| -66.716683|
|00627|18.412600| -66.863926|
|00631|18.190607| -66.832041|
|00637|18.076713| -66.947389|
|00638|18.295913| -66.515588|
|00641|18.263085| -66.712985|
|00646|18.433150| -66.285875|
|00647|17.963613| -66.947127|
|00650|18.349416| -66.578079|
【问题讨论】:
-
你能用
dataFrame.printSchema()显示你的数据框的架构吗 -
root |-- zip: string (nullable = true) |-- lat: string (nullable = true) |-- lng: string (nullable = true)
标签: sql scala apache-spark