voonhous commented on code in PR #19163:
URL: https://github.com/apache/hudi/pull/19163#discussion_r3664860637


##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestMergeIntoWriteCoverage.scala:
##########
@@ -0,0 +1,242 @@
+/*
+ * 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.sql.hudi.dml.others
+
+import org.apache.hudi.DataSourceWriteOptions.SPARK_SQL_OPTIMIZED_WRITES
+
+import org.apache.spark.sql.hudi.common.HoodieSparkSqlTestBase
+
+/**
+ * Focused coverage for the MERGE INTO write path implemented by
+ * [[org.apache.spark.sql.hudi.command.payload.ExpressionPayload]] and
+ * [[org.apache.spark.sql.hudi.command.MergeIntoKeyGenerator]].
+ *
+ * The scenarios below intentionally combine, within a single statement, all 
of:
+ *   - conditional matched UPDATE clauses (the update-condition evaluation 
loop),
+ *   - matched DELETE clauses (both conditional and unconditional delete 
markers),
+ *   - conditional NOT-MATCHED INSERT clauses (including a not-matched row that
+ *     matches no insert condition and is therefore filtered),
+ * so both the matched and not-matched evaluators, the delete-marker branch, 
and the
+ * record-merge branch are exercised. Running against partitioned COW and MOR 
tables
+ * with the row-writer path both enabled and disabled additionally drives the
+ * record-key / partition-path extraction overloads of MergeIntoKeyGenerator 
(the
+ * meta-field-populated branch for matched rows and the key-generator fallback 
for
+ * freshly inserted rows).
+ */
+class TestMergeIntoWriteCoverage extends HoodieSparkSqlTestBase {
+
+  test("Test MergeInto conditional update, delete-marker and insert on 
partitioned COW") {
+    Seq(true, false).foreach { optimizedWrites =>
+      withTempDir { tmp =>
+        withSQLConf(SPARK_SQL_OPTIMIZED_WRITES.key() -> 
optimizedWrites.toString) {
+          val tableName = generateTableName
+          spark.sql(
+            s"""
+               |create table $tableName (
+               |  id int,
+               |  name string,
+               |  price double,
+               |  ts int,
+               |  pt string
+               |) using hudi
+               | partitioned by (pt)
+               | location '${tmp.getCanonicalPath}'
+               | tblproperties (
+               |  type = 'cow',
+               |  primaryKey = 'id',

Review Comment:
   Okay. `buildMergeIntoConfig` picks `MergeIntoKeyGenerator` only when 
`!hasPrimaryKey()`, and all four tests here declare `primaryKey = 'id'`, so 
every one of them goes through `SqlKeyGenerator`. The claim was wrong.
   
   Narrowed rather than added a test: `TestMergeIntoTableWithNonRecordKeyField` 
already covers the pkless path end to end -- `Test pkless complex merge cond`, 
`Test pkless multiple source match`, and `Test MergeInto Basic pkless`, between 
them matched update, not-matched insert, and matched delete. A fifth here would 
duplicate that.
   
   Scaladoc and the PR description now say which generator these tests actually 
drive and point at that suite. Happy to add the pkless case here instead if 
you'd rather have it co-located.
   



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