dengzhhu653 commented on code in PR #5950: URL: https://github.com/apache/hive/pull/5950#discussion_r2443659032
########## standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/SmallFilesWarningUtil.java: ########## @@ -0,0 +1,104 @@ +/* + * 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.hadoop.hive.metastore.utils; + +import java.util.Map; +import java.util.Optional; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.common.StatsSetupConst; +import org.apache.hadoop.hive.metastore.conf.MetastoreConf; + +public final class SmallFilesWarningUtil { + private SmallFilesWarningUtil() {} + + /** Default minimum number of files before we consider emitting the warning. */ + public static final long DEFAULT_MIN_FILES = 100L; + + /** + * True if quick HMS stats in {@code parameters} indicate small average file size. + * Missing/malformed stats or insufficient file count return false. + */ + public static boolean smallAverageFilesDetected(long minFiles, + long avgSizeThreshold, + Map<String, String> parameters) { + if (parameters == null) return false; + + final String ts = parameters.get(StatsSetupConst.TOTAL_SIZE); + final String nf = parameters.get(StatsSetupConst.NUM_FILES); + if (ts == null || nf == null) return false; + + final long totalSize; + final long numFiles; + try { + totalSize = Long.parseLong(ts); + numFiles = Long.parseLong(nf); + } catch (NumberFormatException ignore) { + return false; + } + + if (numFiles <= minFiles || totalSize <= 0) return false; + + final long avg = Math.floorDiv(totalSize, numFiles); + return avg <= avgSizeThreshold; + } + + /** + * Convenience overload: reads the threshold from {@code conf} and uses {@link #DEFAULT_MIN_FILES}. + * Returns false if {@code conf} is null. + */ + public static boolean smallAverageFilesDetected(Configuration conf, + Map<String, String> parameters) { + if (conf == null) return false; Review Comment: why `conf` would be null? -- 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]
