Hive官方提示,Hive在版本0.14之后可以支持对表数据的UPDATE和DELETE:
具体操作如下:
-- 环境参数设置
set hive.support.concurrency=true;
set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
-- 建表,以ORC的方式存储
CREATE TABLE table_01 (
id int,
name string
)
STORED AS ORC
TBLPROPERTIES ("transactional"="true",
"compactor.mapreduce.map.memory.mb"="2048",
"compactorthreshold.hive.compactor.delta.num.threshold"="4",
"compactorthreshold.hive.compactor.delta.pct.threshold"="0.5"
);
-- 手动插入一条测试数据
INSERT INTO TABLE table_01 SELECT 1,'aaa';
-- 更新数据
UPDATE table_01 SET name='bbb' WHERE id=1;
-- 删除数据
DELETE FROM table_01 WHERE id=1;