https://delta.io logo
j

jacktby jacktby

08/13/2023, 5:15 AM
I see here, the deleteSourceRowExpr will be used for "delete unmatched source row when it should not be inserted". But I test some cases and I can't find the source row deleted. can you give me a sql case to achieve this?
Copy code
// N + 1 (or N + 2 with CDC, N + 4 preserving Row Tracking and CDC) expressions to delete the
    // unmatched source row when it should not be inserted. `target.output` will produce NULLs
    // which will get deleted eventually.
    val deleteSourceRowExprs =
      (targetOutputCols ++
        Seq(Literal(true))) ++
        (if (cdcEnabled) Seq(CDC_TYPE_NOT_CDC) else Seq())

    // ==== Generate N + 2 (N + 4 preserving Row Tracking) expressions for NOT MATCHED clause ====
    val processedNotMatchClauses: Seq[ProcessedClause] = generateAllActionExprs(
      targetOutputCols,
      clausesWithPrecompConditions.collect{ case c: DeltaMergeIntoNotMatchedClause => c },
      cdcEnabled,
      shouldCountDeletedRows)
    val notMatchedExprs: Seq[Expression] = generateClauseOutputExprs(
      numOutputCols,
      processedNotMatchClauses,
      deleteSourceRowExprs)