背景
因为使用alter table … drop (del)等情况都是在异步执行的,所以我们在导数的时候一定会考虑重复导数,补数等情况
分区表
1.先把导数的分区下掉
alter table [table] detach partition ‘xxx’;
2.把数据导入表中
2.1 alter table [table] move partition ‘xxx’ to table [table]
2.2 直接写
两种方式任选一种
3.删除下掉的数据
alter table [xxx] drop detached partition ‘xxx’
ps:可能报错allow_drop_detached
解决:https://stackoverflow.com/questions/61950278/how-to-enable-allow-drop-detached-in-system-settings
/etc/clickhouse-server/users.d/query.settings.xml
<?xml version="1.0"?>
<yandex>
<profiles>
<default>
<!-- Allow ALTER TABLE ... DROP DETACHED PART[ITION] ... queries. -->
<allow_drop_detached>1</allow_drop_detached>
</default>
</profiles>
</yandex>
非分区表
直接truncate然后轮询的查询,没有数据时再导入