这是所有RDBMS系统如何对待null
值发生。
null
有着特殊的意义 - 像not defined
当您检查:
COL1 NOT IN ('reversed')
以下比较将进行:
(null) != reversed
active != reversed
...
,只有那些返回true
会返回:
scala> spark.sql("SELECT 'active' != 'reversed'").show
+-------------------------+
|(NOT (active = reversed))|
+-------------------------+
| true|
+-------------------------+
scala> spark.sql("SELECT null != 'reversed'").show
+---------------------------------------+
|(NOT (CAST(NULL AS STRING) = reversed))|
+---------------------------------------+
| null|
+---------------------------------------+
,你可以看到:(null) != 'reversed'
不返回true
- 这就是为什么你没有看到它在结果集中
此外:
scala> spark.sql("SELECT (null) = 'reversed'").show
+---------------------------------+
|(CAST(NULL AS STRING) = reversed)|
+---------------------------------+
| null|
+---------------------------------+
正因为如此,我们有IS NULL
,IS NOT NULL
, COALESCE
等方法和功能,允许我们使用NULL
值
谢谢澄清!它有帮助。 – Neena