Cannot resolve column (numeric column name) in Spark Dataframe

一曲冷凌霜 提交于 2019-12-03 07:30:56

You can use backticks to escape the dot, which is reserved for accessing columns for struct type:

data.select("`2.0`").show
+---+
|2.0|
+---+
| , |
+---+
Tawkir

The problem is you can not add dot character in the column name while selecting from dataframe. You can have a look at this question, kind of similar.

val data = spark.createDataFrame(Seq(
  ("Hello", ", ", "World!")
)).toDF("1.0", "2.0", "3.0")
data.select(sanitize("2.0")).show

def sanitize(input: String): String = s"`$input`"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!