Guosmilesmile commented on code in PR #12979:
URL: https://github.com/apache/iceberg/pull/12979#discussion_r2079918798


##########
flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/sink/IcebergSink.java:
##########
@@ -216,7 +237,81 @@ public SimpleVersionedSerializer<IcebergCommittable> 
getCommittableSerializer()
   @Override
   public void addPostCommitTopology(
       DataStream<CommittableMessage<IcebergCommittable>> committables) {
-    // TODO Support small file compaction
+
+    if (!compactMode) {
+      return;
+    }
+
+    SingleOutputStreamOperator<TableChange> tableChangeStream =
+        committables
+            .global()
+            .transform(
+                "CommittableToTableChangeConverter",
+                TypeInformation.of(TableChange.class),
+                new CommittableToTableChangeConverter(tableLoader.clone()))
+            .uid("committable-to-table-change-converter")
+            .forceNonParallel();
+    try {
+      TriggerLockFactory triggerLockFactory = 
LockFactoryCreator.create(flinkOptions);
+      RewriteDataFiles.Builder rewriteBuilder = 
createRewriteBuilder(flinkOptions);
+      TableMaintenance.Builder builder =
+          TableMaintenance.forChangeStream(tableChangeStream, tableLoader, 
triggerLockFactory)
+              .add(rewriteBuilder);
+      configureTableMaintenance(builder, flinkOptions);
+      builder.append();
+    } catch (IOException e) {
+      throw new UncheckedIOException("Failed to create tableMaintenance ", e);
+    }
+  }
+
+  private RewriteDataFiles.Builder createRewriteBuilder(Map<String, String> 
properties) {
+    RewriteDataFilesConfig rewriteDataFilesConfig = new 
RewriteDataFilesConfig(properties);
+    RewriteDataFiles.Builder builder = RewriteDataFiles.builder();
+    Optional.ofNullable(rewriteDataFilesConfig.getPartialProgressEnable())
+        .ifPresent(builder::partialProgressEnabled);
+    Optional.ofNullable(rewriteDataFilesConfig.getPartialProgressMaxCommits())
+        .ifPresent(builder::partialProgressMaxCommits);
+    Optional.ofNullable(rewriteDataFilesConfig.getMaxRewriteBytes())
+        .ifPresent(builder::maxRewriteBytes);
+    Optional.ofNullable(rewriteDataFilesConfig.getTargetFileSizeBytes())
+        .ifPresent(builder::targetFileSizeBytes);
+    Optional.ofNullable(rewriteDataFilesConfig.getMinFileSizeBytes())
+        .ifPresent(builder::minFileSizeBytes);
+    Optional.ofNullable(rewriteDataFilesConfig.getMaxFileSizeBytes())
+        .ifPresent(builder::maxFileSizeBytes);
+    Optional.ofNullable(rewriteDataFilesConfig.getMaxFileGroupSizeBytes())
+        .ifPresent(builder::maxFileGroupSizeBytes);
+    Optional.ofNullable(rewriteDataFilesConfig.getMinInputFiles())
+        .ifPresent(builder::minInputFiles);
+    Optional.ofNullable(rewriteDataFilesConfig.getDeleteFileThreshold())
+        .ifPresent(builder::deleteFileThreshold);
+    
Optional.ofNullable(rewriteDataFilesConfig.getRewriteAll()).ifPresent(builder::rewriteAll);
+
+    Optional.ofNullable(rewriteDataFilesConfig.getScheduleOnCommitCount())
+        .ifPresent(builder::scheduleOnCommitCount);
+    Optional.ofNullable(rewriteDataFilesConfig.getScheduleOnDataFileCount())
+        .ifPresent(builder::scheduleOnDataFileCount);
+    Optional.ofNullable(rewriteDataFilesConfig.getScheduleOnDataFileSize())
+        .ifPresent(builder::scheduleOnDataFileSize);
+    Optional.ofNullable(rewriteDataFilesConfig.getScheduleOnIntervalSecond())
+        .ifPresent(
+            intervalSecond -> 
builder.scheduleOnInterval(Duration.ofSeconds(intervalSecond)));
+
+    return builder;
+  }

Review Comment:
   You are right , I move it to RewriteDataFiles/Builder.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to