-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,984 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
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
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
106 changes: 106 additions & 0 deletions
106
core/src/main/java/org/apache/iceberg/actions/RewritePositionDeleteGroup.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,106 @@ | ||
/* | ||
* 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.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import org.apache.iceberg.DeleteFile; | ||
import org.apache.iceberg.PositionDeletesScanTask; | ||
import org.apache.iceberg.relocated.com.google.common.base.MoreObjects; | ||
import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
|
||
/** | ||
* Container class representing a set of position delete files to be rewritten by a RewriteAction | ||
* and the new files which have been written by the action. | ||
*/ | ||
public class RewritePositionDeleteGroup { | ||
private final RewritePositionDeleteFiles.PositionDeleteGroupInfo info; | ||
private final List<PositionDeletesScanTask> positionDeletesScanTasks; | ||
|
||
private Set<DeleteFile> addedDeleteFiles = Collections.emptySet(); | ||
|
||
public RewritePositionDeleteGroup( | ||
RewritePositionDeleteFiles.PositionDeleteGroupInfo info, | ||
List<PositionDeletesScanTask> fileScanTasks) { | ||
this.info = info; | ||
this.positionDeletesScanTasks = fileScanTasks; | ||
} | ||
|
||
public RewritePositionDeleteFiles.PositionDeleteGroupInfo info() { | ||
return info; | ||
} | ||
|
||
public List<PositionDeletesScanTask> scans() { | ||
return positionDeletesScanTasks; | ||
} | ||
|
||
public void setOutputFiles(Set<DeleteFile> files) { | ||
addedDeleteFiles = files; | ||
} | ||
|
||
public Set<DeleteFile> rewrittenDeleteFiles() { | ||
return scans().stream().map(PositionDeletesScanTask::file).collect(Collectors.toSet()); | ||
} | ||
|
||
public Set<DeleteFile> addedDeleteFiles() { | ||
return addedDeleteFiles; | ||
} | ||
|
||
public RewritePositionDeleteFiles.PositionDeleteGroupRewriteResult asResult() { | ||
Preconditions.checkState( | ||
addedDeleteFiles != null, "Cannot get result, Group was never rewritten"); | ||
long addedBytes = addedDeleteFiles.stream().mapToLong(DeleteFile::fileSizeInBytes).sum(); | ||
|
||
return ImmutablePositionDeleteGroupRewriteResult.builder() | ||
.info(info) | ||
.addedDeleteFilesCount(addedDeleteFiles.size()) | ||
.rewrittenDeleteFilesCount(positionDeletesScanTasks.size()) | ||
.rewrittenBytesCount(rewrittenBytes()) | ||
.addedBytesCount(addedBytes()) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("info", info) | ||
.add("numRewrittenPositionDeleteFiles", positionDeletesScanTasks.size()) | ||
.add( | ||
"numAddedPositionDeleteFiles", | ||
addedDeleteFiles == null | ||
? "Rewrite Incomplete" | ||
: Integer.toString(addedDeleteFiles.size())) | ||
.add("numRewrittenBytes", rewrittenBytes()) | ||
.toString(); | ||
} | ||
|
||
public long rewrittenBytes() { | ||
return positionDeletesScanTasks.stream().mapToLong(PositionDeletesScanTask::length).sum(); | ||
} | ||
|
||
public long addedBytes() { | ||
return addedDeleteFiles.stream().mapToLong(DeleteFile::fileSizeInBytes).sum(); | ||
} | ||
|
||
public int numDeleteFiles() { | ||
return positionDeletesScanTasks.size(); | ||
} | ||
} |
Oops, something went wrong.