bvaradar commented on a change in pull request #1678: URL: https://github.com/apache/hudi/pull/1678#discussion_r461755543
########## File path: hudi-client/src/main/java/org/apache/hudi/table/action/commit/MergeHelper.java ########## @@ -0,0 +1,204 @@ +/* + * 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.table.action.commit; + +import java.io.ByteArrayOutputStream; +import org.apache.avro.generic.GenericDatumReader; +import org.apache.avro.generic.GenericDatumWriter; +import org.apache.avro.io.BinaryDecoder; +import org.apache.avro.io.BinaryEncoder; +import org.apache.avro.io.DecoderFactory; +import org.apache.avro.io.EncoderFactory; +import org.apache.hadoop.fs.Path; +import org.apache.hudi.avro.HoodieAvroUtils; +import org.apache.hudi.client.utils.MergingParquetIterator; +import org.apache.hudi.client.utils.ParquetReaderIterator; +import org.apache.hudi.common.model.HoodieBaseFile; +import org.apache.hudi.common.model.HoodieRecordPayload; +import org.apache.hudi.common.util.ParquetUtils; +import org.apache.hudi.common.util.queue.BoundedInMemoryExecutor; +import org.apache.hudi.common.util.queue.BoundedInMemoryQueueConsumer; +import org.apache.hudi.exception.HoodieException; +import org.apache.hudi.execution.SparkBoundedInMemoryExecutor; +import org.apache.hudi.io.HoodieMergeHandle; +import org.apache.hudi.table.HoodieTable; +import org.apache.parquet.avro.AvroParquetReader; +import org.apache.parquet.avro.AvroReadSupport; +import org.apache.parquet.avro.AvroSchemaConverter; +import org.apache.parquet.hadoop.ParquetReader; +import org.apache.parquet.schema.MessageType; + +import org.apache.avro.Schema; +import org.apache.avro.generic.GenericRecord; +import org.apache.hadoop.conf.Configuration; + +import java.io.IOException; +import java.util.Iterator; + +/** + * Helper to read records from previous version of parquet and run Merge. + */ +public class MergeHelper { + + /** + * Read records from previous version of base file and merge. + * @param table Hoodie Table + * @param upsertHandle Merge Handle + * @param <T> + * @throws IOException in case of error + */ + public static <T extends HoodieRecordPayload<T>> void runMerge(HoodieTable<T> table, + HoodieMergeHandle<T> upsertHandle) throws IOException { + final boolean externalchemaTransformation = table.getConfig().shouldUseExternalSchemaTransformation(); + Configuration configForHudiFile = new Configuration(table.getHadoopConf()); + HoodieBaseFile baseFile = upsertHandle.getPrevBaseFile(); + + final GenericDatumWriter<GenericRecord> gWriter; + final GenericDatumReader<GenericRecord> gReader; + if (externalchemaTransformation || baseFile.getExternalBaseFile().isPresent()) { + MessageType usedParquetSchema = ParquetUtils.readSchema(table.getHadoopConf(), upsertHandle.getOldFilePath()); Review comment: For reference ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
