我必须在此处添加一些介绍,因为SO表示我的问题主要是代码;)
这是我的考试:
CREATE TABLE test (
c1 string,
c2 string
);
INSERT INTO test VALUES
(NULL, NULL),
('A', NULL),
('A', 'B'),
('A', 'A')
;
SELECT *, (c1 <=> c2) as is_equal, (NOT (c1 <=> c2)) as is_not_equal
FROM test;
和结果:
test.c1,test.c2,is_equal,is_not_equal
NULL,NULL,true,NULL
A,NULL,false,NULL
A,B,false,true
A,A,true,false
我宁愿:
test.c1,test.c2,is_equal,is_not_equal
NULL,NULL,true,false
A,NULL,false,true
A,B,false,true
A,A,true,false
这是蜂巢中的错误吗?
编辑
此查询按预期工作:
SELECT *,
(c1 is null and c2 is null) or (c1 is not null and c2 is not null and c1 = c2) as is_equal,
(NOT ((c1 is null and c2 is null) or (c1 is not null and c2 is not null and c1 = c2))) as is_not_equal
FROM test;
EDIT2
我们使用Hive 1.2.1(来自HDP 2.6.2)