You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by bl...@apache.org on 2021/04/15 23:51:05 UTC

[iceberg] branch master updated: Spark: Add new actions entry point, SparkActions (#2473)

This is an automated email from the ASF dual-hosted git repository.

blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new 0a59a35  Spark: Add new actions entry point, SparkActions (#2473)
0a59a35 is described below

commit 0a59a351cca79b0be290fa0a4ffebaf4bd5e3cf3
Author: Anton Okolnychyi <ao...@apple.com>
AuthorDate: Thu Apr 15 16:50:51 2021 -0700

    Spark: Add new actions entry point, SparkActions (#2473)
---
 .../iceberg/spark/actions/BaseSparkActions.java    | 55 ++++++++++++++++++
 .../apache/iceberg/spark/actions/SparkActions.java | 44 +++++++++++++++
 .../apache/iceberg/spark/actions/SparkActions.java | 65 ++++++++++++++++++++++
 3 files changed, 164 insertions(+)

diff --git a/spark/src/main/java/org/apache/iceberg/spark/actions/BaseSparkActions.java b/spark/src/main/java/org/apache/iceberg/spark/actions/BaseSparkActions.java
new file mode 100644
index 0000000..4da4b80
--- /dev/null
+++ b/spark/src/main/java/org/apache/iceberg/spark/actions/BaseSparkActions.java
@@ -0,0 +1,55 @@
+/*
+ * 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 org.apache.iceberg.Table;
+import org.apache.iceberg.actions.ActionsProvider;
+import org.apache.iceberg.actions.ExpireSnapshots;
+import org.apache.iceberg.actions.RemoveOrphanFiles;
+import org.apache.iceberg.actions.RewriteManifests;
+import org.apache.spark.sql.SparkSession;
+
+abstract class BaseSparkActions implements ActionsProvider {
+
+  private final SparkSession spark;
+
+  protected BaseSparkActions(SparkSession spark) {
+    this.spark = spark;
+  }
+
+  protected SparkSession spark() {
+    return spark;
+  }
+
+  @Override
+  public RemoveOrphanFiles removeOrphanFiles(Table table) {
+    return new BaseRemoveOrphanFilesSparkAction(spark, table);
+  }
+
+  @Override
+  public RewriteManifests rewriteManifests(Table table) {
+    return new BaseRewriteManifestsSparkAction(spark, table);
+  }
+
+  @Override
+  public ExpireSnapshots expireSnapshots(Table table) {
+    return new BaseExpireSnapshotsSparkAction(spark, table);
+  }
+}
diff --git a/spark2/src/main/java/org/apache/iceberg/spark/actions/SparkActions.java b/spark2/src/main/java/org/apache/iceberg/spark/actions/SparkActions.java
new file mode 100644
index 0000000..66e2aa5
--- /dev/null
+++ b/spark2/src/main/java/org/apache/iceberg/spark/actions/SparkActions.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.iceberg.actions.ActionsProvider;
+import org.apache.spark.sql.SparkSession;
+
+/**
+ * An implementation of {@link ActionsProvider} for Spark.
+ * <p>
+ * This class is the primary API for interacting with actions in Spark that users should use
+ * to instantiate particular actions.
+ */
+public class SparkActions extends BaseSparkActions {
+
+  private SparkActions(SparkSession spark) {
+    super(spark);
+  }
+
+  public static SparkActions get(SparkSession spark) {
+    return new SparkActions(spark);
+  }
+
+  public static SparkActions get() {
+    return new SparkActions(SparkSession.active());
+  }
+}
diff --git a/spark3/src/main/java/org/apache/iceberg/spark/actions/SparkActions.java b/spark3/src/main/java/org/apache/iceberg/spark/actions/SparkActions.java
new file mode 100644
index 0000000..1497845
--- /dev/null
+++ b/spark3/src/main/java/org/apache/iceberg/spark/actions/SparkActions.java
@@ -0,0 +1,65 @@
+/*
+ * 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 org.apache.iceberg.actions.ActionsProvider;
+import org.apache.iceberg.actions.MigrateTable;
+import org.apache.iceberg.actions.SnapshotTable;
+import org.apache.iceberg.spark.Spark3Util;
+import org.apache.iceberg.spark.Spark3Util.CatalogAndIdentifier;
+import org.apache.spark.sql.SparkSession;
+import org.apache.spark.sql.connector.catalog.CatalogPlugin;
+
+/**
+ * An implementation of {@link ActionsProvider} for Spark.
+ * <p>
+ * This class is the primary API for interacting with actions in Spark that users should use
+ * to instantiate particular actions.
+ */
+public class SparkActions extends BaseSparkActions {
+
+  private SparkActions(SparkSession spark) {
+    super(spark);
+  }
+
+  public static SparkActions get(SparkSession spark) {
+    return new SparkActions(spark);
+  }
+
+  public static SparkActions get() {
+    return new SparkActions(SparkSession.active());
+  }
+
+  @Override
+  public SnapshotTable snapshotTable(String tableIdent) {
+    String ctx = "snapshot source";
+    CatalogPlugin defaultCatalog = spark().sessionState().catalogManager().currentCatalog();
+    CatalogAndIdentifier catalogAndIdent = Spark3Util.catalogAndIdentifier(ctx, spark(), tableIdent, defaultCatalog);
+    return new BaseSnapshotTableSparkAction(spark(), catalogAndIdent.catalog(), catalogAndIdent.identifier());
+  }
+
+  @Override
+  public MigrateTable migrateTable(String tableIdent) {
+    String ctx = "migrate target";
+    CatalogPlugin defaultCatalog = spark().sessionState().catalogManager().currentCatalog();
+    CatalogAndIdentifier catalogAndIdent = Spark3Util.catalogAndIdentifier(ctx, spark(), tableIdent, defaultCatalog);
+    return new BaseMigrateTableSparkAction(spark(), catalogAndIdent.catalog(), catalogAndIdent.identifier());
+  }
+}