我正在尝试计算两个表之间的比较。由于减号运算符在蜂巢中不起作用,因此不会发生。您能否提供一些简单的方法来进行两个表之间的计数比较。
select 'Call Detail - Hive T1 to HDFS Staging - Data Compare', case when cnt>0 then 'Fail' Else 'Pass' end from (select count(*) cnt from ( (select count(*) from students1 s1)- (select count(*) from students2 s2) ) as tbl1 ) as tbl2;
抛出错误:
失败:ParseException行81:0无法识别源中’(’‘(’‘select’附近的输入
使用cross join如果你没有GROUP BY列。在这种情况下,它将产生包含两个计数的一行:
cross join
select s.cnt-s1.cnt diff, case when abs(s.cnt-s1.cnt) > 0 then 'Fail' Else 'Pass' end result from (select count(*) cnt from students1 s1) s cross join (select count(*) cnt from students2 s2) s1
如果要添加一些按列分组以在更详细的谷物上进行比较,则可以FULL JOIN对按列分组使用:
FULL JOIN
select s.col1 s_col1, s1.col1 s1_col1, s.cnt-s1.cnt diff, case when abs(s.cnt-s1.cnt) > 0 then 'Fail' Else 'Pass' end result from (select count(*) cnt, col1 from students1 s1 group by col1) s full join (select count(*) cnt, col1 from students2 s2 group by col1) s1 on s.col1 = s1.col1
该查询将返回计算出差异的联接行,并且两个表中都不联接行。