the-other-tim-brown commented on code in PR #14265: URL: https://github.com/apache/hudi/pull/14265#discussion_r2548018818
########## hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchemaCompatibility.java: ########## @@ -0,0 +1,206 @@ +/* + * 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.schema; + +import org.apache.hudi.avro.AvroSchemaUtils; +import org.apache.hudi.common.util.ValidationUtils; + +import java.util.Collections; +import java.util.Set; + +/** + * Utility class for checking HoodieSchema compatibility and evolution rules. + * This provides HoodieSchema-native methods that delegate to existing AvroSchemaUtils + * functionality while maintaining the architectural separation. + * + * <p>This class handles schema compatibility checking, which is crucial for: + * <ul> + * <li>Table schema evolution validation</li> + * <li>Writer schema compatibility with table schema</li> + * <li>Projection compatibility for query optimization</li> + * <li>Metadata field handling during schema checks</li> + * </ul> + */ +public final class HoodieSchemaCompatibility { + + // Prevent instantiation + private HoodieSchemaCompatibility() { + } + + /** + * Checks if writer schema is compatible with table schema for write operations. + * This is equivalent to AvroSchemaUtils.checkSchemaCompatible() but operates on HoodieSchemas. + * + * @param tableSchema the table schema to check against + * @param writerSchema the writer schema to validate + * @param shouldValidate whether to perform compatibility validation + * @param allowProjection whether to allow projection (fewer fields in writer) + * @throws IllegalArgumentException if schemas are null + * @throws org.apache.hudi.exception.SchemaCompatibilityException if schemas are incompatible + */ + public static void checkSchemaCompatible(HoodieSchema tableSchema, HoodieSchema writerSchema, + boolean shouldValidate, boolean allowProjection) { + ValidationUtils.checkArgument(tableSchema != null, "Table schema cannot be null"); + ValidationUtils.checkArgument(writerSchema != null, "Writer schema cannot be null"); + + // Delegate to AvroSchemaUtils for the actual compatibility check + AvroSchemaUtils.checkSchemaCompatible( + tableSchema.toAvroSchema(), + writerSchema.toAvroSchema(), + shouldValidate, + allowProjection, + Collections.emptySet()); // Default to no partition columns Review Comment: Makes sense, it is updated in the latest commit. -- 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]
