bvaradar commented on code in PR #11923:
URL: https://github.com/apache/hudi/pull/11923#discussion_r1840872466


##########
hudi-common/src/main/java/org/apache/hudi/common/table/timeline/versioning/v1/ArchivedTimelineLoaderV1.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.hudi.common.table.timeline.versioning.v1;
+
+import org.apache.hudi.avro.model.HoodieArchivedMetaEntry;
+import org.apache.hudi.avro.model.HoodieMergeArchiveFilePlan;
+import org.apache.hudi.common.model.HoodieLogFile;
+import org.apache.hudi.common.model.HoodiePartitionMetadata;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.log.HoodieLogFormat;
+import org.apache.hudi.common.table.log.block.HoodieAvroDataBlock;
+import org.apache.hudi.common.table.log.block.HoodieLogBlock;
+import org.apache.hudi.common.table.timeline.ArchivedTimelineLoader;
+import org.apache.hudi.common.table.timeline.HoodieArchivedTimeline;
+import org.apache.hudi.common.table.timeline.TimelineMetadataUtils;
+import org.apache.hudi.common.util.FileIOUtils;
+import org.apache.hudi.common.util.StringUtils;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+import org.apache.hudi.exception.HoodieIOException;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StoragePath;
+import org.apache.hudi.storage.StoragePathInfo;
+
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.IndexedRecord;
+import org.jetbrains.annotations.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.StreamSupport;
+
+public class ArchivedTimelineLoaderV1 implements ArchivedTimelineLoader {
+  private static final String MERGE_ARCHIVE_PLAN_NAME = "mergeArchivePlan";
+  private static final Pattern ARCHIVE_FILE_PATTERN =
+      Pattern.compile("^\\.commits_\\.archive\\.([0-9]+).*");
+  private static final String STATE_TRANSITION_TIME = "stateTransitionTime";
+  private static final String ACTION_TYPE_KEY = "actionType";
+  private static final Logger LOG = 
LoggerFactory.getLogger(ArchivedTimelineLoaderV1.class);
+
+  @Override
+  public void loadInstants(HoodieTableMetaClient metaClient,
+                                          @Nullable 
HoodieArchivedTimeline.TimeRangeFilter filter,
+                                          HoodieArchivedTimeline.LoadMode 
loadMode,
+                                          Function<GenericRecord, Boolean> 
commitsFilter,
+                                          BiConsumer<String, GenericRecord> 
recordConsumer) {
+    Set<String> instantsInRange = new HashSet<>();
+    try {
+      // List all files
+      List<StoragePathInfo> entryList = metaClient.getStorage().globEntries(
+          new StoragePath(metaClient.getArchivePath() + 
"/.commits_.archive*"));
+
+      // Sort files by version suffix in reverse (implies reverse 
chronological order)
+      entryList.sort(new ArchiveFileVersionComparator());
+
+      for (StoragePathInfo fs : entryList) {
+        // Read the archived file
+        try (HoodieLogFormat.Reader reader = 
HoodieLogFormat.newReader(metaClient.getStorage(),
+            new HoodieLogFile(fs.getPath()), 
HoodieArchivedMetaEntry.getClassSchema())) {
+          int instantsInPreviousFile = instantsInRange.size();
+          // Read the avro blocks
+          while (reader.hasNext()) {
+            HoodieLogBlock block = reader.next();
+            if (block instanceof HoodieAvroDataBlock) {
+              HoodieAvroDataBlock avroBlock = (HoodieAvroDataBlock) block;
+              // TODO If we can store additional metadata in datablock, we can 
skip parsing records
+              // (such as startTime, endTime of records in the block)
+              try (ClosableIterator<HoodieRecord<IndexedRecord>> itr = 
avroBlock.getRecordIterator(HoodieRecord.HoodieRecordType.AVRO)) {
+                StreamSupport.stream(Spliterators.spliteratorUnknownSize(itr, 
Spliterator.IMMUTABLE), true)
+                    // Filter blocks in desired time window
+                    .map(r -> (GenericRecord) r.getData())
+                    .filter(commitsFilter::apply)
+                    .forEach(r -> {
+                      String instantTime = 
r.get(HoodiePartitionMetadata.COMMIT_TIME_KEY).toString();

Review Comment:
   The code was using a record key field name defined in the 
HoodiePartitionMetadata. As this is used by Archiver as well, moved it to 
HoodieTableMetaClient



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