deniskuzZ commented on code in PR #5529:
URL: https://github.com/apache/hive/pull/5529#discussion_r1861808232


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/IcebergTableUtil.java:
##########
@@ -458,6 +458,52 @@ public static List<DeleteFile> getDeleteFiles(Table table, 
String partitionPath)
         t -> ((PositionDeletesScanTask) t).file()));
   }
 
+  public static float getFileSizeRatio(Table table, String partitionPath, long 
fileSizeInBytesThreshold) {
+    long uncompactedFilesCount = getDataFileCount(table, partitionPath, 
fileSizeInBytesThreshold, true);
+    long compactedFilesCount = getDataFileCount(table, partitionPath, 
fileSizeInBytesThreshold, false);
+
+    if (uncompactedFilesCount == 0) {
+      return 0;
+    } else if (compactedFilesCount == 0) {
+      return 1;
+    } else {
+      return uncompactedFilesCount * 1.0f / (uncompactedFilesCount + 
compactedFilesCount);
+    }
+  }
+
+  private static long getDataFileCount(Table table, String partitionPath, long 
fileSizeInBytesThreshold,
+      boolean isLess) {
+    CloseableIterable<FileScanTask> fileScanTasks =
+        
table.newScan().useSnapshot(table.currentSnapshot().snapshotId()).ignoreResiduals().planFiles();
+    CloseableIterable<FileScanTask> filteredFileScanTasks =
+        CloseableIterable.filter(fileScanTasks, t -> {
+          DataFile file = t.asFileScanTask().file();
+          return (!table.spec().isPartitioned() ||
+              partitionPath == null && file.specId() != table.spec().specId() 
||
+              partitionPath != null &&
+                  
table.specs().get(file.specId()).partitionToPath(file.partition()).equals(partitionPath))
 &&
+              (isLess ? file.fileSizeInBytes() < fileSizeInBytesThreshold :
+                  file.fileSizeInBytes() >= fileSizeInBytesThreshold);
+        });
+    return Lists.newArrayList(filteredFileScanTasks).size();
+  }
+
+  public static long countDeleteRecords(Table table, String partitionPath) {
+    Table deletesTable =
+        MetadataTableUtils.createMetadataTableInstance(table, 
MetadataTableType.POSITION_DELETES);
+    CloseableIterable<ScanTask> deletesScanTasks = 
deletesTable.newBatchScan().planFiles();
+    CloseableIterable<ScanTask> filteredDeletesScanTasks =
+        CloseableIterable.filter(deletesScanTasks, t -> {
+          DeleteFile file = ((PositionDeletesScanTask) t).file();
+          return !table.spec().isPartitioned() ||

Review Comment:
   Up to you; it's a matter of style. I haven't seen any recommendations on 
that topic in either Clean Code or Effective Java.
   Only remark it should be easy to read and understand.
   
   ````
   Even if the operator precedence seems clear to you, it might not be to 
others—you shouldn’t assume that other programmers know precedence as well as 
you do.
   if (a == b && c == d) // AVOID!
   if ((a == b) && (c == d)) // RIGHT"
   ````
   to be honest, that seems like a joke 
   
   ````
   x && y || z
   x && (y || z)
   ````
   are 2 completely different expressions, if you know  boolean algebra
   



-- 
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: gitbox-unsubscr...@hive.apache.org

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


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

Reply via email to