hive报错return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask

场景:计算一年中每一天的数据,每一天的取值是前一年或者半年的平均值,所以我有两张临时表,第一张存放主体的一年中每一天的数据,第二张存放主体近两年的每一天对应的数据,第一张表左连接第二张表,这样子进行窗口函数计算即可。
select h1.*,h3.volume,h3.vwap,
     avg(h3.turnoverval)over(PARTITION by h1.TRADINGITEMID order by h1.natualday asc rows BETWEEN 364 PRECEDING and CURRENT ROW) as turnoverval
from  htsc_dwa_irm.tmp5 h1
     left join htsc_dwa_irm.tmp6 h3 
     on h1.TRADINGITEMID = h3.TRADINGITEMID and h1.natualday=h3.pricingdate 
    and h3.volume!=0 and h3.vwap!=0
但是这样子确报错,语法没有问题,单纯 avg 会有问题,如果求max 后者其他就不会报错。尝试了很久,而跑2019年、2020年的数据是没有问题的,然而跑2018年是会报错的,预估是脏数据导致的,但是不管怎样查询都查不出数据的问题, 最后发现需要把 h1的非交易日排除掉才行正常执行(这样子就不能准确的计算前180天的平均值了)
最后想到的办法是求出sum 和 count,确实可行
     select h1.secucode,h1.natualday,h3.volume,h3.vwap, h3.volume * h3.vwap ,
     SUM(h3.volume * h3.vwap)over(PARTITION by h1.secucode order by h1.natualday asc rows BETWEEN 180 PRECEDING and CURRENT ROW) as turnoverval,
     count(h3.volume * h3.vwap )over(PARTITION by h1.secucode order by h1.natualday asc rows BETWEEN 180 PRECEDING and CURRENT ROW) as turnovercnt
     from htsc_dwa_irm.tmp5 h1
     left join htsc_dwa_irm.tmp_ciqpriceequity h3 
     on h1.secucode = h3.secucode and h1.natualday=h3.pricingdate

你可能感兴趣的:(数据仓库,大数据,hive)