-
Notifications
You must be signed in to change notification settings - Fork 3k
Expire snapshots action without cache #1344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rdblue
merged 3 commits into
apache:master
from
RussellSpitzer:ExpireSnapshotsActionWithoutCache
Aug 20, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -20,8 +20,10 @@ | |
| package org.apache.iceberg.actions; | ||
|
|
||
| import java.util.List; | ||
| import org.apache.iceberg.BaseTable; | ||
| import org.apache.iceberg.MetadataTableType; | ||
| import org.apache.iceberg.Snapshot; | ||
| import org.apache.iceberg.StaticTableOperations; | ||
| import org.apache.iceberg.Table; | ||
| import org.apache.iceberg.TableMetadata; | ||
| import org.apache.iceberg.TableOperations; | ||
|
|
@@ -36,7 +38,10 @@ abstract class BaseAction<R> implements Action<R> { | |
| protected abstract Table table(); | ||
|
|
||
| protected String metadataTableName(MetadataTableType type) { | ||
| String tableName = table().toString(); | ||
| return metadataTableName(table().toString(), type); | ||
| } | ||
|
|
||
| protected String metadataTableName(String tableName, MetadataTableType type) { | ||
| if (tableName.contains("/")) { | ||
| return tableName + "#" + type; | ||
| } else if (tableName.startsWith("hadoop.")) { | ||
|
|
@@ -56,9 +61,9 @@ protected String metadataTableName(MetadataTableType type) { | |
| * @param table the table | ||
| * @return the paths of the Manifest Lists | ||
| */ | ||
| protected List<String> getManifestListPaths(Table table) { | ||
| private List<String> getManifestListPaths(Iterable<Snapshot> snapshots) { | ||
| List<String> manifestLists = Lists.newArrayList(); | ||
| for (Snapshot snapshot : table.snapshots()) { | ||
| for (Snapshot snapshot : snapshots) { | ||
| String manifestListLocation = snapshot.manifestListLocation(); | ||
| if (manifestListLocation != null) { | ||
| manifestLists.add(manifestListLocation); | ||
|
|
@@ -73,7 +78,7 @@ protected List<String> getManifestListPaths(Table table) { | |
| * @param ops TableOperations for the table we will be getting paths from | ||
| * @return a list of paths to metadata files | ||
| */ | ||
| protected List<String> getOtherMetadataFilePaths(TableOperations ops) { | ||
| private List<String> getOtherMetadataFilePaths(TableOperations ops) { | ||
| List<String> otherMetadataFiles = Lists.newArrayList(); | ||
| otherMetadataFiles.add(ops.metadataFileLocation("version-hint.text")); | ||
|
|
||
|
|
@@ -86,27 +91,36 @@ protected List<String> getOtherMetadataFilePaths(TableOperations ops) { | |
| } | ||
|
|
||
| protected Dataset<Row> buildValidDataFileDF(SparkSession spark) { | ||
| String allDataFilesMetadataTable = metadataTableName(MetadataTableType.ALL_DATA_FILES); | ||
| return buildValidDataFileDF(spark, table().toString()); | ||
| } | ||
|
|
||
| protected Dataset<Row> buildValidDataFileDF(SparkSession spark, String tableName) { | ||
| String allDataFilesMetadataTable = metadataTableName(tableName, MetadataTableType.ALL_DATA_FILES); | ||
| return spark.read().format("iceberg").load(allDataFilesMetadataTable).select("file_path"); | ||
| } | ||
|
|
||
| protected Dataset<Row> buildManifestFileDF(SparkSession spark) { | ||
| String allManifestsMetadataTable = metadataTableName(MetadataTableType.ALL_MANIFESTS); | ||
| protected Dataset<Row> buildManifestFileDF(SparkSession spark, String tableName) { | ||
| String allManifestsMetadataTable = metadataTableName(tableName, MetadataTableType.ALL_MANIFESTS); | ||
| return spark.read().format("iceberg").load(allManifestsMetadataTable).selectExpr("path as file_path"); | ||
| } | ||
|
|
||
| protected Dataset<Row> buildManifestListDF(SparkSession spark, Table table) { | ||
| List<String> manifestLists = getManifestListPaths(table); | ||
| List<String> manifestLists = getManifestListPaths(table.snapshots()); | ||
| return spark.createDataset(manifestLists, Encoders.STRING()).toDF("file_path"); | ||
| } | ||
|
|
||
| protected Dataset<Row> buildManifestListDF(SparkSession spark, String metadataFileLocation) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You cannot pass a pure table name here since we aren't looking up the table using Spark, this path is for metadataFileLocation based tables only. |
||
| StaticTableOperations ops = new StaticTableOperations(metadataFileLocation, table().io()); | ||
| return buildManifestListDF(spark, new BaseTable(ops, table().toString())); | ||
| } | ||
|
|
||
| protected Dataset<Row> buildOtherMetadataFileDF(SparkSession spark, TableOperations ops) { | ||
| List<String> otherMetadataFiles = getOtherMetadataFilePaths(ops); | ||
| return spark.createDataset(otherMetadataFiles, Encoders.STRING()).toDF("file_path"); | ||
| } | ||
|
|
||
| protected Dataset<Row> buildValidMetadataFileDF(SparkSession spark, Table table, TableOperations ops) { | ||
| Dataset<Row> manifestDF = buildManifestFileDF(spark); | ||
| Dataset<Row> manifestDF = buildManifestFileDF(spark, table.toString()); | ||
| Dataset<Row> manifestListDF = buildManifestListDF(spark, table); | ||
| Dataset<Row> otherMetadataFileDF = buildOtherMetadataFileDF(spark, ops); | ||
|
|
||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We add these 2 arg versions so that we can specify metadata Json files directly, the single arg versions just use the current table state as before.