hudi-agent commented on code in PR #19165: URL: https://github.com/apache/hudi/pull/19165#discussion_r3523689250
########## hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestFileGroupReaderReadPath.scala: ########## @@ -0,0 +1,315 @@ +/* + * 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.functional + +import org.apache.hudi.{DataSourceReadOptions, DataSourceWriteOptions, HoodieFileIndex, ScalaAssertionSupport} +import org.apache.hudi.HoodieConversionUtils.toJavaOption +import org.apache.hudi.common.model.HoodieTableType +import org.apache.hudi.common.table.HoodieTableConfig +import org.apache.hudi.config.HoodieWriteConfig +import org.apache.hudi.testutils.{DataSourceTestUtils, HoodieSparkClientTestBase} +import org.apache.hudi.util.JFunction + +import org.apache.spark.sql.{SaveMode, SparkSession, SparkSessionExtensions} +import org.apache.spark.sql.catalyst.expressions.{And, AttributeReference, EqualTo, Literal} +import org.apache.spark.sql.execution.datasources.PartitionDirectory +import org.apache.spark.sql.hudi.HoodieSparkSessionExtension +import org.apache.spark.sql.types.{DataType, DoubleType, IntegerType, LongType, StringType} +import org.junit.jupiter.api.{AfterEach, BeforeEach} +import org.junit.jupiter.api.Assertions.{assertEquals, assertFalse, assertTrue} +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +import java.util.function.Consumer + +/** + * Functional coverage for the default (file-group reader) Spark read path. + * + * These tests keep [[org.apache.hudi.common.config.HoodieReaderConfig.FILE_GROUP_READER_ENABLED]] + * at its default (enabled) and drive read-time schema evolution, MOR base+log merge, partition + * pruning and typed partition-value projection through public DataFrame reads. They intentionally + * target branches left uncovered by the legacy-reader suite (PR #19133) and the existing + * COW/MOR/CDC functional suites: schema-on-read filter rebuilding, add-column / type-promotion + * evolution branches, HoodieFileIndex/SparkHoodieTableFileIndex partition pruning decisions, and + * the per-version HoodiePartitionValues getters used when partition columns are reconstructed. + */ +class TestFileGroupReaderReadPath extends HoodieSparkClientTestBase with ScalaAssertionSupport { + + var spark: SparkSession = _ + + private val baseOpts = Map( + "hoodie.insert.shuffle.parallelism" -> "2", + "hoodie.upsert.shuffle.parallelism" -> "2", + "hoodie.bulkinsert.shuffle.parallelism" -> "2", + "hoodie.delete.shuffle.parallelism" -> "1", + DataSourceWriteOptions.RECORDKEY_FIELD.key -> "id", + HoodieTableConfig.ORDERING_FIELDS.key -> "ts", + HoodieWriteConfig.TBL_NAME.key -> "hoodie_fg_reader_test", + // keep log files around on MOR so snapshot reads exercise base+log merge + "hoodie.compact.inline" -> "false" + ) + + override def getSparkSessionExtensionsInjector: org.apache.hudi.common.util.Option[Consumer[SparkSessionExtensions]] = + toJavaOption( + Some( + JFunction.toJavaConsumer((receiver: SparkSessionExtensions) => + new HoodieSparkSessionExtension().apply(receiver)))) + + @BeforeEach + override def setUp(): Unit = { + initPath() + initSparkContexts() + spark = sqlContext.sparkSession + initTestDataGenerator() + initHoodieStorage() + } + + @AfterEach + override def tearDown(): Unit = { + cleanupSparkContexts() + cleanupTestDataGenerator() + cleanupFileSystem() + } + + /** + * Add-column schema evolution read: a column is introduced by a later commit while + * schema-on-read is enabled. The snapshot read must expose the new column (null for the + * older, un-touched rows), and pushed-down filters over both the pre-existing and the newly + * added columns must produce correct results. On MOR the update batch lands in log files, so + * the snapshot read additionally exercises the base+log merge iteration. + */ + @ParameterizedTest + @EnumSource(classOf[HoodieTableType]) + def testAddColumnEvolutionSnapshotAndIncrementalRead(tableType: HoodieTableType): Unit = { + val _spark = spark + import _spark.implicits._ + + val writeOpts = baseOpts ++ Map( + DataSourceWriteOptions.TABLE_TYPE.key -> tableType.name, + DataSourceWriteOptions.PARTITIONPATH_FIELD.key -> "part", + "hoodie.schema.on.read.enable" -> "true" Review Comment: 🤖 nit: `"hoodie.schema.on.read.enable"` appears five times across this file. Could you extract it as a `private val` at the class level (or use the constant from `HoodieReaderConfig` if one exists)? That way a key rename only needs one touch. <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]
