yihua commented on code in PR #7690:
URL: https://github.com/apache/hudi/pull/7690#discussion_r1086116287


##########
hudi-common/src/main/java/org/apache/hudi/common/table/view/AbstractTableFileSystemView.java:
##########
@@ -289,6 +296,123 @@ private void clear() {
    */
   protected abstract void resetViewState();
 
+  /**
+   * Batch loading all the partitions if needed.
+   *
+   * @return A list of relative partition paths of all partitions.
+   */
+  private List<String> ensureAllPartitionsLoadedCorrectly() {
+    ValidationUtils.checkArgument(!isClosed(), "View is already closed");
+    try {
+      List<String> formattedPartitionList = getAllPartitionPaths().stream()
+          .map(this::formatPartitionKey).collect(Collectors.toList());
+      ensurePartitionsLoadedCorrectly(formattedPartitionList);
+      return formattedPartitionList;
+    } catch (IOException e) {
+      throw new HoodieIOException("Failed to get all partition paths", e);
+    }
+  }
+
+  /**
+   * Allows lazily loading the partitions if needed.
+   *
+   * @param partitionList list of partitions to be loaded if not present.
+   */
+  private void ensurePartitionsLoadedCorrectly(List<String> partitionList) {
+
+    ValidationUtils.checkArgument(!isClosed(), "View is already closed");
+
+    Set<String> partitionSet = new HashSet<>();
+    partitionList.forEach(partition ->
+        addedPartitions.computeIfAbsent(partition, partitionPathStr -> {
+          if (!isPartitionAvailableInStore(partitionPathStr)) {
+            partitionSet.add(partitionPathStr);
+          }
+          return true;
+        })
+    );
+
+    if (!partitionSet.isEmpty()) {
+      long beginTs = System.currentTimeMillis();
+      // Not loaded yet
+      try {
+        LOG.info("Building file system view for partitions " + partitionSet);
+
+        // Pairs of relative partition path and absolute partition path
+        List<Pair<String, Path>> absolutePartitionPathList = 
partitionSet.stream()
+            .map(partition -> Pair.of(
+                partition, 
FSUtils.getPartitionPath(metaClient.getBasePathV2(), partition)))
+            .collect(Collectors.toList());
+        long beginLsTs = System.currentTimeMillis();
+        Map<Pair<String, Path>, FileStatus[]> statusesMap =
+            listPartitions(absolutePartitionPathList);
+        long endLsTs = System.currentTimeMillis();
+        LOG.debug("Time taken to list partitions " + partitionSet + " =" + 
(endLsTs - beginLsTs));
+        statusesMap.forEach((partitionPair, statuses) -> {
+          String relativePartitionStr = partitionPair.getLeft();
+          List<HoodieFileGroup> groups = addFilesToView(statuses);
+          if (groups.isEmpty()) {
+            storePartitionView(relativePartitionStr, new ArrayList<>());
+          }
+          LOG.debug("#files found in partition (" + relativePartitionStr + ") 
=" + statuses.length);
+        });
+      } catch (IOException e) {
+        throw new HoodieIOException("Failed to list base files in partitions " 
+ partitionSet, e);
+      }
+      long endTs = System.currentTimeMillis();
+      LOG.debug("Time to load partition " + partitionSet + " =" + (endTs - 
beginTs));
+    }
+  }
+
+  /***
+   * @return A list of relative partition paths of all partitions.
+   * @throws IOException upon error.
+   */
+  protected List<String> getAllPartitionPaths() throws IOException {

Review Comment:
   Fixed.



##########
hudi-common/src/main/java/org/apache/hudi/common/table/view/AbstractTableFileSystemView.java:
##########
@@ -550,6 +674,28 @@ public final Stream<HoodieBaseFile> 
getLatestBaseFilesBeforeOrOn(String partitio
     }
   }
 
+  @Override

Review Comment:
   I think eventually we should unify the code path between 
metadata-table-based and FS-based code path, so I put it here.



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

Reply via email to