-
Notifications
You must be signed in to change notification settings - Fork 3k
Spark: Ensure that partition stats files are considered for GC procedures #9284
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,13 +133,13 @@ public static List<String> manifestListLocations(Table table, Set<Long> snapshot | |
| } | ||
|
|
||
| /** | ||
| * Returns locations of statistics files in a table. | ||
| * Returns locations of all statistics files in a table. | ||
| * | ||
| * @param table table for which statistics files needs to be listed | ||
| * @return the location of statistics files | ||
| */ | ||
| public static List<String> statisticsFilesLocations(Table table) { | ||
| return statisticsFilesLocations(table, statisticsFile -> true); | ||
| return statisticsFilesLocationsForSnapshots(table, null); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -148,12 +148,50 @@ public static List<String> statisticsFilesLocations(Table table) { | |
| * @param table table for which statistics files needs to be listed | ||
| * @param predicate predicate for filtering the statistics files | ||
| * @return the location of statistics files | ||
| * @deprecated since 1.5.0, will be removed in 1.6.0; use the {@code | ||
| * statisticsFilesLocationsForSnapshots(table, snapshotIds)} instead. | ||
| */ | ||
| @Deprecated | ||
| public static List<String> statisticsFilesLocations( | ||
| Table table, Predicate<StatisticsFile> predicate) { | ||
| return table.statisticsFiles().stream() | ||
| .filter(predicate) | ||
| .map(StatisticsFile::path) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns locations of all statistics files for a table matching the given snapshot IDs. | ||
| * | ||
| * @param table table for which statistics files needs to be listed | ||
| * @param snapshotIds ids of snapshots for which statistics files will be returned. If null, | ||
| * statistics files for all the snapshots will be returned. | ||
| * @return the location of statistics files | ||
| */ | ||
| public static List<String> statisticsFilesLocationsForSnapshots( | ||
|
Contributor
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. What do you think about calling it
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. The deprecated method already has a name Hence, I had to keep different name. |
||
| Table table, Set<Long> snapshotIds) { | ||
| List<String> statsFileLocations = Lists.newArrayList(); | ||
|
|
||
| Predicate<StatisticsFile> statsFilePredicate; | ||
aokolnychyi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Predicate<PartitionStatisticsFile> partitionStatsFilePredicate; | ||
| if (snapshotIds == null) { | ||
aokolnychyi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| statsFilePredicate = file -> true; | ||
| partitionStatsFilePredicate = file -> true; | ||
| } else { | ||
| statsFilePredicate = file -> snapshotIds.contains(file.snapshotId()); | ||
| partitionStatsFilePredicate = file -> snapshotIds.contains(file.snapshotId()); | ||
| } | ||
|
|
||
| table.statisticsFiles().stream() | ||
| .filter(statsFilePredicate) | ||
| .map(StatisticsFile::path) | ||
| .forEach(statsFileLocations::add); | ||
|
|
||
| table.partitionStatisticsFiles().stream() | ||
| .filter(partitionStatsFilePredicate) | ||
| .map(PartitionStatisticsFile::path) | ||
| .forEach(statsFileLocations::add); | ||
|
|
||
| return statsFileLocations; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * 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.extensions; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.UUID; | ||
| import org.apache.iceberg.ImmutableGenericPartitionStatisticsFile; | ||
| import org.apache.iceberg.PartitionStatisticsFile; | ||
| import org.apache.iceberg.io.FileIO; | ||
| import org.apache.iceberg.io.PositionOutputStream; | ||
|
|
||
| public class ProcedureUtil { | ||
|
|
||
| private ProcedureUtil() {} | ||
|
|
||
| static PartitionStatisticsFile writePartitionStatsFile( | ||
| long snapshotId, String statsLocation, FileIO fileIO) { | ||
| PositionOutputStream positionOutputStream; | ||
| try { | ||
| positionOutputStream = fileIO.newOutputFile(statsLocation).create(); | ||
| positionOutputStream.close(); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| } | ||
|
|
||
| return ImmutableGenericPartitionStatisticsFile.builder() | ||
| .snapshotId(snapshotId) | ||
| .fileSizeInBytes(42L) | ||
| .path(statsLocation) | ||
| .build(); | ||
| } | ||
|
|
||
| static String statsFileLocation(String tableLocation) { | ||
| String statsFileName = "stats-file-" + UUID.randomUUID(); | ||
| return tableLocation.replaceFirst("file:", "") + "/metadata/" + statsFileName; | ||
| } | ||
| } |
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.
can't use the
Predicate<StatisticsFile>for partition stats. Hence, deprecated and introduced snapshot id based input like other methods in this class (manifest list, manifest etc)