yihua commented on code in PR #19912: URL: https://github.com/apache/hudi/pull/19912#discussion_r4200177321
########## hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestIncrementalFileIndexSizeInBytes.scala: ########## @@ -0,0 +1,106 @@ +/* + * 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, HoodieIncrementalFileIndex} +import org.apache.hudi.common.model.HoodieTableType +import org.apache.hudi.common.table.HoodieTableConfig +import org.apache.hudi.common.testutils.HoodieTestDataGenerator.recordsToStrings +import org.apache.hudi.config.HoodieWriteConfig +import org.apache.hudi.testutils.HoodieSparkClientTestBase + +import org.apache.spark.sql.{DataFrame, SaveMode, SparkSession} +import org.apache.spark.sql.execution.datasources.{HadoopFsRelation, LogicalRelation} +import org.junit.jupiter.api.{AfterEach, BeforeEach} +import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue} +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +import scala.collection.JavaConverters._ + +/** + * Verifies the size reported to the Spark planner by [[HoodieIncrementalFileIndex]], which must never be 0 + * or Spark may pick a broadcast join against the incremental source. + */ +class TestIncrementalFileIndexSizeInBytes extends HoodieSparkClientTestBase { + + var spark: SparkSession = null + + val commonOpts = Map( + "hoodie.insert.shuffle.parallelism" -> "4", + "hoodie.upsert.shuffle.parallelism" -> "4", + DataSourceWriteOptions.RECORDKEY_FIELD.key -> "_row_key", + DataSourceWriteOptions.PARTITIONPATH_FIELD.key -> "partition", + HoodieTableConfig.ORDERING_FIELDS.key -> "timestamp", + HoodieWriteConfig.TBL_NAME.key -> "hoodie_test" + ) + + @BeforeEach + override def setUp(): Unit = { + setTableName("hoodie_test") + initPath() + initSparkContexts() + spark = sqlContext.sparkSession + initTestDataGenerator() + initHoodieStorage() + } + + @AfterEach + override def tearDown(): Unit = { + cleanupSparkContexts() + cleanupTestDataGenerator() + cleanupFileSystem() + } + + @ParameterizedTest + @EnumSource(value = classOf[HoodieTableType]) + def testIncrementalFileIndexSizeInBytes(tableType: HoodieTableType): Unit = { + val records = recordsToStrings(dataGen.generateInserts("001", 100)).asScala.toList + spark.read.json(spark.sparkContext.parallelize(records, 2)).write.format("hudi") + .options(commonOpts) + .option(DataSourceWriteOptions.TABLE_TYPE.key, tableType.name()) + .option(DataSourceWriteOptions.OPERATION.key, DataSourceWriteOptions.INSERT_OPERATION_OPT_VAL) + .mode(SaveMode.Append) + .save(basePath) + + // Reports Long.MaxValue by default, matching the pre-1.0 IncrementalRelation. + assertEquals(Long.MaxValue, incrementalFileIndexOf(Map.empty).sizeInBytes) + + // Reports the size of the files affected by the commits in range when disabled. + val fileIndex = incrementalFileIndexOf(Map( + DataSourceReadOptions.INCREMENTAL_REPORT_MAX_FILE_SIZE.key -> "false", + DataSourceReadOptions.INCREMENTAL_FALLBACK_TO_FULL_TABLE_SCAN.key -> "false")) + val size = fileIndex.sizeInBytes + assertTrue(size > 0 && size < Long.MaxValue, s"Expected the affected files size but got $size") Review Comment: non-blocking: with a single commit read from `000`, the affected files are the whole table, and `size > 0 && size < Long.MaxValue` would also pass for the whole-table size or any other positive number. Could the test add a second commit as an upsert (so the MOR arm gets log files) and assert that the size for the second commit's range equals the sum of that commit's write-stat file sizes? -- 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]
