批量插入
导入多条事件时,先收集记录再统一提交,避免每条事件都调用一次插入。表和 EventLog 映射沿用主键生成:
EventLog first = new EventLog();
first.setEventName("login");
EventLog second = new EventLog();
second.setEventName("logout");
lambda.insert(EventLog.class)
.applyEntity(first, second)
.executeSumResult();
String firstId = first.getId();
String secondId = second.getId();
配置 KeyType.UUID32 后,每条事件在插入前获得应用生成的 ID。无需数据库生成列回填时,dbVisitor 使用 JDBC batch 提交插入。
注意
合并提交不等于增加了整体回滚的事务。调用失败后先确认已写入的数据;MergeTree 不会拒绝重复 ID,直接重试可能产生重复记录。见重复记录处理。