nsivabalan commented on code in PR #12340:
URL: https://github.com/apache/hudi/pull/12340#discussion_r2001378215


##########
hudi-client/hudi-spark-client/src/main/scala/org/apache/hudi/SparkFileFormatInternalRowReaderContext.scala:
##########
@@ -165,7 +165,7 @@ class 
SparkFileFormatInternalRowReaderContext(parquetFileReader: SparkParquetRea
         HoodieAvroUtils.removeFields(skeletonRequiredSchema, rowIndexColumn))
 
       //If we need to do position based merging with log files we will leave 
the row index column at the end
-      val dataProjection = if (getHasLogFiles && 
getShouldMergeUseRecordPosition) {
+      val dataProjection = if (getShouldMergeUseRecordPosition) {

Review Comment:
   why removed the log files check? 



##########
hudi-common/src/test/java/org/apache/hudi/common/table/read/TestSchemaHandler.java:
##########
@@ -0,0 +1,464 @@
+/*
+ * 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.common.table.read;
+
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.common.config.RecordMergeMode;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.engine.HoodieReaderContext;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordMerger;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.testutils.HoodieTestDataGenerator;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StoragePath;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.IndexedRecord;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.UnaryOperator;
+import java.util.stream.Stream;
+
+import static 
org.apache.hudi.common.config.RecordMergeMode.COMMIT_TIME_ORDERING;
+import static org.apache.hudi.common.config.RecordMergeMode.CUSTOM;
+import static 
org.apache.hudi.common.config.RecordMergeMode.EVENT_TIME_ORDERING;
+import static 
org.apache.hudi.common.table.read.HoodiePositionBasedSchemaHandler.addPositionalMergeCol;
+import static 
org.apache.hudi.common.table.read.HoodiePositionBasedSchemaHandler.getPositionalMergeField;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class TestSchemaHandler {
+
+  protected static final Schema DATA_SCHEMA = 
HoodieAvroUtils.addMetadataFields(HoodieTestDataGenerator.AVRO_SCHEMA);
+  protected static final Schema DATA_COLS_ONLY_SCHEMA = 
generateProjectionSchema("begin_lat", "tip_history", "rider");
+  protected static final Schema META_COLS_ONLY_SCHEMA = 
generateProjectionSchema("_hoodie_commit_seqno", "_hoodie_record_key");
+
+  @Test
+  public void testCow() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(false);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(false);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = DATA_SCHEMA;
+    HoodieFileGroupReaderSchemaHandler schemaHandler = new 
HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA,
+        requestedSchema, Option.empty(), hoodieTableConfig, new 
TypedProperties());
+    assertEquals(requestedSchema, schemaHandler.getRequiredSchema());
+
+    //read subset of columns
+    requestedSchema = generateProjectionSchema("begin_lat", "tip_history", 
"rider");
+    schemaHandler =
+        new HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    assertEquals(requestedSchema, schemaHandler.getRequiredSchema());
+  }
+
+  @Test
+  public void testCowBootstrap() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(false);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(true);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = generateProjectionSchema("begin_lat", 
"tip_history", "_hoodie_record_key", "rider");
+    HoodieFileGroupReaderSchemaHandler schemaHandler =
+        new HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    //meta cols must go first in the required schema
+    Schema expectedRequiredSchema = 
generateProjectionSchema("_hoodie_record_key", "begin_lat", "tip_history", 
"rider");
+    assertEquals(expectedRequiredSchema, schemaHandler.getRequiredSchema());
+    Pair<List<Schema.Field>, List<Schema.Field>> bootstrapFields = 
schemaHandler.getBootstrapRequiredFields();
+    assertEquals(Collections.singletonList(getField("_hoodie_record_key")), 
bootstrapFields.getLeft());
+    assertEquals(Arrays.asList(getField("begin_lat"), getField("tip_history"), 
getField("rider")), bootstrapFields.getRight());
+  }
+
+  @Test
+  public void testCowBootstrapWithPositionMerge() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(true);

Review Comment:
   I see lot of code duplications across. atleast all 3 COW related tests, we 
can dedup. 
   



##########
hudi-common/src/test/java/org/apache/hudi/common/table/read/TestSchemaHandler.java:
##########
@@ -0,0 +1,464 @@
+/*
+ * 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.common.table.read;
+
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.common.config.RecordMergeMode;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.engine.HoodieReaderContext;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordMerger;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.testutils.HoodieTestDataGenerator;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StoragePath;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.IndexedRecord;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.UnaryOperator;
+import java.util.stream.Stream;
+
+import static 
org.apache.hudi.common.config.RecordMergeMode.COMMIT_TIME_ORDERING;
+import static org.apache.hudi.common.config.RecordMergeMode.CUSTOM;
+import static 
org.apache.hudi.common.config.RecordMergeMode.EVENT_TIME_ORDERING;
+import static 
org.apache.hudi.common.table.read.HoodiePositionBasedSchemaHandler.addPositionalMergeCol;
+import static 
org.apache.hudi.common.table.read.HoodiePositionBasedSchemaHandler.getPositionalMergeField;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class TestSchemaHandler {
+
+  protected static final Schema DATA_SCHEMA = 
HoodieAvroUtils.addMetadataFields(HoodieTestDataGenerator.AVRO_SCHEMA);
+  protected static final Schema DATA_COLS_ONLY_SCHEMA = 
generateProjectionSchema("begin_lat", "tip_history", "rider");
+  protected static final Schema META_COLS_ONLY_SCHEMA = 
generateProjectionSchema("_hoodie_commit_seqno", "_hoodie_record_key");
+
+  @Test
+  public void testCow() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(false);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(false);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = DATA_SCHEMA;
+    HoodieFileGroupReaderSchemaHandler schemaHandler = new 
HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA,
+        requestedSchema, Option.empty(), hoodieTableConfig, new 
TypedProperties());
+    assertEquals(requestedSchema, schemaHandler.getRequiredSchema());
+
+    //read subset of columns
+    requestedSchema = generateProjectionSchema("begin_lat", "tip_history", 
"rider");
+    schemaHandler =
+        new HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    assertEquals(requestedSchema, schemaHandler.getRequiredSchema());
+  }
+
+  @Test
+  public void testCowBootstrap() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(false);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(true);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = generateProjectionSchema("begin_lat", 
"tip_history", "_hoodie_record_key", "rider");
+    HoodieFileGroupReaderSchemaHandler schemaHandler =
+        new HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    //meta cols must go first in the required schema
+    Schema expectedRequiredSchema = 
generateProjectionSchema("_hoodie_record_key", "begin_lat", "tip_history", 
"rider");
+    assertEquals(expectedRequiredSchema, schemaHandler.getRequiredSchema());
+    Pair<List<Schema.Field>, List<Schema.Field>> bootstrapFields = 
schemaHandler.getBootstrapRequiredFields();
+    assertEquals(Collections.singletonList(getField("_hoodie_record_key")), 
bootstrapFields.getLeft());
+    assertEquals(Arrays.asList(getField("begin_lat"), getField("tip_history"), 
getField("rider")), bootstrapFields.getRight());
+  }
+
+  @Test
+  public void testCowBootstrapWithPositionMerge() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(true);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(true);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = generateProjectionSchema("begin_lat", 
"tip_history", "_hoodie_record_key", "rider");
+    HoodieFileGroupReaderSchemaHandler schemaHandler =
+        new HoodiePositionBasedSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    //meta cols must go first in the required schema
+    Schema expectedRequiredSchema = 
generateProjectionSchema("_hoodie_record_key", "begin_lat", "tip_history", 
"rider");
+    assertEquals(expectedRequiredSchema, schemaHandler.getRequiredSchema());
+    Pair<List<Schema.Field>, List<Schema.Field>> bootstrapFields = 
schemaHandler.getBootstrapRequiredFields();
+    assertEquals(Arrays.asList(getField("_hoodie_record_key"), 
getPositionalMergeField()), bootstrapFields.getLeft());
+    assertEquals(Arrays.asList(getField("begin_lat"), getField("tip_history"), 
getField("rider"), getPositionalMergeField()), bootstrapFields.getRight());
+
+    schemaHandler = new HoodiePositionBasedSchemaHandler(readerContext, 
DATA_SCHEMA, DATA_COLS_ONLY_SCHEMA,
+        Option.empty(), hoodieTableConfig, new TypedProperties());
+    assertEquals(DATA_COLS_ONLY_SCHEMA, schemaHandler.getRequiredSchema());
+    bootstrapFields = schemaHandler.getBootstrapRequiredFields();
+    assertTrue(bootstrapFields.getLeft().isEmpty());
+    assertEquals(Arrays.asList(getField("begin_lat"), getField("tip_history"), 
getField("rider")), bootstrapFields.getRight());
+
+    schemaHandler = new HoodiePositionBasedSchemaHandler(readerContext, 
DATA_SCHEMA, META_COLS_ONLY_SCHEMA,
+        Option.empty(), hoodieTableConfig, new TypedProperties());
+    assertEquals(META_COLS_ONLY_SCHEMA, schemaHandler.getRequiredSchema());
+    bootstrapFields = schemaHandler.getBootstrapRequiredFields();
+    assertEquals(Arrays.asList(getField("_hoodie_commit_seqno"), 
getField("_hoodie_record_key")), bootstrapFields.getLeft());
+    assertTrue(bootstrapFields.getRight().isEmpty());
+  }
+
+  private static Stream<Arguments> testMorParams() {
+    Stream.Builder<Arguments> b = Stream.builder();
+    for (boolean mergeUseRecordPosition : new boolean[] {true, false}) {
+      for (boolean supportsParquetRowIndex : new boolean[] {true, false}) {
+        b.add(Arguments.of(EVENT_TIME_ORDERING, true, false, 
mergeUseRecordPosition, supportsParquetRowIndex));
+        b.add(Arguments.of(EVENT_TIME_ORDERING, false, false, 
mergeUseRecordPosition, supportsParquetRowIndex));
+        b.add(Arguments.of(COMMIT_TIME_ORDERING, false, false, 
mergeUseRecordPosition, supportsParquetRowIndex));
+        b.add(Arguments.of(CUSTOM, false, true, mergeUseRecordPosition, 
supportsParquetRowIndex));
+        b.add(Arguments.of(CUSTOM, false, false, mergeUseRecordPosition, 
supportsParquetRowIndex));
+      }
+    }
+    return b.build();
+  }
+
+  @ParameterizedTest
+  @MethodSource("testMorParams")
+  public void testMor(RecordMergeMode mergeMode,
+                      boolean hasPrecombine,
+                      boolean isProjectionCompatible,
+                      boolean mergeUseRecordPosition,
+                      boolean supportsParquetRowIndex) {
+    HoodieReaderContext<String> readerContext = new 
MockReaderContext(supportsParquetRowIndex);
+    readerContext.setHasLogFiles(true);

Review Comment:
   can we add a test for hasLogFiles = false. i.e. representing a compacted 
file group. 
   we should not be projecting the additional cols that we usually do when we 
have log files. 
   



##########
hudi-common/src/main/java/org/apache/hudi/common/table/read/HoodiePositionBasedSchemaHandler.java:
##########
@@ -50,10 +51,18 @@ public 
HoodiePositionBasedSchemaHandler(HoodieReaderContext<T> readerContext,
     super(readerContext, dataSchema, requestedSchema, internalSchemaOpt, 
hoodieTableConfig, properties);
   }
 
+  private boolean morMergeNeedsPositionCol() {
+    return readerContext.supportsParquetRowIndex() && 
readerContext.getShouldMergeUseRecordPosition();
+  }
+
+  private boolean bootstrapMergeNeedsPositionCol() {

Review Comment:
   I don't have good context on bootstrap flows. Will let @yihua review/skim 
them



##########
hudi-common/src/main/java/org/apache/hudi/common/table/read/HoodiePositionBasedSchemaHandler.java:
##########
@@ -50,10 +51,18 @@ public 
HoodiePositionBasedSchemaHandler(HoodieReaderContext<T> readerContext,
     super(readerContext, dataSchema, requestedSchema, internalSchemaOpt, 
hoodieTableConfig, properties);
   }
 
+  private boolean morMergeNeedsPositionCol() {

Review Comment:
   infact L 56 we are checking for log files prior to this patch. and w/ this 
patch we are calling morMergeNeedsPositionCol which is not checking for log 
files. 
   



##########
hudi-common/src/test/java/org/apache/hudi/common/table/read/TestSchemaHandler.java:
##########
@@ -0,0 +1,464 @@
+/*
+ * 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.common.table.read;
+
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.common.config.RecordMergeMode;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.engine.HoodieReaderContext;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordMerger;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.testutils.HoodieTestDataGenerator;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StoragePath;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.IndexedRecord;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.UnaryOperator;
+import java.util.stream.Stream;
+
+import static 
org.apache.hudi.common.config.RecordMergeMode.COMMIT_TIME_ORDERING;
+import static org.apache.hudi.common.config.RecordMergeMode.CUSTOM;
+import static 
org.apache.hudi.common.config.RecordMergeMode.EVENT_TIME_ORDERING;
+import static 
org.apache.hudi.common.table.read.HoodiePositionBasedSchemaHandler.addPositionalMergeCol;
+import static 
org.apache.hudi.common.table.read.HoodiePositionBasedSchemaHandler.getPositionalMergeField;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class TestSchemaHandler {
+
+  protected static final Schema DATA_SCHEMA = 
HoodieAvroUtils.addMetadataFields(HoodieTestDataGenerator.AVRO_SCHEMA);
+  protected static final Schema DATA_COLS_ONLY_SCHEMA = 
generateProjectionSchema("begin_lat", "tip_history", "rider");
+  protected static final Schema META_COLS_ONLY_SCHEMA = 
generateProjectionSchema("_hoodie_commit_seqno", "_hoodie_record_key");
+
+  @Test
+  public void testCow() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(false);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(false);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = DATA_SCHEMA;
+    HoodieFileGroupReaderSchemaHandler schemaHandler = new 
HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA,
+        requestedSchema, Option.empty(), hoodieTableConfig, new 
TypedProperties());
+    assertEquals(requestedSchema, schemaHandler.getRequiredSchema());
+
+    //read subset of columns
+    requestedSchema = generateProjectionSchema("begin_lat", "tip_history", 
"rider");
+    schemaHandler =
+        new HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    assertEquals(requestedSchema, schemaHandler.getRequiredSchema());
+  }
+
+  @Test
+  public void testCowBootstrap() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(false);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(true);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = generateProjectionSchema("begin_lat", 
"tip_history", "_hoodie_record_key", "rider");
+    HoodieFileGroupReaderSchemaHandler schemaHandler =
+        new HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    //meta cols must go first in the required schema
+    Schema expectedRequiredSchema = 
generateProjectionSchema("_hoodie_record_key", "begin_lat", "tip_history", 
"rider");
+    assertEquals(expectedRequiredSchema, schemaHandler.getRequiredSchema());
+    Pair<List<Schema.Field>, List<Schema.Field>> bootstrapFields = 
schemaHandler.getBootstrapRequiredFields();
+    assertEquals(Collections.singletonList(getField("_hoodie_record_key")), 
bootstrapFields.getLeft());
+    assertEquals(Arrays.asList(getField("begin_lat"), getField("tip_history"), 
getField("rider")), bootstrapFields.getRight());
+  }
+
+  @Test
+  public void testCowBootstrapWithPositionMerge() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(true);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(true);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = generateProjectionSchema("begin_lat", 
"tip_history", "_hoodie_record_key", "rider");
+    HoodieFileGroupReaderSchemaHandler schemaHandler =
+        new HoodiePositionBasedSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    //meta cols must go first in the required schema
+    Schema expectedRequiredSchema = 
generateProjectionSchema("_hoodie_record_key", "begin_lat", "tip_history", 
"rider");
+    assertEquals(expectedRequiredSchema, schemaHandler.getRequiredSchema());
+    Pair<List<Schema.Field>, List<Schema.Field>> bootstrapFields = 
schemaHandler.getBootstrapRequiredFields();
+    assertEquals(Arrays.asList(getField("_hoodie_record_key"), 
getPositionalMergeField()), bootstrapFields.getLeft());
+    assertEquals(Arrays.asList(getField("begin_lat"), getField("tip_history"), 
getField("rider"), getPositionalMergeField()), bootstrapFields.getRight());
+
+    schemaHandler = new HoodiePositionBasedSchemaHandler(readerContext, 
DATA_SCHEMA, DATA_COLS_ONLY_SCHEMA,
+        Option.empty(), hoodieTableConfig, new TypedProperties());
+    assertEquals(DATA_COLS_ONLY_SCHEMA, schemaHandler.getRequiredSchema());
+    bootstrapFields = schemaHandler.getBootstrapRequiredFields();
+    assertTrue(bootstrapFields.getLeft().isEmpty());
+    assertEquals(Arrays.asList(getField("begin_lat"), getField("tip_history"), 
getField("rider")), bootstrapFields.getRight());
+
+    schemaHandler = new HoodiePositionBasedSchemaHandler(readerContext, 
DATA_SCHEMA, META_COLS_ONLY_SCHEMA,
+        Option.empty(), hoodieTableConfig, new TypedProperties());
+    assertEquals(META_COLS_ONLY_SCHEMA, schemaHandler.getRequiredSchema());
+    bootstrapFields = schemaHandler.getBootstrapRequiredFields();
+    assertEquals(Arrays.asList(getField("_hoodie_commit_seqno"), 
getField("_hoodie_record_key")), bootstrapFields.getLeft());
+    assertTrue(bootstrapFields.getRight().isEmpty());
+  }
+
+  private static Stream<Arguments> testMorParams() {
+    Stream.Builder<Arguments> b = Stream.builder();
+    for (boolean mergeUseRecordPosition : new boolean[] {true, false}) {
+      for (boolean supportsParquetRowIndex : new boolean[] {true, false}) {
+        b.add(Arguments.of(EVENT_TIME_ORDERING, true, false, 
mergeUseRecordPosition, supportsParquetRowIndex));
+        b.add(Arguments.of(EVENT_TIME_ORDERING, false, false, 
mergeUseRecordPosition, supportsParquetRowIndex));
+        b.add(Arguments.of(COMMIT_TIME_ORDERING, false, false, 
mergeUseRecordPosition, supportsParquetRowIndex));
+        b.add(Arguments.of(CUSTOM, false, true, mergeUseRecordPosition, 
supportsParquetRowIndex));
+        b.add(Arguments.of(CUSTOM, false, false, mergeUseRecordPosition, 
supportsParquetRowIndex));
+      }
+    }
+    return b.build();
+  }
+
+  @ParameterizedTest
+  @MethodSource("testMorParams")
+  public void testMor(RecordMergeMode mergeMode,
+                      boolean hasPrecombine,
+                      boolean isProjectionCompatible,
+                      boolean mergeUseRecordPosition,
+                      boolean supportsParquetRowIndex) {
+    HoodieReaderContext<String> readerContext = new 
MockReaderContext(supportsParquetRowIndex);
+    readerContext.setHasLogFiles(true);

Review Comment:
   recently we landed a fix to account for "_hoodie_is_deleted" with 
https://github.com/apache/hudi/pull/12970 
   may be we can consolidate those tests here as well. 



##########
hudi-common/src/main/java/org/apache/hudi/common/table/read/HoodiePositionBasedSchemaHandler.java:
##########
@@ -50,10 +51,18 @@ public 
HoodiePositionBasedSchemaHandler(HoodieReaderContext<T> readerContext,
     super(readerContext, dataSchema, requestedSchema, internalSchemaOpt, 
hoodieTableConfig, properties);
   }
 
+  private boolean morMergeNeedsPositionCol() {

Review Comment:
   why naming this as MOR? the two conditions we check are not strictly 
confined to MOR tables right?
   ```
   readerContext.supportsParquetRowIndex() && 
readerContext.getShouldMergeUseRecordPosition()
   ```
   
   or if we can include hasLogFiles, may be it might make sense. 
   
   
   



##########
hudi-common/src/test/java/org/apache/hudi/common/table/read/TestSchemaHandler.java:
##########
@@ -0,0 +1,464 @@
+/*
+ * 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.common.table.read;
+
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.common.config.RecordMergeMode;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.engine.HoodieReaderContext;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordMerger;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.testutils.HoodieTestDataGenerator;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StoragePath;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.IndexedRecord;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.UnaryOperator;
+import java.util.stream.Stream;
+
+import static 
org.apache.hudi.common.config.RecordMergeMode.COMMIT_TIME_ORDERING;
+import static org.apache.hudi.common.config.RecordMergeMode.CUSTOM;
+import static 
org.apache.hudi.common.config.RecordMergeMode.EVENT_TIME_ORDERING;
+import static 
org.apache.hudi.common.table.read.HoodiePositionBasedSchemaHandler.addPositionalMergeCol;
+import static 
org.apache.hudi.common.table.read.HoodiePositionBasedSchemaHandler.getPositionalMergeField;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class TestSchemaHandler {
+
+  protected static final Schema DATA_SCHEMA = 
HoodieAvroUtils.addMetadataFields(HoodieTestDataGenerator.AVRO_SCHEMA);
+  protected static final Schema DATA_COLS_ONLY_SCHEMA = 
generateProjectionSchema("begin_lat", "tip_history", "rider");
+  protected static final Schema META_COLS_ONLY_SCHEMA = 
generateProjectionSchema("_hoodie_commit_seqno", "_hoodie_record_key");
+
+  @Test
+  public void testCow() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(false);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(false);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = DATA_SCHEMA;
+    HoodieFileGroupReaderSchemaHandler schemaHandler = new 
HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA,
+        requestedSchema, Option.empty(), hoodieTableConfig, new 
TypedProperties());
+    assertEquals(requestedSchema, schemaHandler.getRequiredSchema());
+
+    //read subset of columns
+    requestedSchema = generateProjectionSchema("begin_lat", "tip_history", 
"rider");
+    schemaHandler =
+        new HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    assertEquals(requestedSchema, schemaHandler.getRequiredSchema());
+  }
+
+  @Test
+  public void testCowBootstrap() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(false);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(true);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = generateProjectionSchema("begin_lat", 
"tip_history", "_hoodie_record_key", "rider");
+    HoodieFileGroupReaderSchemaHandler schemaHandler =
+        new HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    //meta cols must go first in the required schema
+    Schema expectedRequiredSchema = 
generateProjectionSchema("_hoodie_record_key", "begin_lat", "tip_history", 
"rider");
+    assertEquals(expectedRequiredSchema, schemaHandler.getRequiredSchema());
+    Pair<List<Schema.Field>, List<Schema.Field>> bootstrapFields = 
schemaHandler.getBootstrapRequiredFields();
+    assertEquals(Collections.singletonList(getField("_hoodie_record_key")), 
bootstrapFields.getLeft());
+    assertEquals(Arrays.asList(getField("begin_lat"), getField("tip_history"), 
getField("rider")), bootstrapFields.getRight());
+  }
+
+  @Test
+  public void testCowBootstrapWithPositionMerge() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(true);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(true);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = generateProjectionSchema("begin_lat", 
"tip_history", "_hoodie_record_key", "rider");
+    HoodieFileGroupReaderSchemaHandler schemaHandler =
+        new HoodiePositionBasedSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    //meta cols must go first in the required schema
+    Schema expectedRequiredSchema = 
generateProjectionSchema("_hoodie_record_key", "begin_lat", "tip_history", 
"rider");
+    assertEquals(expectedRequiredSchema, schemaHandler.getRequiredSchema());
+    Pair<List<Schema.Field>, List<Schema.Field>> bootstrapFields = 
schemaHandler.getBootstrapRequiredFields();
+    assertEquals(Arrays.asList(getField("_hoodie_record_key"), 
getPositionalMergeField()), bootstrapFields.getLeft());
+    assertEquals(Arrays.asList(getField("begin_lat"), getField("tip_history"), 
getField("rider"), getPositionalMergeField()), bootstrapFields.getRight());
+
+    schemaHandler = new HoodiePositionBasedSchemaHandler(readerContext, 
DATA_SCHEMA, DATA_COLS_ONLY_SCHEMA,
+        Option.empty(), hoodieTableConfig, new TypedProperties());
+    assertEquals(DATA_COLS_ONLY_SCHEMA, schemaHandler.getRequiredSchema());
+    bootstrapFields = schemaHandler.getBootstrapRequiredFields();
+    assertTrue(bootstrapFields.getLeft().isEmpty());
+    assertEquals(Arrays.asList(getField("begin_lat"), getField("tip_history"), 
getField("rider")), bootstrapFields.getRight());
+
+    schemaHandler = new HoodiePositionBasedSchemaHandler(readerContext, 
DATA_SCHEMA, META_COLS_ONLY_SCHEMA,
+        Option.empty(), hoodieTableConfig, new TypedProperties());
+    assertEquals(META_COLS_ONLY_SCHEMA, schemaHandler.getRequiredSchema());
+    bootstrapFields = schemaHandler.getBootstrapRequiredFields();
+    assertEquals(Arrays.asList(getField("_hoodie_commit_seqno"), 
getField("_hoodie_record_key")), bootstrapFields.getLeft());
+    assertTrue(bootstrapFields.getRight().isEmpty());
+  }
+
+  private static Stream<Arguments> testMorParams() {
+    Stream.Builder<Arguments> b = Stream.builder();
+    for (boolean mergeUseRecordPosition : new boolean[] {true, false}) {
+      for (boolean supportsParquetRowIndex : new boolean[] {true, false}) {
+        b.add(Arguments.of(EVENT_TIME_ORDERING, true, false, 
mergeUseRecordPosition, supportsParquetRowIndex));
+        b.add(Arguments.of(EVENT_TIME_ORDERING, false, false, 
mergeUseRecordPosition, supportsParquetRowIndex));
+        b.add(Arguments.of(COMMIT_TIME_ORDERING, false, false, 
mergeUseRecordPosition, supportsParquetRowIndex));
+        b.add(Arguments.of(CUSTOM, false, true, mergeUseRecordPosition, 
supportsParquetRowIndex));
+        b.add(Arguments.of(CUSTOM, false, false, mergeUseRecordPosition, 
supportsParquetRowIndex));
+      }
+    }
+    return b.build();
+  }
+
+  @ParameterizedTest
+  @MethodSource("testMorParams")
+  public void testMor(RecordMergeMode mergeMode,
+                      boolean hasPrecombine,
+                      boolean isProjectionCompatible,
+                      boolean mergeUseRecordPosition,
+                      boolean supportsParquetRowIndex) {
+    HoodieReaderContext<String> readerContext = new 
MockReaderContext(supportsParquetRowIndex);
+    readerContext.setHasLogFiles(true);
+    readerContext.setHasBootstrapBaseFile(false);
+    //has no effect on schema unless we support position based merging
+    readerContext.setShouldMergeUseRecordPosition(mergeUseRecordPosition);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    when(hoodieTableConfig.populateMetaFields()).thenReturn(Boolean.TRUE);
+    when(hoodieTableConfig.getRecordMergeMode()).thenReturn(mergeMode);
+    if (hasPrecombine) {
+      when(hoodieTableConfig.getPreCombineField()).thenReturn("timestamp");
+    } else {
+      when(hoodieTableConfig.getPreCombineField()).thenReturn(null);
+    }
+    if (mergeMode == CUSTOM) {
+      Option<HoodieRecordMerger> merger = Option.of(new 
MockMerger(isProjectionCompatible, new String[]{"begin_lat", "begin_lon", 
"_hoodie_record_key", "timestamp"}));

Review Comment:
   minor. can we add java docs to HoodieRecordMerger.isProjectionCompatible 
   
   that its only applicable for CUSTOM Merger. for commit itme ordering and 
event time ordering, this api is not used only. It was not apparent. 
   



##########
hudi-common/src/test/java/org/apache/hudi/common/table/read/TestSchemaHandler.java:
##########
@@ -0,0 +1,464 @@
+/*
+ * 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.common.table.read;
+
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.common.config.RecordMergeMode;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.engine.HoodieReaderContext;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordMerger;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.testutils.HoodieTestDataGenerator;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StoragePath;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.IndexedRecord;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.UnaryOperator;
+import java.util.stream.Stream;
+
+import static 
org.apache.hudi.common.config.RecordMergeMode.COMMIT_TIME_ORDERING;
+import static org.apache.hudi.common.config.RecordMergeMode.CUSTOM;
+import static 
org.apache.hudi.common.config.RecordMergeMode.EVENT_TIME_ORDERING;
+import static 
org.apache.hudi.common.table.read.HoodiePositionBasedSchemaHandler.addPositionalMergeCol;
+import static 
org.apache.hudi.common.table.read.HoodiePositionBasedSchemaHandler.getPositionalMergeField;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class TestSchemaHandler {
+
+  protected static final Schema DATA_SCHEMA = 
HoodieAvroUtils.addMetadataFields(HoodieTestDataGenerator.AVRO_SCHEMA);
+  protected static final Schema DATA_COLS_ONLY_SCHEMA = 
generateProjectionSchema("begin_lat", "tip_history", "rider");
+  protected static final Schema META_COLS_ONLY_SCHEMA = 
generateProjectionSchema("_hoodie_commit_seqno", "_hoodie_record_key");
+
+  @Test
+  public void testCow() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(false);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(false);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = DATA_SCHEMA;
+    HoodieFileGroupReaderSchemaHandler schemaHandler = new 
HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA,
+        requestedSchema, Option.empty(), hoodieTableConfig, new 
TypedProperties());
+    assertEquals(requestedSchema, schemaHandler.getRequiredSchema());
+
+    //read subset of columns
+    requestedSchema = generateProjectionSchema("begin_lat", "tip_history", 
"rider");
+    schemaHandler =
+        new HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    assertEquals(requestedSchema, schemaHandler.getRequiredSchema());
+  }
+
+  @Test
+  public void testCowBootstrap() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(false);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(true);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = generateProjectionSchema("begin_lat", 
"tip_history", "_hoodie_record_key", "rider");
+    HoodieFileGroupReaderSchemaHandler schemaHandler =
+        new HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    //meta cols must go first in the required schema
+    Schema expectedRequiredSchema = 
generateProjectionSchema("_hoodie_record_key", "begin_lat", "tip_history", 
"rider");
+    assertEquals(expectedRequiredSchema, schemaHandler.getRequiredSchema());
+    Pair<List<Schema.Field>, List<Schema.Field>> bootstrapFields = 
schemaHandler.getBootstrapRequiredFields();
+    assertEquals(Collections.singletonList(getField("_hoodie_record_key")), 
bootstrapFields.getLeft());
+    assertEquals(Arrays.asList(getField("begin_lat"), getField("tip_history"), 
getField("rider")), bootstrapFields.getRight());
+  }
+
+  @Test
+  public void testCowBootstrapWithPositionMerge() {
+    HoodieReaderContext<String> readerContext = new MockReaderContext(true);
+    readerContext.setHasLogFiles(false);
+    readerContext.setHasBootstrapBaseFile(true);
+    readerContext.setShouldMergeUseRecordPosition(false);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    Schema requestedSchema = generateProjectionSchema("begin_lat", 
"tip_history", "_hoodie_record_key", "rider");
+    HoodieFileGroupReaderSchemaHandler schemaHandler =
+        new HoodiePositionBasedSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+            Option.empty(), hoodieTableConfig, new TypedProperties());
+    //meta cols must go first in the required schema
+    Schema expectedRequiredSchema = 
generateProjectionSchema("_hoodie_record_key", "begin_lat", "tip_history", 
"rider");
+    assertEquals(expectedRequiredSchema, schemaHandler.getRequiredSchema());
+    Pair<List<Schema.Field>, List<Schema.Field>> bootstrapFields = 
schemaHandler.getBootstrapRequiredFields();
+    assertEquals(Arrays.asList(getField("_hoodie_record_key"), 
getPositionalMergeField()), bootstrapFields.getLeft());
+    assertEquals(Arrays.asList(getField("begin_lat"), getField("tip_history"), 
getField("rider"), getPositionalMergeField()), bootstrapFields.getRight());
+
+    schemaHandler = new HoodiePositionBasedSchemaHandler(readerContext, 
DATA_SCHEMA, DATA_COLS_ONLY_SCHEMA,
+        Option.empty(), hoodieTableConfig, new TypedProperties());
+    assertEquals(DATA_COLS_ONLY_SCHEMA, schemaHandler.getRequiredSchema());
+    bootstrapFields = schemaHandler.getBootstrapRequiredFields();
+    assertTrue(bootstrapFields.getLeft().isEmpty());
+    assertEquals(Arrays.asList(getField("begin_lat"), getField("tip_history"), 
getField("rider")), bootstrapFields.getRight());
+
+    schemaHandler = new HoodiePositionBasedSchemaHandler(readerContext, 
DATA_SCHEMA, META_COLS_ONLY_SCHEMA,
+        Option.empty(), hoodieTableConfig, new TypedProperties());
+    assertEquals(META_COLS_ONLY_SCHEMA, schemaHandler.getRequiredSchema());
+    bootstrapFields = schemaHandler.getBootstrapRequiredFields();
+    assertEquals(Arrays.asList(getField("_hoodie_commit_seqno"), 
getField("_hoodie_record_key")), bootstrapFields.getLeft());
+    assertTrue(bootstrapFields.getRight().isEmpty());
+  }
+
+  private static Stream<Arguments> testMorParams() {
+    Stream.Builder<Arguments> b = Stream.builder();
+    for (boolean mergeUseRecordPosition : new boolean[] {true, false}) {
+      for (boolean supportsParquetRowIndex : new boolean[] {true, false}) {
+        b.add(Arguments.of(EVENT_TIME_ORDERING, true, false, 
mergeUseRecordPosition, supportsParquetRowIndex));
+        b.add(Arguments.of(EVENT_TIME_ORDERING, false, false, 
mergeUseRecordPosition, supportsParquetRowIndex));
+        b.add(Arguments.of(COMMIT_TIME_ORDERING, false, false, 
mergeUseRecordPosition, supportsParquetRowIndex));
+        b.add(Arguments.of(CUSTOM, false, true, mergeUseRecordPosition, 
supportsParquetRowIndex));
+        b.add(Arguments.of(CUSTOM, false, false, mergeUseRecordPosition, 
supportsParquetRowIndex));
+      }
+    }
+    return b.build();
+  }
+
+  @ParameterizedTest
+  @MethodSource("testMorParams")
+  public void testMor(RecordMergeMode mergeMode,
+                      boolean hasPrecombine,
+                      boolean isProjectionCompatible,
+                      boolean mergeUseRecordPosition,
+                      boolean supportsParquetRowIndex) {
+    HoodieReaderContext<String> readerContext = new 
MockReaderContext(supportsParquetRowIndex);
+    readerContext.setHasLogFiles(true);
+    readerContext.setHasBootstrapBaseFile(false);
+    //has no effect on schema unless we support position based merging
+    readerContext.setShouldMergeUseRecordPosition(mergeUseRecordPosition);
+    HoodieTableConfig hoodieTableConfig = mock(HoodieTableConfig.class);
+    when(hoodieTableConfig.populateMetaFields()).thenReturn(Boolean.TRUE);
+    when(hoodieTableConfig.getRecordMergeMode()).thenReturn(mergeMode);
+    if (hasPrecombine) {
+      when(hoodieTableConfig.getPreCombineField()).thenReturn("timestamp");
+    } else {
+      when(hoodieTableConfig.getPreCombineField()).thenReturn(null);
+    }
+    if (mergeMode == CUSTOM) {
+      Option<HoodieRecordMerger> merger = Option.of(new 
MockMerger(isProjectionCompatible, new String[]{"begin_lat", "begin_lon", 
"_hoodie_record_key", "timestamp"}));
+      readerContext.setRecordMerger(merger);
+    }
+    Schema requestedSchema = DATA_SCHEMA;
+    HoodieFileGroupReaderSchemaHandler schemaHandler = supportsParquetRowIndex
+        ? new HoodiePositionBasedSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+        Option.empty(), hoodieTableConfig, new TypedProperties())
+        : new HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+        Option.empty(), hoodieTableConfig, new TypedProperties());
+    Schema expectedRequiredFullSchema = supportsParquetRowIndex && 
mergeUseRecordPosition
+        ? 
HoodiePositionBasedSchemaHandler.addPositionalMergeCol(requestedSchema)
+        : requestedSchema;
+    assertEquals(expectedRequiredFullSchema, 
schemaHandler.getRequiredSchema());
+
+    //read subset of columns
+    requestedSchema = DATA_COLS_ONLY_SCHEMA;
+    schemaHandler = supportsParquetRowIndex
+        ? new HoodiePositionBasedSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+        Option.empty(), hoodieTableConfig, new TypedProperties())
+        : new HoodieFileGroupReaderSchemaHandler(readerContext, DATA_SCHEMA, 
requestedSchema,
+        Option.empty(), hoodieTableConfig, new TypedProperties());
+    Schema expectedRequiredSchema;
+    if (mergeMode == EVENT_TIME_ORDERING && hasPrecombine) {
+      expectedRequiredSchema = generateProjectionSchema("begin_lat", 
"tip_history", "rider", "_hoodie_record_key", "timestamp");
+    } else if (mergeMode == EVENT_TIME_ORDERING || mergeMode == 
COMMIT_TIME_ORDERING) {
+      expectedRequiredSchema = generateProjectionSchema("begin_lat", 
"tip_history", "rider", "_hoodie_record_key");
+    } else if (mergeMode == CUSTOM && isProjectionCompatible) {
+      expectedRequiredSchema = generateProjectionSchema("begin_lat", 
"tip_history", "rider", "begin_lon", "_hoodie_record_key", "timestamp");
+    } else {
+      expectedRequiredSchema = DATA_SCHEMA;

Review Comment:
   don't we need to add meta fields at the beginning in addition to actual data 
cols? 
   for CUSTOM merge mode and if projection is not compatible 
   



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