dengzhhu653 commented on code in PR #5950:
URL: https://github.com/apache/hive/pull/5950#discussion_r2437813745


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/Msck.java:
##########
@@ -240,6 +246,76 @@ public int repair(MsckInfo msckInfo) throws TException, 
MetastoreException, IOEx
           }
         }
 
+        // Generate small files warnings only for partsNotInMs
+        try {
+          // Threshold in bytes for average file size considered "small"
+          final long threshold =
+                  MetastoreConf.getLongVar(getConf(), 
MetastoreConf.ConfVars.MSCK_SMALLFILES_AVG_SIZE);
+
+          // Collect partition names
+          final List<String> names = new ArrayList<>(partsNotInMs.size());
+          for (CheckResult.PartitionResult pr : partsNotInMs) {
+            final String name = pr.getPartitionName();
+            if (name != null && !name.isEmpty()) {
+              names.add(name);
+            }
+          }
+
+          // Batch over the names to limit single-RPC payload.
+          final int BATCH = 1000;
+          final Map<String, Partition> byName = new HashMap<>(names.size() * 
2);
+
+          for (int i = 0; i < names.size(); i += BATCH) {
+            final List<String> batch = names.subList(i, Math.min(i + BATCH, 
names.size()));
+            final GetPartitionsByNamesRequest req = new 
GetPartitionsByNamesRequest(table.getDbName(), table.getTableName());
+            req.setNames(batch);
+
+            // In this branch, getPartitionsByNames returns List<Partition>
+            List<Partition> plist;
+            try {
+              @SuppressWarnings("unchecked")
+              List<Partition> tmp = (List<Partition>) 
getMsc().getPartitionsByNames(req);
+              plist = (tmp != null) ? tmp : Collections.emptyList();
+            } catch (NoSuchObjectException e) {
+              plist = Collections.emptyList();
+            }
+
+            for (Partition p : plist) {
+              final String pName = 
Warehouse.makePartName(table.getPartitionKeys(), p.getValues());
+              byName.put(pName, p);
+            }
+          }
+
+          // Build small-files stats for partitions that have quick HMS stats.
+          final Map<String, String> smallFilesStats = new TreeMap<>();
+
+          for (String pName : names) {
+            final Partition p = byName.get(pName);
+            if (p == null) {
+              // not found / not visible yet
+              continue;
+            }
+
+            final Map<String, String> params = p.getParameters();
+            // Use util to decide if this partition should trigger the warning
+            if 
(SmallFilesWarningUtil.smallAverageFilesDetected(SmallFilesWarningUtil.DEFAULT_MIN_FILES,
 threshold, params)) {
+              // We know stats exist and are well-formed; compute numbers for 
the value string
+              final long totalSize = 
Long.parseLong(params.get(StatsSetupConst.TOTAL_SIZE));
+              final long numFiles  = 
Long.parseLong(params.get(StatsSetupConst.NUM_FILES));
+              final long avg       = Math.floorDiv(totalSize, numFiles);
+              smallFilesStats.put(pName, "avgBytes=" + avg + ", partition 
total files=" + numFiles + ", totalBytes=" + totalSize);
+            }
+          }
+
+          msckInfo.setSmallFilesStats(smallFilesStats.isEmpty() ? 
Collections.emptyMap() : smallFilesStats);

Review Comment:
   why not `msckInfo.setSmallFilesStat(smallFilesStats)`



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

Reply via email to