amogh-jahagirdar commented on code in PR #6638: URL: https://github.com/apache/iceberg/pull/6638#discussion_r1084620912
########## spark/v3.3/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/CreateOrReplaceBranchExec.scala: ########## @@ -38,33 +40,35 @@ case class CreateBranchExec( override protected def run(): Seq[InternalRow] = { catalog.loadTable(ident) match { case iceberg: SparkTable => + val snapshotId = branchOptions.snapshotId.getOrElse(iceberg.table.currentSnapshot().snapshotId()) + val manageSnapshots = if (replace) { + iceberg.table().manageSnapshots().replaceBranch(branch, snapshotId) + } else { + iceberg.table().manageSnapshots().createBranch(branch, snapshotId) + } - val snapshotId = createBranch.snapshotId.getOrElse(iceberg.table.currentSnapshot().snapshotId()) - val manageSnapshot = iceberg.table.manageSnapshots() - .createBranch(createBranch.branch, snapshotId) - - if (createBranch.numSnapshots.nonEmpty) { - manageSnapshot.setMinSnapshotsToKeep(createBranch.branch, createBranch.numSnapshots.get.toInt) + if (branchOptions.numSnapshots.nonEmpty) { + manageSnapshots.setMinSnapshotsToKeep(branch, branchOptions.numSnapshots.get.toInt) } - if (createBranch.snapshotRetain.nonEmpty) { - manageSnapshot.setMaxSnapshotAgeMs(createBranch.branch, createBranch.snapshotRetain.get) + if (branchOptions.snapshotRetain.nonEmpty) { + manageSnapshots.setMaxSnapshotAgeMs(branch, branchOptions.snapshotRetain.get) } - if (createBranch.snapshotRefRetain.nonEmpty) { - manageSnapshot.setMaxRefAgeMs(createBranch.branch, createBranch.snapshotRefRetain.get) + if (branchOptions.snapshotRefRetain.nonEmpty) { + manageSnapshots.setMaxRefAgeMs(branch, branchOptions.snapshotRefRetain.get) } - manageSnapshot.commit() + manageSnapshots.commit() case table => - throw new UnsupportedOperationException(s"Cannot add branch to non-Iceberg table: $table") + throw new UnsupportedOperationException(s"Cannot replace branch to non-Iceberg table: $table") Review Comment: Need to update this message -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org