hudi-agent commented on code in PR #18375:
URL: https://github.com/apache/hudi/pull/18375#discussion_r3179837309


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/config/HoodieWriteConfig.java:
##########
@@ -3756,6 +3764,40 @@ protected void setDefaults() {
       autoAdjustConfigsForConcurrencyMode(isLockProviderPropertySet);
     }
 
+    /**
+     * When the table's base file format requires SPARK record type (e.g. 
Lance) but the user
+     * has not configured a Spark-compatible record merger, inject
+     * {@link #DEFAULT_SPARK_RECORD_MERGER_CLASS} into {@link 
HoodieWriteConfig#RECORD_MERGE_IMPL_CLASSES}.
+     *
+     * <p>The injection runs for every merge mode (not just {@link 
RecordMergeMode#CUSTOM}) because
+     * the Hudi write path resolves the engine-side record type from
+     * {@code config.getRecordMerger().getRecordType()} when picking a {@code 
HoodieFileWriter}.
+     * For Lance, that resolution must yield {@code SPARK}; otherwise the 
writer falls back to
+     * the AVRO path and writes throw
+     * {@code ClassCastException: SerializableIndexedRecord cannot be cast to 
InternalRow}.
+     * On the read side, {@code COMMIT_TIME} and {@code EVENT_TIME} hardcode 
their merger
+     * instances in {@code BaseSparkInternalRowReaderContext.getRecordMerger}, 
so the value
+     * populated here is harmless for those modes and only takes effect under 
{@code CUSTOM}.
+     */
+    private void autoSelectSparkRecordMergerForBaseFileFormat() {
+      HoodieFileFormat tableLevel = 
HoodieFileFormat.getValue(writeConfig.getString(HoodieTableConfig.BASE_FILE_FORMAT.key()));

Review Comment:
   🤖 nit: `tableLevel` is a bit ambiguous here — it reads like it refers to 
some kind of tier or priority rather than "the format as configured in 
HoodieTableConfig". Could you rename it to something like `tableConfigFormat` 
or `configuredTableFormat` to make the source clear at a glance?
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
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:
   🤖 nit: the lazy init of `recordIterator` here isn't explained — could you 
add a brief comment saying why it's deferred to `next()` rather than opened in 
the constructor? Without a reason, a future reader might wonder if it was an 
oversight vs. an intentional choice (e.g. to avoid holding an open iterator 
until the task actually starts consuming).
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



-- 
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]

Reply via email to