danny0405 commented on code in PR #9209: URL: https://github.com/apache/hudi/pull/9209#discussion_r1287878544
########## hudi-common/src/main/java/org/apache/hudi/common/model/HoodieArchivedManifest.java: ########## @@ -0,0 +1,132 @@ +/* + * 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.model; + +import org.apache.hudi.common.util.JsonUtils; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Manifest entry for a version snapshot of the archived timeline. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class HoodieArchivedManifest implements Serializable { + private static final Logger LOG = LoggerFactory.getLogger(HoodieArchivedManifest.class); + + public static final HoodieArchivedManifest EMPTY = new HoodieArchivedManifest(); + + private final List<FileEntry> files; + + // for ser/deser + public HoodieArchivedManifest() { + this.files = new ArrayList<>(); + } + + public HoodieArchivedManifest(List<FileEntry> files) { + this.files = files; + } + + public void addFile(String fileName, long fileLen) { + this.files.add(FileEntry.getInstance(fileName, fileLen)); + } + + public void addFile(FileEntry fileEntry) { + this.files.add(fileEntry); + } + + public List<FileEntry> getFiles() { + return files; + } + + public List<String> getFileNames() { + return files.stream().map(FileEntry::getFileName).collect(Collectors.toList()); + } + + // ------------------------------------------------------------------------- + // Utilities + // ------------------------------------------------------------------------- + + public String toJsonString() throws IOException { + return JsonUtils.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this); + } + + public static <T> T fromJsonString(String jsonStr, Class<T> clazz) throws Exception { + if (jsonStr == null || jsonStr.isEmpty()) { + // For empty commit file (no data or something bad happen). + return clazz.newInstance(); + } + return JsonUtils.getObjectMapper().readValue(jsonStr, clazz); + } + + public HoodieArchivedManifest copy(List<String> filesToRemove) { + List<FileEntry> newFiles = this.files.stream().filter(fileEntry -> !filesToRemove.contains(fileEntry.getFileName())).collect(Collectors.toList()); + return new HoodieArchivedManifest(newFiles); + } + + public HoodieArchivedManifest copy() { + return new HoodieArchivedManifest(new ArrayList<>(this.files)); + } + + // ------------------------------------------------------------------------- + // Inner Class + // ------------------------------------------------------------------------- + + /** + * A file entry. + */ + public static class FileEntry implements Serializable, Comparable<FileEntry> { Review Comment: I don't see any request for that now, we can extend it easily in the future because it is a JSON. -- 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: commits-unsubscr...@hudi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org