如何逃避星火SQL连字符列名 [英] How to escape column names with hyphen in Spark SQL
本文介绍了如何逃避星火SQL连字符列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已导入在星火一个JSON文件,变了成一个表作为
I have imported a json file in Spark and convertd it into a table as
myDF.registerTempTable("myDF")
我再想运行该结果表的SQL查询
I then want to run SQL queries on this resulting table
val newTable = sqlContext.sql("select column-1 from myDF")
然而,这给了我一个错误,因为在列列1
的名字连字符的。我如何解决这个星火SQL?
However this gives me an error because of the hypen in the name of the column column-1
. How do I resolve this is Spark SQL?
推荐答案
反引号(`)似乎工作,所以
Backticks (`) appear to work, so
val newTable = sqlContext.sql("select `column-1` from myDF")
应该做的伎俩,至少在星火v1.3.x。
should do the trick, at least in Spark v1.3.x.
这篇关于如何逃避星火SQL连字符列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文