voonhous commented on code in PR #18961: URL: https://github.com/apache/hudi/pull/18961#discussion_r3472587063
########## hudi-common/src/main/java/org/apache/hudi/avro/VariantShreddingRuntime.java: ########## @@ -0,0 +1,101 @@ +/* + * 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.avro; + +import org.apache.hudi.common.util.Option; + +import lombok.extern.slf4j.Slf4j; + +/** + * Classpath detection of engine-specific variant shredding components. + * + * <p>Engine modules (currently the Spark 4.x bundles) ship implementations of + * {@link VariantShreddingProvider} and {@link VariantShreddingSchemaInferrer}; hudi-common + * discovers them by probing well-known class names so that it stays free of engine + * dependencies. Probes are memoized: classpath content does not change within a JVM.</p> + */ +@Slf4j +public final class VariantShreddingRuntime { + + /** Provider candidates, most specific first. Mirrors what each Spark bundle ships. */ + private static final String[] PROVIDER_CANDIDATES = { + "org.apache.hudi.variant.Spark4VariantShreddingProvider" + }; + + /** + * Inferrer candidates, one per Spark version module that ships one (inference exists only in + * Spark 4.1+, SPARK-53659). A new Spark version module adds its implementation here. + */ + private static final String[] INFERRER_CANDIDATES = { + "org.apache.hudi.variant.Spark41VariantShreddingSchemaInferrer" + }; + + private static final Option<String> PROVIDER_CLASS = probe(PROVIDER_CANDIDATES); + private static final Option<VariantShreddingSchemaInferrer> INFERRER = loadInferrer(); + + private VariantShreddingRuntime() { + } + + /** + * The fully-qualified name of the first {@link VariantShreddingProvider} implementation + * found on the classpath, if any. + */ + public static Option<String> detectProviderClass() { Review Comment: Good call, renamed to `getProviderClass`. It just returns the memoized `PROVIDER_CLASS` field, so the `detect` prefix was misleading. -- 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]
