danny0405 commented on code in PR #20085: URL: https://github.com/apache/hudi/pull/20085#discussion_r4118406077
########## hudi-common/src/main/java/org/apache/hudi/common/util/InternalSchemaHistory.java: ########## @@ -0,0 +1,339 @@ +/* + * 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.util; + +import org.apache.hudi.common.model.HoodieCommitMetadata; +import org.apache.hudi.common.schema.HoodieSchemaUtils; +import org.apache.hudi.common.schema.internal.InternalSchema; +import org.apache.hudi.common.schema.internal.convert.InternalSchemaConverter; +import org.apache.hudi.common.schema.internal.io.FileBasedInternalSchemaStorageManager; +import org.apache.hudi.common.schema.internal.utils.SerDeHelper; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.timeline.InstantFileNameParser; +import org.apache.hudi.exception.HoodieException; +import org.apache.hudi.exception.HoodieIOException; +import org.apache.hudi.storage.StoragePath; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import lombok.extern.slf4j.Slf4j; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * The schema history of a table as seen by one query, used to find the {@link InternalSchema} a data file + * was written with from the file's commit time. + * + * <p>It is loaded once where the query is planned, restricted to the query's valid commits, and shipped to + * the readers, so resolving a file's schema reads no table metadata. It resolves a version id exactly like + * {@link InternalSchemaCache#getInternalSchemaByVersionId(long, String, org.apache.hudi.storage.HoodieStorage, + * String, org.apache.hudi.common.table.timeline.TimelineLayout, org.apache.hudi.common.table.HoodieTableConfig)}: + * a valid commit resolves to the {@code latest_schema} in its own commit metadata, which is not always the history + * version in effect at its commit time (a schema change requested before the commit may complete after it). + * + * <p>It is kept as configuration entries, so it can travel inside a Hadoop configuration and a reader looks up + * only the entry it needs. + */ +@Slf4j +public final class InternalSchemaHistory implements Serializable { + + private static final long serialVersionUID = 1L; + + private static final String CONFIG_PREFIX = "hoodie.internal.schema.history."; + // comma-separated version ids of the schema history + private static final String VERSIONS_KEY = CONFIG_PREFIX + "versions"; + private static final String VERSION_KEY_PREFIX = CONFIG_PREFIX + "version."; + // comma-separated "<commit time>=<version id>" for commits whose schema is a history version, + // and "<commit time>=#<n>" for commits whose schema is kept under SCHEMA_KEY_PREFIX + n + private static final String COMMITS_KEY = CONFIG_PREFIX + "commits"; + // schemas of commits that are not history versions, each distinct schema kept once + private static final String SCHEMA_KEY_PREFIX = CONFIG_PREFIX + "schema."; + private static final char SCHEMA_REF_MARKER = '#'; + + private static final int MAX_COMMIT_READ_PARALLELISM = 16; + + // Completed commit files never change, so what each one says about its schema is kept across queries. + private static final Cache<String, CommitSchema> COMMIT_SCHEMA_CACHE = Caffeine.newBuilder() + .maximumWeight(16L * 1024 * 1024) + .weigher((String commitFile, CommitSchema commitSchema) -> commitFile.length() + Math.max(1, commitSchema.weight)) + .build(); + + private final Map<String, String> configs; Review Comment: can we make the class as POJO instead of maintaining these properties as a map, that would make it more clear and straight-forward. -- 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]
