如何在Spark SQL中表达名称包含空格的列 [英] How to express a column which name contains spaces in Spark SQL
本文介绍了如何在Spark SQL中表达名称包含空格的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们尝试用方括号 [column name]
包裹列名,单个 &双引号和反引号,它们都不起作用.
We have tried wrapping the column name with brackets [column name]
, single & double quotes, and backticks, none of them works.
Spark SQL 是否支持名称包含空格的列?
Does Spark SQL support columns whose name contains spaces?
谢谢!
推荐答案
反引号似乎很好用:
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
与DataFrame
API 相同:
scala> df.select($"foo bar").show
foo bar
a
所以看起来它是受支持的,尽管我怀疑它是否值得推荐.
So it looks like it is supported, although I doubt it is recommended.
这篇关于如何在Spark SQL中表达名称包含空格的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文