alexeykudinkin commented on code in PR #7512: URL: https://github.com/apache/hudi/pull/7512#discussion_r1082093165
########## hudi-common/src/main/java/org/apache/parquet/avro/HoodieAvroReadSupport.java: ########## @@ -0,0 +1,133 @@ +/* + * 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.parquet.avro; + +import org.apache.avro.generic.GenericData; +import org.apache.hadoop.conf.Configuration; +import org.apache.parquet.schema.GroupType; +import org.apache.parquet.schema.MessageType; +import org.apache.parquet.schema.OriginalType; +import org.apache.parquet.schema.Type; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Support to avro-record read parquet-log which written by spark-record. + * See the examples in TestMORDataSource#testRecordTypeCompatibilityWithParquetLog. + * Exception throw when schema end with map or list. + */ +public class HoodieAvroReadSupport<T> extends AvroReadSupport<T> { + + public HoodieAvroReadSupport(GenericData model) { + super(model); + } + + public HoodieAvroReadSupport() { + } + + @Override + public ReadContext init(Configuration configuration, Map<String, String> keyValueMetaData, MessageType fileSchema) { + boolean legacyMode = checkLegacyMode(fileSchema.getFields()); + // support non-legacy list + if (!legacyMode && configuration.get(AvroWriteSupport.WRITE_OLD_LIST_STRUCTURE) == null) { + configuration.set(AvroWriteSupport.WRITE_OLD_LIST_STRUCTURE, + "false", "support reading avro from non-legacy map/list in parquet file"); + } + ReadContext readContext = super.init(configuration, keyValueMetaData, fileSchema); + MessageType requestedSchema = readContext.getRequestedSchema(); + // support non-legacy map. Convert non-legacy map to legacy map + // Because there is no AvroWriteSupport.WRITE_OLD_MAP_STRUCTURE + // according to AvroWriteSupport.WRITE_OLD_LIST_STRUCTURE + if (!legacyMode) { + requestedSchema = new MessageType(requestedSchema.getName(), convertLegacyMap(requestedSchema.getFields())); Review Comment: @wzx140 since we're force-converting the schemas, this would lead to failures when users would have files written w/ Map/List in a new format, wouldn't it? -- 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]
