forked from apache/iceberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spark: Add new actions entry point, SparkActions (apache#2473)
- Loading branch information
1 parent
66f4683
commit 0a59a35
Showing
3 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
spark/src/main/java/org/apache/iceberg/spark/actions/BaseSparkActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
spark2/src/main/java/org/apache/iceberg/spark/actions/SparkActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
spark3/src/main/java/org/apache/iceberg/spark/actions/SparkActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |