-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Spark: Add an action to rewrite equality deletes #2364
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
6624df5
a347dbe
ea5e6f9
f7b2543
f4a23c1
186151f
370cc95
4369d88
bec8e30
792c0a9
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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * 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.actions; | ||
|
|
||
| import java.util.Set; | ||
| import org.apache.iceberg.DeleteFile; | ||
|
|
||
| public interface RewriteDeletes extends SnapshotUpdate<RewriteDeletes, RewriteDeletes.Result> { | ||
|
|
||
| /** | ||
| * Set the implementation class name of rewrite delete strategy | ||
| * | ||
| * @return this for method chaining | ||
| */ | ||
| RewriteDeletes strategy(String strategyImpl); | ||
|
|
||
| /** | ||
| * The action result that contains a summary of the execution. | ||
| */ | ||
| interface Result { | ||
| /** | ||
| * Returns the delete files to rewrite. | ||
| */ | ||
| Set<DeleteFile> deletedFiles(); | ||
|
|
||
| /** | ||
| * Returns the added delete files. | ||
| */ | ||
| Set<DeleteFile> addedFiles(); | ||
| } | ||
| } |
| 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.actions; | ||
|
|
||
| import java.util.Set; | ||
| import org.apache.iceberg.DeleteFile; | ||
|
|
||
| public class BaseRewriteDeletesResult implements RewriteDeletes.Result { | ||
|
|
||
| private final Set<DeleteFile> deletesToReplace; | ||
| private final Set<DeleteFile> deletesToAdd; | ||
|
|
||
| public BaseRewriteDeletesResult(Set<DeleteFile> deletesToReplace, Set<DeleteFile> deletesToAdd) { | ||
| this.deletesToReplace = deletesToReplace; | ||
| this.deletesToAdd = deletesToAdd; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<DeleteFile> deletedFiles() { | ||
| return deletesToReplace; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<DeleteFile> addedFiles() { | ||
| return deletesToAdd; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * 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.actions; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import org.apache.iceberg.DeleteFile; | ||
| import org.apache.iceberg.FileScanTask; | ||
| import org.apache.iceberg.Table; | ||
|
|
||
| public interface RewriteDeleteStrategy { | ||
|
|
||
| /** | ||
| * Returns the name of this rewrite deletes strategy | ||
| */ | ||
| String name(); | ||
|
|
||
| /** | ||
| * Returns the table being modified by this rewrite strategy | ||
| */ | ||
| Table table(); | ||
|
|
||
| /** | ||
| * Select the deletes to rewrite. | ||
| * | ||
| * @param dataFiles iterable of FileScanTasks for data files in a given partition | ||
| * @return iterable of original delete file to be replaced. | ||
| */ | ||
| Iterable<DeleteFile> selectDeletesToRewrite(Iterable<FileScanTask> dataFiles); | ||
|
|
||
| /** | ||
| * Define how to rewrite the deletes. | ||
| * | ||
| * @param deleteFilesToRewrite a group of files to be rewritten together | ||
| * @return iterable of delete files used to replace the original delete files. | ||
| */ | ||
| Set<DeleteFile> rewriteDeletes(Set<DeleteFile> deleteFilesToRewrite); | ||
|
|
||
| /** | ||
| * Groups file scans into lists which will be processed in a single executable unit. Each group will end up being | ||
| * committed as an independent set of changes. This creates the jobs which will eventually be run as by the underlying | ||
| * Action. | ||
| * | ||
| * @param deleteFiles iterable of DeleteFile to be rewritten | ||
| * @return iterable of lists of FileScanTasks which will be processed together | ||
| */ | ||
| Iterable<Set<DeleteFile>> planDeleteGroups(Iterable<DeleteFile> deleteFiles); | ||
|
|
||
| /** | ||
| * Sets options to be used with this strategy | ||
| */ | ||
| RewriteDeleteStrategy options(Map<String, String> options); | ||
|
|
||
| /** | ||
| * Returns a set of options which this rewrite strategy can use. This is an allowed-list and any options not | ||
| * specified here will be rejected at runtime. | ||
| */ | ||
| Set<String> validOptions(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,16 +19,29 @@ | |
|
|
||
| package org.apache.iceberg.util; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
| import java.util.Map; | ||
| import java.util.function.Function; | ||
| import org.apache.iceberg.BaseCombinedScanTask; | ||
| import org.apache.iceberg.CombinedScanTask; | ||
| import org.apache.iceberg.FileScanTask; | ||
| import org.apache.iceberg.PartitionSpec; | ||
| import org.apache.iceberg.io.CloseableIterable; | ||
| import org.apache.iceberg.io.CloseableIterator; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.FluentIterable; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ListMultimap; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Maps; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Multimaps; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class TableScanUtil { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(TableScanUtil.class); | ||
|
|
||
| private TableScanUtil() { | ||
| } | ||
|
|
||
|
|
@@ -64,4 +77,21 @@ public static CloseableIterable<CombinedScanTask> planTasks(CloseableIterable<Fi | |
| splitFiles), | ||
| BaseCombinedScanTask::new); | ||
| } | ||
|
|
||
| public static Map<StructLikeWrapper, Collection<FileScanTask>> groupTasksByPartition( | ||
|
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. maybe I missed some other place, I only see it used in the strategy class, why is it not a private method?
Member
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. Moving the common |
||
| PartitionSpec spec, | ||
|
Member
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. I don't think it's correct to use the table latest partition spec to group the |
||
| CloseableIterator<FileScanTask> tasksIter) { | ||
| ListMultimap<StructLikeWrapper, FileScanTask> tasksGroupedByPartition = Multimaps.newListMultimap( | ||
| Maps.newHashMap(), Lists::newArrayList); | ||
| try (CloseableIterator<FileScanTask> iterator = tasksIter) { | ||
| iterator.forEachRemaining(task -> { | ||
| StructLikeWrapper structLike = StructLikeWrapper.forType(spec.partitionType()).set(task.file().partition()); | ||
| tasksGroupedByPartition.put(structLike, task); | ||
| }); | ||
| } catch (IOException e) { | ||
| LOG.warn("Failed to close task iterator", e); | ||
| } | ||
|
|
||
| return tasksGroupedByPartition.asMap(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.