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


##########
hudi-spark-datasource/hudi-spark3-common/src/main/scala/org/apache/spark/sql/hudi/command/MergeIntoHoodieTableCommand.scala:
##########
@@ -600,8 +603,14 @@ case class MergeIntoHoodieTableCommand(mergeInto: 
MergeIntoTable) extends Hoodie
       && getPartialUpdateMode(parameters).isEmpty)
   }
 
+  /**
+   * A table with record key(s) is upserted when the statement has a matched 
clause, since only the index
+   * lookup finds the target record the clause applies to.
+   */
   private def getOperationType(parameters: Map[String, String]) = {
-    if 
(StringUtils.isNullOrEmpty(ConfigUtils.getOrderingFieldsStrDuringWrite(parameters.asJava))
 && updatingActions.isEmpty) {
+    val hasMatchedClauseToApply = if (hasPrimaryKey()) 
mergeInto.matchedActions.nonEmpty else updatingActions.nonEmpty

Review Comment:
   **blocker:** Moving delete+insert statements to upsert loses a re-insert on 
MOR with SIMPLE/BLOOM: after `delete from t where id = 1` (log-file delete), 
`when matched and s.op = 'del' then delete when not matched then insert` with 
source id 1 leaves id 1 absent, while master inserted it. The index tags the 
key from the base file, so ExpressionPayload takes the matched branch 
(ExpressionPayload.scala:283-290), the same reason the description gives for 
keeping insert-only off upsert. Could the deleted-key test at L1012 also run a 
delete+insert statement, and the "same on master" limitation be reworded, since 
it only holds for tables with an ordering field or bucket index?



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