slfan1989 commented on code in PR #14209:
URL: https://github.com/apache/iceberg/pull/14209#discussion_r2393398415


##########
spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/actions/Hive2IcebergAction.java:
##########
@@ -0,0 +1,445 @@
+/*
+ * 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.spark.actions;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Map;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.CatalogProperties;
+import org.apache.iceberg.actions.Hive2Iceberg;
+import org.apache.iceberg.actions.ImmutableHive2Iceberg;
+import org.apache.iceberg.actions.RewriteTablePath;
+import org.apache.iceberg.actions.SnapshotTable;
+import org.apache.iceberg.hadoop.HadoopFileIO;
+import org.apache.iceberg.hive.HiveCatalog;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.spark.Spark3Util;
+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.catalog.CatalogTable;
+import org.apache.spark.sql.catalyst.catalog.CatalogUtils;
+import org.apache.spark.sql.connector.catalog.CatalogPlugin;
+import org.apache.spark.sql.connector.catalog.Identifier;
+import org.apache.spark.sql.connector.catalog.StagingTableCatalog;
+import org.apache.spark.sql.connector.catalog.TableCatalog;
+import org.apache.spark.sql.connector.catalog.TableChange;
+import org.apache.spark.sql.connector.catalog.V1Table;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Hive2IcebergAction extends 
BaseTableCreationSparkAction<Hive2IcebergAction>
+    implements Hive2Iceberg {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(Hive2IcebergAction.class);
+  private SnapshotTableSparkAction snapshotTableSparkAction;
+  private Identifier sourceTableIdent;
+  private int parallelism = 1;
+  private SparkSession sparkSession;
+  private CatalogPlugin sourceCatalog;
+
+  Hive2IcebergAction(SparkSession spark, CatalogPlugin sourceCatalog, 
Identifier sourceTableIdent) {
+    super(spark, sourceCatalog, sourceTableIdent);
+    this.sourceTableIdent = sourceTableIdent;
+    this.sparkSession = spark;
+    this.sourceCatalog = sourceCatalog;
+  }
+
+  @Override
+  public Hive2Iceberg parallelism(int pParallelism) {
+    this.parallelism = pParallelism;
+    return this;
+  }
+
+  @Override
+  public Result execute() {
+
+    // Step1. Process SnapShot
+    String snapShotTableName = 
generateSnapShotTableName(sourceTableIdent.name());
+    boolean snapshotSuccess = handleSnapshotCreation(snapShotTableName);
+    if (!snapshotSuccess) {
+      return buildFailureResult("Snapshot creation failed");
+    }
+
+    // Step2. Prepare SourceTable
+    OperationSourceTableResult sourceTableResult = 
handleSourceTablePreparation();
+    if (!sourceTableResult.isSuccess()) {
+      return buildFailureResult("Source Table preparation failed");
+    }
+
+    CatalogTable sourceSparkTable = sourceTableResult.getSourceSparkTable();
+    Identifier sourceIdentifier = sourceTableResult.getSourceIdentifier();
+
+    // Step3. Prepare TargetTable
+    OperationTargetTableResult targetTableResult = 
handleTargetTablePreparation(snapShotTableName);
+    if (!targetTableResult.isSuccess()) {
+      return buildFailureResult("Target Table preparation failed");
+    }
+
+    SparkTable snapShotSparkTable = targetTableResult.getSnapShotSparkTable();
+
+    // Step4. Rewrite Table Path
+    OperationPathRewriteResult handlePathRewrite =
+        handlePathRewrite(snapShotSparkTable, sourceSparkTable);
+    if (!handlePathRewrite.isSuccess()) {
+      return buildFailureResult("Rewrite Table Path failed");
+    }
+
+    String latestVersion = handlePathRewrite.getLatestVersion();
+    String targetPrefix = 
CatalogUtils.URIToString(sourceSparkTable.storage().locationUri().get());

Review Comment:
   Thank you for your suggestions, I have improved this part of the code.
   



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


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

Reply via email to