wombatu-kun commented on code in PR #18375: URL: https://github.com/apache/hudi/pull/18375#discussion_r3198650032
########## hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/HoodieLanceRecordReader.java: ########## @@ -0,0 +1,123 @@ +/* + * 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.hadoop; + +import org.apache.hudi.common.config.HoodieConfig; +import org.apache.hudi.common.model.HoodieFileFormat; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.schema.HoodieSchema; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.common.util.collection.ClosableIterator; +import org.apache.hudi.hadoop.fs.HadoopFSUtils; +import org.apache.hudi.hadoop.utils.HoodieRealtimeRecordReaderUtils; +import org.apache.hudi.io.storage.HoodieFileReader; +import org.apache.hudi.io.storage.HoodieIOFactory; +import org.apache.hudi.storage.HoodieStorageUtils; +import org.apache.hudi.storage.StorageConfiguration; +import org.apache.hudi.storage.StoragePath; + +import org.apache.avro.generic.IndexedRecord; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.io.ArrayWritable; +import org.apache.hadoop.io.NullWritable; +import org.apache.hadoop.io.Writable; +import org.apache.hadoop.mapred.FileSplit; +import org.apache.hadoop.mapred.InputSplit; +import org.apache.hadoop.mapred.JobConf; +import org.apache.hadoop.mapred.RecordReader; + +import java.io.IOException; + +import static org.apache.hudi.common.util.ConfigUtils.getReaderConfigs; +import static org.apache.hudi.hadoop.fs.HadoopFSUtils.convertToStoragePath; + +public class HoodieLanceRecordReader implements RecordReader<NullWritable, ArrayWritable> { + + private long count = 0; + private final ArrayWritable valueObj; + private HoodieFileReader reader; + private ClosableIterator<HoodieRecord<IndexedRecord>> recordIterator; + private final HoodieSchema schema; + + public HoodieLanceRecordReader(Configuration conf, InputSplit split, JobConf job) throws IOException { + FileSplit fileSplit = (FileSplit) split; + StoragePath path = convertToStoragePath(fileSplit.getPath()); + StorageConfiguration<?> storageConf = HadoopFSUtils.getStorageConf(conf); + HoodieConfig hoodieConfig = getReaderConfigs(storageConf); + HoodieIOFactory ioFactory = HoodieIOFactory.getIOFactory(HoodieStorageUtils.getStorage(path, storageConf)); + reader = ioFactory.getReaderFactory(HoodieRecord.HoodieRecordType.AVRO) + .getFileReader(hoodieConfig, path, HoodieFileFormat.LANCE, Option.empty()); + + schema = reader.getSchema(); + valueObj = new ArrayWritable(Writable.class, new Writable[schema.getFields().size()]); + } + + @Override + public boolean next(NullWritable key, ArrayWritable value) throws IOException { + if (recordIterator == null) { + recordIterator = reader.getRecordIterator(schema); + } Review Comment: Done in commit fd85491409dc — added a comment at the lazy-init site explaining the iterator is opened on first `next()` so the file isn't held open for splits the framework constructs but never iterates. -- 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]
