alexeykudinkin commented on code in PR #6358: URL: https://github.com/apache/hudi/pull/6358#discussion_r990596435
########## hudi-common/src/main/java/org/apache/hudi/avro/AvroSchemaCompatibility.java: ########## @@ -0,0 +1,941 @@ +/* + * 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.avro.AvroRuntimeException; +import org.apache.avro.Schema; +import org.apache.avro.Schema.Field; +import org.apache.avro.Schema.Type; +import org.apache.hudi.common.util.Either; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import static org.apache.hudi.common.util.ValidationUtils.checkState; + +/** + * Evaluate the compatibility between a reader schema and a writer schema. A + * reader and a writer schema are declared compatible if all datum instances of + * the writer schema can be successfully decoded using the specified reader + * schema. + * + * NOTE: PLEASE READ CAREFULLY BEFORE CHANGING + * + * This code is borrowed from Avro 1.10, with the following modifications: + * <ol> + * <li>Compatibility checks ignore schema name, unless schema is held inside + * a union</li> + * </ol> + * + */ +public class AvroSchemaCompatibility { Review Comment: Context: Avro requires at all times that schema's names have to match in order for them to be counted as compatible. Provided that only Avro bears the names on the schemas themselves (Spark does not, for ex) this makes for ex, some schemas converted from Spark's [[StructType]] incompatible w/ Avro This code is mostly borrowed as is from Avro 1.10 w/ the following critical adjustments: 1. Schema names now are only checked in following 2 cases: 1.a In case it's a top-level schema 1.b In case schema is enclosed into a union (in which case its name might be used for reverse-lookup) 2. Default value access is adapted to work for both Avro 1.8.x as well as 1.10.x -- 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]
