RussellSpitzer commented on a change in pull request #2379:
URL: https://github.com/apache/iceberg/pull/2379#discussion_r609715625



##########
File path: 
core/src/main/java/org/apache/iceberg/spark/actions/compaction/BinningCompactionStrategy.java
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iceberg.spark.actions.compaction;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.actions.compaction.DataCompactionStrategy;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
+import org.apache.iceberg.util.BinPacking;
+import org.apache.iceberg.util.PropertyUtil;
+
+import static org.apache.iceberg.util.StreamUtil.streamOf;
+
+/**
+ * A Compaction strategy for rewriting files based on their sizes, the goal is 
to end up with files
+ * whose size is close to the Target Size as specified in this strategy's 
options.
+ */
+public abstract class BinningCompactionStrategy implements 
DataCompactionStrategy {
+
+
+  public static final String TARGET_SIZE_OPTION = "target_size";
+  public static final String TARGET_THRESHOLD_OPTION = "target_threshold";
+
+  // TODO Maybe these should be global?
+  public static final String MAX_JOB_SIZE_OPTION = "max_job_size";
+
+  protected static final long TARGET_THRESHOLD_DEFAULT = 50 * 1024 * 1024; // 
50 MB
+  protected static final long TARGET_SIZE_DEFAULT = 512 * 1024 * 1024; // 512 
MB // TODO (Table default)
+  protected static final long MAX_JOB_SIZE_DEFAULT = 100L * 1024 * 1024 * 
1024; // 100 GB
+
+  private long targetThreshold = TARGET_THRESHOLD_DEFAULT;
+  private long targetSize = TARGET_SIZE_DEFAULT;
+  private long maxJobSize = MAX_JOB_SIZE_DEFAULT;
+
+  @Override
+  public String name() {
+    return "Binning Size Based Compaction Strategy";
+  }
+
+  @Override
+  public Set<String> validOptions() {
+    return ImmutableSet.of(TARGET_SIZE_OPTION, TARGET_THRESHOLD_OPTION, 
MAX_JOB_SIZE_OPTION);
+  }
+
+  @Override
+  public Iterator<FileScanTask> filesToCompact(Iterator<FileScanTask> 
dataFiles) {
+    return streamOf(dataFiles)
+        .filter(task -> Math.abs(task.file().fileSizeInBytes() - targetSize) > 
targetThreshold)

Review comment:
       I think that's a good Idea, this is really just a prototype so we can 
build consensus on the approach. I didn't want to code in all the features just 
yet.




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to