rdblue commented on a change in pull request #1525:
URL: https://github.com/apache/iceberg/pull/1525#discussion_r538755375



##########
File path: 
spark3/src/main/java/org/apache/iceberg/actions/Spark3SnapshotAction.java
##########
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iceberg.actions;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.SnapshotSummary;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.spark.SparkTableUtil;
+import org.apache.iceberg.spark.source.SparkTable;
+import org.apache.spark.sql.SparkSession;
+import org.apache.spark.sql.catalyst.TableIdentifier;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException;
+import org.apache.spark.sql.connector.catalog.CatalogPlugin;
+import org.apache.spark.sql.connector.catalog.Identifier;
+import org.apache.spark.sql.connector.catalog.StagedTable;
+import org.apache.spark.sql.connector.catalog.TableCatalog;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import scala.collection.JavaConverters;
+
+/**
+ * Creates a new Iceberg table based on a source Spark table. The new Iceberg 
table will
+ * have a different data and metadata directory allowing it to exist 
independently of the
+ * source table.
+ */
+class Spark3SnapshotAction extends Spark3CreateAction implements 
SnapshotAction {
+  private static final Logger LOG = 
LoggerFactory.getLogger(Spark3SnapshotAction.class);
+
+  private String destTableLocation = null;
+
+  Spark3SnapshotAction(SparkSession spark, CatalogPlugin sourceCatalog,
+                       Identifier sourceTableName, CatalogPlugin destCatalog,
+                       Identifier destTableName) {
+    super(spark, sourceCatalog, sourceTableName, destCatalog, destTableName);
+  }
+
+  @Override
+  public Long execute() {
+    StagedTable stagedTable;
+    Table icebergTable;
+
+    try {
+      stagedTable = destCatalog().stageCreate(destTableName(), 
v1SourceTable().schema(),
+          sourcePartitionSpec(), buildPropertyMap());
+      icebergTable = ((SparkTable) stagedTable).table();
+
+      if 
(!icebergTable.properties().containsKey(TableProperties.DEFAULT_NAME_MAPPING)) {
+        assignDefaultTableNameMapping(icebergTable);
+      }
+    } catch (TableAlreadyExistsException taeException) {
+      throw new IllegalArgumentException("Cannot create snapshot because a 
table already exists with that name",
+          taeException);
+    } catch (NoSuchNamespaceException nsnException) {
+      throw new IllegalArgumentException("Cannot create snapshot because the 
namespace given does not exist",
+          nsnException);
+    }
+
+    boolean threw = true;
+    try {
+      String stagingLocation = icebergTable.location() + "/" + 
ICEBERG_METADATA_FOLDER;

Review comment:
       I don't really have an opinion on whether we need to customize this in 
snapshot tables. I think for migration it is a good idea. For snapshots, I'd 
probably opt to keep it simple.




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

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to