蜂巢。 Select 最近 N 周的数据

Hive. Select data for the last N weeks

我正在将一些 MySQL 查询重写到 HiveQL 中,有些东西我有一段时间没能解决。

MySQL 语法是这样的(bc_date 是一个 日期 ):

WHERE date_format(bc_date, '%x-%v') >= date_format(CURRENT_DATE - INTERVAL 16 WEEK, '%x-%v')

如何在 HiveQL 中表达这一点?

我的 Hive 版本不支持 date_format 功能,该功能可用 "as of Hive 1.2.0"

这是我的一个建议,它似乎有效。我将 0 添加到小于 10 的周数,以进行正确的字符串比较

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 )