[英]sql/spark-sql: if statement syntax in a query
I am looking into some existing spark-sql codes, which trying two join to tables as below: 我正在研究一些现有的spark-sql代码,尝试将两个表连接到表中,如下所示:
items_t1_t2 as (
select *,
if(id_t1 is not Null, True, False) as in_t1,
if(id_t2 is not Null, True, False) as in_t2
from item_t2 full join item_t1
on id_t2 = id_t1)
I am wondering why there is three elements in the if parentheses? 我想知道为什么if括号中包含三个元素? What does the if statement mean here and how it works here?
if语句在这里意味着什么以及它在这里如何工作? Thanks a lot!
非常感谢!
The "IF" statement in Spark SQL (and in some other SQL systems) has three clauses: Spark SQL(和某些其他SQL系统)中的“ IF”语句具有三个子句:
IF (condition_to_evaluate, result_if_true, result_if_false)
In this case, for instance, the expression: 例如,在这种情况下,表达式:
IF(id_t1 IS NOT NULL, True, False) AS in_t1
Is logically equivalent to this one: 在逻辑上等效于这一点:
id_t1 IS NOT NULL AS in_t1
Or, to put it in another way: in_t1
is just a flag saying "if id_t1 is not null" and the same goes for in_t2
and id_t2
. 或者,
in_t1
一种说法: in_t1
只是一个标志,上面写着“ if id_t1不为null”, in_t2
和id_t2
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.