kbendick commented on a change in pull request #3213: URL: https://github.com/apache/iceberg/pull/3213#discussion_r731181586
########## File path: core/src/main/java/org/apache/iceberg/util/SmallFileUtil.java ########## @@ -0,0 +1,107 @@ +/* + * 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.util; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.apache.iceberg.DataFile; +import org.apache.iceberg.FileScanTask; +import org.apache.iceberg.Table; +import org.apache.iceberg.TableProperties; +import org.apache.iceberg.io.CloseableIterable; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SmallFileUtil { + private static final Logger LOG = LoggerFactory.getLogger(SmallFileUtil.class); + + private SmallFileUtil() { + + } + + /** + * Returns whether small files should be merged. + */ + public static boolean shouldMergeSmallFiles(Table table) { + boolean shouldMerge = false; + + long currentTimeMillis = System.currentTimeMillis(); + Map<String, String> props = table.properties(); + boolean autoMergeEnable = PropertyUtil.propertyAsBoolean( + props, + TableProperties.WRITE_FLINK_AUTO_COMPACT_ENABLED, + TableProperties.WRITE_FLINK_AUTO_COMPACT_ENABLED_DEFAULT); + + long mergeIntervalMillis = PropertyUtil.propertyAsLong( + props, + TableProperties.WRITE_FLINK_COMPACT_INTERVAL_MS, + TableProperties.WRITE_FLINK_COMPACT_INTERVAL_MS_DEFAULT); + + long lastCommittedTimestamp = PropertyUtil.propertyAsLong( + props, + TableProperties.WRITE_FLINK_COMPACT_LAST_REWRITE_MS, + TableProperties.WRITE_FLINK_COMPACT_LAST_REWRITE_MS_DEFAULT); + + long smallFileThreshold = PropertyUtil.propertyAsLong( + props, + TableProperties.WRITE_FLINK_COMPACT_SMALL_FILE_NUMS, + TableProperties.WRITE_FLINK_COMPACT_SMALL_FILE_NUMS_DEFAULT); + + LOG.info("Summary: actual compact interval: {}s, compact.auto.enabled: {}, " + + "compact.interval: {}s, current time: {}, last compact time: {}, small-file-nums: {}", + (currentTimeMillis - lastCommittedTimestamp) / 1000, + autoMergeEnable, + mergeIntervalMillis / 1000, + new Date(currentTimeMillis), + new Date(lastCommittedTimestamp), + smallFileThreshold); + + if (autoMergeEnable && (currentTimeMillis - lastCommittedTimestamp >= mergeIntervalMillis || Review comment: Instead of just using a no-op, would it make more sense to skip adding these operators to the DAG if they're not used? If users enable it, and it adds to their job graph and they don't properly handle UIDs, given that we properly handle UIDs on our added operators, I can't remember if that causes issues or not. But for me, it feels like we shouldn't add unused processing nodes to the job graph is this whole workflow is disabled (e.g. users might choose to focus their flink compute on just writing as Flink doesn't autoscale as well as some might like it to and instead compact files in a separate workflow entirely, maybe with Spark even). -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
