在配置单元表中删除具有特定时间键的行

时间:2019-01-12 07:39:16

标签: hadoop hive

enter image description here我有一个表,其中包含特定时间键的条目。每个月的表应更新前三个月的结果。以前的记录应删除。该脚本每月自动运行一次。是否有办法在蜂巢中实现此目的?

2 个答案:

答案 0 :(得分:0)

如果您想通过查询进行操作。

insert overwrite table <tablename>
select 
col1,
col2,
....
from tablename where timekey >(select from_unixtime(unix_timestamp(add_months(current_date(),-3), 'yyyy-MM-dd'), 'yyyyMM'));

以上查询将读取表数据并仅插入最近3个月的记录

答案 1 :(得分:0)

就删除更新而言,Hive不支持此类操作,但支持新的Hive版本事务。但是您需要为此创建事务配置单元表。

下面是创建此交易表时可以使用的语法,

CREATE TABLE hello_acid (key int, value int)
PARTITIONED BY (load_date date)
CLUSTERED BY(key) INTO 3 BUCKETS
STORED AS ORC TBLPROPERTIES ('transactional'='true');

您可以参考下面的链接以获取更多详细信息, https://hortonworks.com/tutorial/using-hive-acid-transactions-to-insert-update-and-delete-data/

希望这会有所帮助。