How to express a column which name contains spaces in Spark SQL?

Backticks seem to work just fine:

scala> val df = sc.parallelize(Seq(("a", 1))).toDF("foo bar", "x")
df: org.apache.spark.sql.DataFrame = [foo bar: string, x: int]
scala> df.registerTempTable("df")

scala> sqlContext.sql("""SELECT `foo bar` FROM df""").show
foo bar
a  

Same as DataFrame API:

scala> df.select($"foo bar").show
foo bar
a   

So it looks like it is supported, although I doubt it is recommended.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)