gpt4 book ai didi

hadoop - 为什么 "select unix_timestamp(' ') is null"当 "select unix_timestamp(' ')"返回 null 时返回 false?

转载 作者:可可西里 更新时间:2023-11-01 14:44:22 25 4
gpt4 key购买 nike

使用 Spark 1.6.2 并尝试查找字段是否包含空字符串或日期值。

Spark documentation解释说,如果 unix_timestamp() 函数在失败时返回 null,那么预期会出现以下行为:

sqlContext.sql("select unix_timestamp('')").show
+----+
| _c0|
+----+
|null|
+----+

但是当我尝试用“is null”检查它时,它返回 false:

sqlContext.sql("select unix_timestamp('') is null").show
+-----+
| _c0|
+-----+
|false|
+-----+

相同的查询在 Hive 中返回 true:

hive> select unix_timestamp('') is null;
OK
true

为了完整起见,这里是对 null 的 null 检查:

sqlContext.sql("select null is null").show
+----+
| _c0|
+----+
|true|
+----+

最佳答案

这是一个错误,看起来它已经在 Spark 2.x 分支中得到解决(可能是 SPARK-12054 )问题的根源是 unix_timestamp 返回的模式。如果你执行:

sqlContext.sql("select unix_timestamp('')").printSchema

你会看到:

root
|-- _c0: long (nullable = false)

由于模式被报告为不可nullable 值未被检查并且 unix_timestamp(...).isNull 始终为 false。

关于hadoop - 为什么 "select unix_timestamp(' ') is null"当 "select unix_timestamp(' ')"返回 null 时返回 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40496163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com