yihua commented on code in PR #11413: URL: https://github.com/apache/hudi/pull/11413#discussion_r1631715014
########## hudi-common/src/main/java/org/apache/hudi/common/table/read/HoodiePositionBasedSchemaHandler.java: ########## @@ -0,0 +1,76 @@ +/* + * 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.common.engine.HoodieReaderContext; +import org.apache.hudi.common.table.HoodieTableConfig; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.internal.schema.InternalSchema; + +import org.apache.avro.Schema; + +import java.util.Collections; +import java.util.List; + +import static org.apache.hudi.avro.AvroSchemaUtils.appendFieldsToSchemaDedupNested; + +/** + * This class is responsible for handling the schema for the file group reader that supports positional merge. + */ +public class HoodiePositionBasedSchemaHandler<T> extends HoodieFileGroupReaderSchemaHandler<T> { + public HoodiePositionBasedSchemaHandler(HoodieReaderContext<T> readerContext, + Schema dataSchema, + Schema requestedSchema, + Option<InternalSchema> internalSchemaOpt, + HoodieTableConfig hoodieTableConfig) { + super(readerContext, dataSchema, requestedSchema, internalSchemaOpt, hoodieTableConfig); + Review Comment: nit: remove empty line. ########## hudi-spark-datasource/hudi-spark-common/src/test/scala/org/apache/spark/execution/datasources/parquet/TestSparkFileFormatInternalRowReaderContext.scala: ########## @@ -0,0 +1,72 @@ +/* + * 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.spark.execution.datasources.parquet + +import org.apache.hudi.SparkFileFormatInternalRowReaderContext +import org.apache.hudi.SparkFileFormatInternalRowReaderContext.filterIsSafeForBootstrap +import org.apache.hudi.common.model.HoodieRecord +import org.apache.hudi.common.table.read.HoodiePositionBasedFileGroupRecordBuffer.ROW_INDEX_TEMPORARY_COLUMN_NAME +import org.apache.hudi.testutils.SparkClientFunctionalTestHarness +import org.apache.spark.sql.sources.{And, IsNotNull, Or} +import org.apache.spark.sql.types.{LongType, StringType, StructField, StructType} +import org.junit.jupiter.api.Assertions.{assertEquals, assertFalse, assertTrue} +import org.junit.jupiter.api.Test + +class TestSparkFileFormatInternalRowReaderContext extends SparkClientFunctionalTestHarness { + + @Test + def testBootstrapFilters(): Unit = { + val recordKeyField = HoodieRecord.HoodieMetadataField.RECORD_KEY_METADATA_FIELD.getFieldName + val commitTimeField = HoodieRecord.HoodieMetadataField.COMMIT_TIME_METADATA_FIELD.getFieldName + + val recordKeyFilter = IsNotNull(recordKeyField) + assertTrue(filterIsSafeForBootstrap(recordKeyFilter)) + val commitTimeFilter = IsNotNull(commitTimeField) + assertTrue(filterIsSafeForBootstrap(commitTimeFilter)) + + val dataFieldFilter = IsNotNull("someotherfield") + assertTrue(filterIsSafeForBootstrap(dataFieldFilter)) + + val legalComplexFilter = Or(recordKeyFilter, commitTimeFilter) + assertTrue(filterIsSafeForBootstrap(legalComplexFilter)) + + val illegalComplexFilter = Or(recordKeyFilter, dataFieldFilter) + assertFalse(filterIsSafeForBootstrap(illegalComplexFilter)) + + val illegalNestedFilter = And(legalComplexFilter, illegalComplexFilter) + assertFalse(filterIsSafeForBootstrap(illegalNestedFilter)) + + val legalNestedFilter = And(legalComplexFilter, recordKeyFilter) + assertTrue(filterIsSafeForBootstrap(legalNestedFilter)) + } + + @Test + def testGetAppliedRequiredSchema(): Unit = { + val fields = Array( + StructField("column_a", LongType, nullable = false), + StructField("column_b", StringType, nullable = false)) + val requiredSchema = StructType(fields) + + val appliedSchema: StructType = SparkFileFormatInternalRowReaderContext.getAppliedRequiredSchema( Review Comment: Do we have tests on `SparkFileFormatInternalRowReaderContext` in different Spark versions so that the filters pushed down are different depending on whether the Spark parquet reader can read row index from the parquet files? ########## hudi-common/src/main/java/org/apache/hudi/common/engine/HoodieReaderContext.java: ########## @@ -301,9 +311,19 @@ public final UnaryOperator<T> projectRecord(Schema from, Schema to) { * @return the record position in the base file. */ public long extractRecordPosition(T record, Schema schema, String fieldName, long providedPositionIfNeeded) { + if (supportsParquetRowIndex()) { + Object position = getValue(record, schema, fieldName); + if (position != null) { + return (long) position; + } Review Comment: Should we throw an error if the position is not read from the parquet reader when we enable that? -- 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: commits-unsubscr...@hudi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org