yihua commented on code in PR #12161: URL: https://github.com/apache/hudi/pull/12161#discussion_r1849647114
########## hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/testutils/HoodieSparkDeleteRecordMerger.java: ########## @@ -0,0 +1,48 @@ +/* + * 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.testutils; + +import org.apache.hudi.HoodieSparkRecordMerger; +import org.apache.hudi.common.config.TypedProperties; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.common.util.collection.Pair; + +import org.apache.avro.Schema; + +import java.io.IOException; + +/** + * Instead of merging, it will just delete the record. Use for testing + * + */ +public class HoodieSparkDeleteRecordMerger extends HoodieSparkRecordMerger { + public static final String DELETE_MERGER_STRATEGY = "aea2e14e-19a2-4e33-bc37-f8871d55bd5b"; + + @Override + public Option<Pair<HoodieRecord, Schema>> merge(HoodieRecord older, Schema oldSchema, HoodieRecord newer, Schema newSchema, TypedProperties props) throws IOException { + return Option.empty(); Review Comment: Could we test something more complex by summing up a field or doing conditional deletes instead of blindly returning empty record for all cases? ########## hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestStructuredStreaming.scala: ########## @@ -496,15 +496,52 @@ class TestStructuredStreaming extends HoodieSparkClientTestBase { val inputDF1 = spark.read.json(spark.sparkContext.parallelize(records1, 2)) inputDF1.coalesce(1).write.mode(SaveMode.Append).json(sourcePath) val opts = commonOpts + (DataSourceWriteOptions.TABLE_TYPE.key -> HoodieTableType.MERGE_ON_READ.name()) + (DataSourceWriteOptions.STREAMING_DISABLE_COMPACTION.key -> "true") - streamingWrite(inputDF1.schema, sourcePath, destPath, opts, "000") + streamingWrite(inputDF1.schema, sourcePath, destPath, opts) for (i <- 1 to 24) { val id = String.format("%03d", new Integer(i)) val records = recordsToStrings(dataGen.generateUpdates(id, 10)).asScala.toList val inputDF = spark.read.json(spark.sparkContext.parallelize(records, 2)) inputDF.coalesce(1).write.mode(SaveMode.Append).json(sourcePath) - streamingWrite(inputDF.schema, sourcePath, destPath, opts, id) + streamingWrite(inputDF.schema, sourcePath, destPath, opts) } - val metaClient = HoodieTestUtils.createMetaClient(storage, destPath); + val metaClient = HoodieTestUtils.createMetaClient(storage, destPath) assertTrue(metaClient.getActiveTimeline.getCommitAndReplaceTimeline.empty()) + assertEquals(25, metaClient.getActiveTimeline.countInstants()) + } + + @ParameterizedTest + @ValueSource(booleans = Array(true, false)) + def testStructuredStreamingWithMergeMode(isCow: Boolean): Unit = { + val (sourcePath, destPath) = initStreamingSourceAndDestPath("source", "dest") + // First chunk of data + val records1 = recordsToStrings(dataGen.generateInserts("000", 10)).asScala.toList + val inputDF1 = spark.read.json(spark.sparkContext.parallelize(records1, 2)) + inputDF1.coalesce(1).write.mode(SaveMode.Append).json(sourcePath) + val tableType = if (isCow) { + "COPY_ON_WRITE" + } else { + "MERGE_ON_READ" + } + val opts = commonOpts ++ Map(DataSourceWriteOptions.OPERATION.key -> UPSERT_OPERATION_OPT_VAL, + DataSourceWriteOptions.TABLE_TYPE.key() -> tableType, + DataSourceWriteOptions.RECORD_MERGE_MODE.key() -> RecordMergeMode.CUSTOM.name(), Review Comment: Could we test all three merge modes here? -- 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]
