我正在将一些MySQL查询重写为HiveQL,并且有些东西我不能指出一段时间。
MySQL语法是这样的(bc_date
是 date ):
WHERE date_format(bc_date, '%x-%v') >= date_format(CURRENT_DATE - INTERVAL 16 WEEK, '%x-%v')
如何在HiveQL中表达这一点?
我的Hive版本不支持date_format
功能,该功能可用于"从Hive 1.2.0"
答案 0 :(得分:0)
这是我的建议,似乎有效。我正在将小于0的周加0,以进行正确的字符串比较
concat(year(broadcast_time), '-', case when weekofyear(broadcast_time)<10 then concat(0,weekofyear(broadcast_time)) else weekofyear(broadcast_time) end ) >=
concat( year(date_sub(to_date(from_unixtime(unix_timestamp())),112)), '-', case when weekofyear(date_sub(to_date(from_unixtime(unix_timestamp())),112))<10 then concat(0,weekofyear(date_sub(to_date(from_unixtime(unix_timestamp())),112))) else weekofyear(date_sub(to_date(from_unixtime(unix_timestamp())),112)) end )