1
0

[HUDI-1423] Support delete in hudi-java-client (#2353)

This commit is contained in:
Shen Hong
2021-01-03 20:38:45 +08:00
committed by GitHub
parent a23aa41a1a
commit ff8313caf1
5 changed files with 188 additions and 2 deletions

View File

@@ -23,6 +23,7 @@ import org.apache.hudi.client.HoodieJavaWriteClient;
import org.apache.hudi.client.common.HoodieJavaEngineContext;
import org.apache.hudi.common.fs.FSUtils;
import org.apache.hudi.common.model.HoodieAvroPayload;
import org.apache.hudi.common.model.HoodieKey;
import org.apache.hudi.common.model.HoodieRecord;
import org.apache.hudi.common.model.HoodieTableType;
import org.apache.hudi.common.table.HoodieTableMetaClient;
@@ -104,6 +105,15 @@ public class HoodieJavaWriteClientExample {
recordsSoFar.stream().map(r -> new HoodieRecord<HoodieAvroPayload>(r)).collect(Collectors.toList());
client.upsert(writeRecords, newCommitTime);
// Delete
newCommitTime = client.startCommit();
LOG.info("Starting commit " + newCommitTime);
// just delete half of the records
int numToDelete = recordsSoFar.size() / 2;
List<HoodieKey> toBeDeleted =
recordsSoFar.stream().map(HoodieRecord::getKey).limit(numToDelete).collect(Collectors.toList());
client.delete(toBeDeleted, newCommitTime);
client.close();
}
}