You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "dramaticlly (via GitHub)" <gi...@apache.org> on 2023/05/19 00:25:02 UTC

[GitHub] [iceberg] dramaticlly commented on a diff in pull request #7593: Spark3.4: Throw a friendly exception if table is empty when creating branch

dramaticlly commented on code in PR #7593:
URL: https://github.com/apache/iceberg/pull/7593#discussion_r1198413433


##########
spark/v3.4/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/CreateOrReplaceBranchExec.scala:
##########
@@ -41,7 +41,12 @@ case class CreateOrReplaceBranchExec(
   override protected def run(): Seq[InternalRow] = {
     catalog.loadTable(ident) match {
       case iceberg: SparkTable =>
-        val snapshotId = branchOptions.snapshotId.getOrElse(iceberg.table.currentSnapshot().snapshotId())
+        var snapshotId = branchOptions.snapshotId.getOrElse(-1L)
+        if (snapshotId == -1) {
+          val currentSnapshot = Option(iceberg.table().currentSnapshot()).getOrElse(throw new IllegalArgumentException(
+            s"Please specify an explicit snapshot as table: $iceberg"  + " has no latest main snapshot"))
+          snapshotId = currentSnapshot.snapshotId()
+        }

Review Comment:
   ```suggestion
   val snapshotId: java.lang.Long = branchOptions.snapshotId.orElse(Option(table.currentSnapshot()).map(x => x.snapshotId())).map(java.lang.Long.valueOf).orNull
   ```



##########
spark/v3.4/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestBranchDDL.java:
##########
@@ -289,4 +300,8 @@ private Table insertRows() throws NoSuchTableException {
     df.writeTo(tableName).append();
     return validationCatalog.loadTable(tableIdent);
   }
+
+  private Table createEmptyTable() {
+    return validationCatalog.loadTable(tableIdent);

Review Comment:
   this is not create table but rather load a table from catalog. 
   
   I think empty table creation is already handled in `before` method at line 43 so this method is not needed at all



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org