JingsongLi commented on code in PR #11322:
URL: https://github.com/apache/paimon/pull/11322#discussion_r4662694379
##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/MergeIntoPaimonDataEvolutionTable.scala:
##########
@@ -1432,6 +1497,77 @@ object MergeIntoPaimonDataEvolutionTable {
final private val MERGE_DELETED_NAME = "_PAIMON_MERGE_INTO_DELETED"
final private val RAW_BLOB_PLACEHOLDER_MARKER_PREFIX =
"__paimon_raw_blob_placeholder_"
+ private[commands] def pinNarrowSource(
+ plan: LogicalPlan,
+ targetRelation: DataSourceV2Relation): Option[LogicalPlan] = {
+ def identity(table: FileStoreTable): (String, String) =
+ (
+ table.location().toString,
+ BranchManager.normalizeBranch(CoreOptions.branch(table.options())))
+
+ val target = targetRelation.table match {
+ case sparkTable: SparkTable =>
sparkTable.getTable.asInstanceOf[FileStoreTable]
+ case _ => return None
+ }
+
+ def pin(current: LogicalPlan): Option[LogicalPlan] = current match {
+ case alias: SubqueryAlias => pin(alias.child).map(child =>
alias.copy(child = child))
+ case project: Project if project.projectList.forall {
+ case _: AttributeReference => true
+ case Alias(_: AttributeReference, _) => true
+ case _ => false
+ } =>
+ pin(project.child).map(child => project.copy(child = child))
+ case relation: DataSourceV2Relation =>
+ relation.table match {
+ case sparkTable: SparkTable =>
+ sparkTable.getTable match {
+ // Pinning one branch would time-travel the other branch as well.
+ case _: FallbackReadFileStoreTable => None
+ case source: FileStoreTable
+ if source.primaryKeys().isEmpty && identity(source) !=
identity(target) &&
+ Set(
+ CoreOptions.StartupMode.LATEST_FULL,
+ CoreOptions.StartupMode.LATEST,
+ CoreOptions.StartupMode.FROM_TIMESTAMP,
+ CoreOptions.StartupMode.FROM_SNAPSHOT,
+ CoreOptions.StartupMode.FROM_SNAPSHOT_FULL
+ )
+ .contains(source.coreOptions().startupMode()) =>
+ // Resolving scan.version can mutate options; never resolve it
on the input table.
+ val copied = source.copy(new JHashMap[String, String]())
+ Option(TimeTravelUtil.tryTravelOrLatest(copied))
+ .filter(snapshot =>
copied.snapshotManager().snapshotExists(snapshot.id()))
+ .flatMap {
+ snapshot =>
+ val options = new JHashMap[String, String]()
+ timeTravelOptionKeys.foreach(options.put(_, null))
+ options.put(CoreOptions.SCAN_SNAPSHOT_ID.key(),
snapshot.id().toString)
Review Comment:
**[P1] Bind both MERGE reads to the same source snapshot contents.** A
snapshot ID can be reused after a rollback. In a local Spark 3.5.9 MERGE, the
shared join saw source snapshot 2 with an unmatched row `(4, 400, 'old')`. The
source was rolled back and a new snapshot 2 contained `(4, 499, 'replacement')`
by the time INSERT read the payload. With narrowing enabled, MERGE committed
the replacement row. With narrowing disabled, it committed the original row. A
matching schema ID cannot distinguish these snapshots. Please reuse the
original snapshot's scan plan for both reads, or stop the MERGE if the pinned
contents are no longer available. The Spark 4.0 mirror uses the same numeric
pin.
--
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]