【发布时间】:2016-06-23 20:29:48
【问题描述】:
下面的 hive 命令,
select * from my_new_table
where month(time_stamp)= '03'
and year(time_stamp) = '2016'
and age = '1'
and gender = '0'
and income = '4'
and ethnicity = '3'
and marital_status = '1';
为 2016 年 3 月 (03) 月份的所有数据(31 天)生成以下结果:
time_stamp age gender income ethnicity marital_status
2016-03-14@17:42:47.000 1 0 4 3 1
2016-03-14@16:10:51.000 1 0 4 3 1
2016-03-20@15:16:44.000 1 0 4 3 1
2016-03-14@17:13:51.000 1 0 4 3 1
2016-03-14@17:12:51.000 1 0 4 3 1
2016-03-14@18:24:51.000 1 0 4 3 1
2016-03-03@13:02:06.000 1 0 4 3 1
同样,我想获取 2016 年第二季度(或第 n 季度,数据应为 3 个月,从本季度的 3 月 1 日至 5 月 31 日)和第 12 周(或第 n 周,数据应为2016 年这个特定周的 7 天)。什么是正确的 Hive 命令?
如果我在 Hive 命令中将 month 替换为 quarter 或 week,则会出错。
select * from my_new_table
where quarter(time_stamp)='03'
and year(time_stamp) = '2016';
返回
FAILED: SemanticException [Error 10011]: Line 1:71 Invalid function 'quarter'
和
select * from my_new_table
where week(time_stamp)='12'
and year(time_stamp) = '2016';
返回
FAILED: SemanticException [Error 10011]: Line 1:71 Invalid function 'week'
看起来需要在获取第 n 个季度或第周时包含计算,但不确定。请帮忙。谢谢。
【问题讨论】:
-
如果您显示您尝试过的命令以及生成的特定错误,这可能会有所帮助。 Date Functions in Hive 可能会提供信息。
-
select * from my_new_table where quarter(time_stamp)='03' and year(time_stamp) = '2016'; FAILED: SemanticException [Error 10011]: Line 1:71 Invalid function 'quarter' select * from my_new_table where week(time_stamp)='12' and year(time_stamp) = '2016'; FAILED: SemanticException [Error 10011]: Line 1:71 Invalid function 'week'
标签: hive