如何在 Spark SQL 中使用连字符转义列名 [英] How to escape column names with hyphen in Spark SQL

查看:31
本文介绍了如何在 Spark SQL 中使用连字符转义列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Spark 中导入了一个 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")

但是,由于 column-1 列名称中的连字符,这给了我一个错误.我如何解决这是 Spark 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")

应该可以解决问题,至少在 Spark v1.3.x 中是这样.

should do the trick, at least in Spark v1.3.x.

这篇关于如何在 Spark SQL 中使用连字符转义列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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