JingsongLi commented on code in PR #1199:
URL: https://github.com/apache/incubator-paimon/pull/1199#discussion_r1201502394
##########
paimon-core/src/main/java/org/apache/paimon/manifest/ManifestFileMeta.java:
##########
@@ -185,4 +207,108 @@ private static void mergeCandidates(
newMetas.addAll(merged);
}
}
+
+ static class FullCompactionHelper {
+ private List<ManifestFileMeta> metas;
+ private ManifestFile manifestFile;
+ private RowType partitionType;
+ private int index;
+
+ public FullCompactionHelper(
+ List<ManifestFileMeta> metas, ManifestFile manifestFile,
RowType partitionType) {
+ this.metas = metas;
+ this.manifestFile = manifestFile;
+ this.partitionType = partitionType;
+ int index = metas.size();
+ }
+
+ public int getFirstManifest() {
+ // Manifests which container DELETE ManifestEntry
+ List<ManifestFileMeta> delta = Lists.newArrayList();
+ long deltaSize = 0;
+ long baseSize = 0;
+
+ for (ManifestFileMeta meta : metas) {
+ if (meta.numDeletedFiles > 0) {
+ deltaSize += meta.fileSize();
+ delta.add(meta);
+ } else {
+ baseSize += meta.fileSize();
+ }
+ }
+
+ if (deltaSize > baseSize) {
+ if (partitionType.getFieldCount() != 0) {
+ Set<BinaryRow> partitions =
findPartitionsToDeleteData(manifestFile, delta);
+
+ Predicate paritionPredicate =
+ convertPartitionToPredicate(partitionType,
partitions);
+
+ // if finding the valid manifest, return the index of
manifest ,else the size of
+ // manifests
+ BiFunction<Predicate, List<ManifestFileMeta>, Integer>
+ firstValidManifestFunction =
+ (predicate, manifests) -> {
+ FieldStatsArraySerializer
fieldStatsArraySerializer =
+ new
FieldStatsArraySerializer(partitionType);
+ int firstMatchIndex = manifests.size();
+ for (int i = 0; i < manifests.size();
i++) {
+ ManifestFileMeta manifestFileMeta
= manifests.get(i);
+ if (paritionPredicate.test(
+
manifestFileMeta.numAddedFiles
+ +
manifestFileMeta.numDeletedFiles,
+ manifestFileMeta
+ .partitionStats()
+
.fields(fieldStatsArraySerializer))) {
+ firstMatchIndex = i;
+ break;
+ }
+ }
+ return firstMatchIndex;
+ };
+
+ index =
firstValidManifestFunction.apply(paritionPredicate, metas);
+ } else {
+ index = 0;
+ }
+ }
+
+ return index;
+ }
+
+ public boolean needFullCompaction() {
+ return index < metas.size();
+ }
+
+ private Predicate convertPartitionToPredicate(
+ RowType partitionType, Set<BinaryRow> partitions) {
+ RowDataToObjectArrayConverter rowDataToObjectArrayConverter =
+ new RowDataToObjectArrayConverter(partitionType);
+
+ List<Predicate> predicateList =
+ partitions.stream()
+ .map(
+ partition ->
+
AbstractFileStoreScan.partitionToPredicate(
+ partition,
rowDataToObjectArrayConverter))
+ .collect(Collectors.toList());
+ Predicate paritionPredicate = PredicateBuilder.or(predicateList);
+ return paritionPredicate;
+ }
+
+ private Set<BinaryRow> findPartitionsToDeleteData(
+ ManifestFile manifestFile, List<ManifestFileMeta>
manifestContainDelete) {
+ Set<BinaryRow> partitions = new HashSet<>();
+ for (ManifestFileMeta meta : manifestContainDelete) {
+ List<ManifestEntry> manifestEntries =
manifestFile.read(meta.fileName);
Review Comment:
Maybe we can just do a merge here. Do merge and collect partitions for
delete entries...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]