hive insert 中途失败怎么办?

What happens when a hive insert is failed halfway?

假设一次插入需要在hive 中加载100 条记录并且已经插入了40 条记录并且由于某种原因插入失败。事务是否会完全回滚,撤消插入的 40 条记录? 或者我们会在配置单元中看到 40 条记录 table 即使在插入查询失败后?

操作是原子的(甚至对于 non-ACID table):如果您使用 HiveQL 插入或重写数据,它会将数据写入临时位置,并且仅当命令成功时文件才会移动到table 位置(如果是 INSERT OVERWRITE,旧文件将被删除)。如果 SQL 语句失败,数据将保持语句执行前的状态。

关于 S3 直接写入的注意事项:应禁用直接写入 S3 功能以允许 Hive 写入临时位置并仅在操作成功时重写目标文件夹:

-- Disable AWS S3 direct writes:
set hive.allow.move.on.s3=true; 

另请阅读此文档,了解有关并发模式和限制中支持的 ACID 功能的更多详细信息:What is ACID and why should you use it?

Up until Hive 0.13, atomicity, consistency, and durability were provided at the partition level. Isolation could be provided by turning on one of the available locking mechanisms (ZooKeeper or in memory). With the addition of transactions in Hive 0.13 it is now possible to provide full ACID semantics at the row level, so that one application can add rows while another reads from the same partition without interfering with each other.

另请阅读有关 Hive locks with ACID enabled (transactional and non-transactional tables)

的内容

更新:Since DEC 2020 Amazon S3 is strongly consistent at no extra charge. 因此,删除了有关 S3 最终一致性的部分。