SPARK SQL - 情况下,当再 [英] SPARK SQL - case when then

查看:336
本文介绍了SPARK SQL - 情况下,当再的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的火花SQL。是否有一个相当于CASE WHEN'条件',那么0 ELSE 1 END,在SPARK SQL?

I'm new to SPARK-SQL. Is there an equivalent to "CASE WHEN 'CONDITION' THEN 0 ELSE 1 END" in SPARK SQL ?

选择情况下,当1 = 1,则1否则从表0结束

谢谢
斯里达尔

Thanks Sridhar

推荐答案

星火1.2.0之前

支持的语法(这我只是想出去星火1.0.2)似乎是

The supported syntax (which I just tried out on Spark 1.0.2) seems to be

SELECT IF(1=1, 1, 0) FROM table

这最近的线程<一个href=\"http://apache-spark-user-list.1001560.n3.nabble.com/Supported-SQL-syntax-in-Spark-SQL-td9538.html\" rel=\"nofollow\">http://apache-spark-user-list.1001560.n3.nabble.com/Supported-SQL-syntax-in-Spark-SQL-td9538.html链接到SQL解析器源,其可能或可能不由取决于使用Scala您的舒适。在上线70开始(在撰写本文时)关键词的最起码的名单应该有所帮助。

This recent thread http://apache-spark-user-list.1001560.n3.nabble.com/Supported-SQL-syntax-in-Spark-SQL-td9538.html links to the SQL parser source, which may or may not help depending on your comfort with Scala. At the very least the list of keywords starting (at time of writing) on line 70 should help.

下面是直接链接到源方便:<一href=\"https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala\" rel=\"nofollow\">https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala.

Here's the direct link to the source for convenience: https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala.

更新星火1.2.0及以后

作为火花1.2.0的,较传统的语法被支撑,以响应火花-3813 :搜索CASE WHEN中的<一个href=\"https://github.com/apache/spark/blob/master/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala\"相对=nofollow>测试源。例如:

As of Spark 1.2.0, the more traditional syntax is supported, in response to SPARK-3813: search for "CASE WHEN" in the test source. For example:

SELECT CASE WHEN key = 1 THEN 1 ELSE 2 END FROM testData

为最近更新的地方,从SQL分析器

解析器源现在可以找到<一个href=\"https://github.com/apache/spark/blob/master/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4\"相对=nofollow>这里。

The parser source can now be found here.

这篇关于SPARK SQL - 情况下,当再的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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