如何在Spark SQL中表示名称包含空格的列 [英] How to express a column which name contains spaces in Spark SQL

查看:519
本文介绍了如何在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?

谢谢!

推荐答案

反引号似乎可以正常工作:

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  

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆