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
Refactor FilteredManifest and ManifestGroup #735
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
03a96dc
[Refactor]: Remove duplication form FilteredManifest
rdsr 4f8d017
Address review comments
rdsr dd34f48
Address review comments - take 2
rdsr 0a707de
Address review comments - take 3
rdsr 94c1450
Address review comments - take 4
rdsr File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
package org.apache.iceberg; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.Iterators; | ||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Sets; | ||
import java.io.IOException; | ||
|
@@ -95,59 +94,33 @@ CloseableIterable<ManifestEntry> allEntries() { | |
Evaluator evaluator = evaluator(); | ||
InclusiveMetricsEvaluator metricsEvaluator = metricsEvaluator(); | ||
|
||
return CloseableIterable.filter(reader.entries(projection(fileSchema, columns, caseSensitive)), | ||
// ensure stats columns are present for metrics evaluation | ||
boolean requireStatsProjection = requireStatsProjection(); | ||
Collection<String> projectColumns = requireStatsProjection ? withStatsColumns(columns) : columns; | ||
|
||
return CloseableIterable.filter( | ||
reader.entries(projection(fileSchema, projectColumns, caseSensitive)), | ||
entry -> entry != null && | ||
evaluator.eval(entry.file().partition()) && | ||
metricsEvaluator.eval(entry.file())); | ||
|
||
} else { | ||
return reader.entries(projection(fileSchema, columns, caseSensitive)); | ||
} | ||
} | ||
|
||
CloseableIterable<ManifestEntry> liveEntries() { | ||
if ((rowFilter != null && rowFilter != Expressions.alwaysTrue()) || | ||
(partFilter != null && partFilter != Expressions.alwaysTrue())) { | ||
Evaluator evaluator = evaluator(); | ||
InclusiveMetricsEvaluator metricsEvaluator = metricsEvaluator(); | ||
|
||
return CloseableIterable.filter(reader.entries(projection(fileSchema, columns, caseSensitive)), | ||
entry -> entry != null && | ||
entry.status() != Status.DELETED && | ||
evaluator.eval(entry.file().partition()) && | ||
metricsEvaluator.eval(entry.file())); | ||
|
||
} else { | ||
return CloseableIterable.filter(reader.entries(projection(fileSchema, columns, caseSensitive)), | ||
entry -> entry != null && entry.status() != Status.DELETED); | ||
} | ||
return CloseableIterable.filter(allEntries(), entry -> entry != null && entry.status() != Status.DELETED); | ||
} | ||
|
||
/** | ||
* @return an Iterator of DataFile. Makes defensive copies of files before returning | ||
*/ | ||
@Override | ||
public Iterator<DataFile> iterator() { | ||
if ((rowFilter != null && rowFilter != Expressions.alwaysTrue()) || | ||
(partFilter != null && partFilter != Expressions.alwaysTrue())) { | ||
Evaluator evaluator = evaluator(); | ||
InclusiveMetricsEvaluator metricsEvaluator = metricsEvaluator(); | ||
|
||
// ensure stats columns are present for metrics evaluation | ||
List<String> projectColumns = Lists.newArrayList(columns); | ||
projectColumns.addAll(STATS_COLUMNS); // order doesn't matter | ||
|
||
// if no stats columns were projected, drop them | ||
boolean dropStats = Sets.intersection(Sets.newHashSet(columns), STATS_COLUMNS).isEmpty(); | ||
|
||
return Iterators.transform( | ||
Iterators.filter(reader.iterator(partFilter, projection(fileSchema, projectColumns, caseSensitive)), | ||
input -> input != null && | ||
evaluator.eval(input.partition()) && | ||
metricsEvaluator.eval(input)), | ||
dropStats ? DataFile::copyWithoutStats : DataFile::copy); | ||
|
||
if (dropStats()) { | ||
return CloseableIterable.transform(liveEntries(), e -> e.file().copyWithoutStats()).iterator(); | ||
} else { | ||
return Iterators.transform( | ||
reader.iterator(partFilter, projection(fileSchema, columns, caseSensitive)), | ||
DataFile::copy); | ||
return CloseableIterable.transform(liveEntries(), e -> e.file().copy()).iterator(); | ||
} | ||
} | ||
|
||
|
@@ -193,4 +166,29 @@ private InclusiveMetricsEvaluator metricsEvaluator() { | |
} | ||
return lazyMetricsEvaluator; | ||
} | ||
|
||
private boolean requireStatsProjection() { | ||
// Make sure we have all stats columns for metrics evaluator | ||
return rowFilter != Expressions.alwaysTrue() && | ||
!columns.containsAll(ManifestReader.ALL_COLUMNS) && | ||
!columns.containsAll(STATS_COLUMNS); | ||
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 like how straight-forward this is now. |
||
} | ||
|
||
private boolean dropStats() { | ||
// Make sure we only drop all stats if we had projected all stats | ||
// We do not drop stats even if we had partially added some stats columns | ||
return rowFilter != Expressions.alwaysTrue() && | ||
!columns.containsAll(ManifestReader.ALL_COLUMNS) && | ||
Sets.intersection(Sets.newHashSet(columns), STATS_COLUMNS).isEmpty(); | ||
} | ||
|
||
private static Collection<String> withStatsColumns(Collection<String> columns) { | ||
if (columns.containsAll(ManifestReader.ALL_COLUMNS)) { | ||
return columns; | ||
} else { | ||
List<String> projectColumns = Lists.newArrayList(columns); | ||
projectColumns.addAll(STATS_COLUMNS); // order doesn't matter | ||
rdsr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return projectColumns; | ||
} | ||
} | ||
} |
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
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.
+1