MAPREDUCE服务 MRS-Hive应用开发规则:HQL语法规则之判空
HQL语法规则之判空
判断字段是否为“空”,即没有值,使用“is null”;判断不为空,即有值,使用“is not null”。
要注意的是,在HQL中String类型的字段若是空字符串, 即长度为0,那么对它进行IS NULL的判断结果是False。此时应该使用“col = '' ”来判断空字符串;使用“col != '' ”来判断非空字符串。
正确示例:
select * from default.tbl_src where id is null; select * from default.tbl_src where id is not null; select * from default.tbl_src where name = ''; select * from default.tbl_src where name != '';
错误示例:
select * from default.tbl_src where id = null; select * from default.tbl_src where id != null; select * from default.tbl_src where name is null; select * from default.tbl_src where name is not null;
注:表tbl_src的id字段为Int类型,name字段为String类型。