-
Notifications
You must be signed in to change notification settings - Fork 3k
API: Refactor FileScanTask #5077
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
aokolnychyi
merged 8 commits into
apache:master
from
aokolnychyi:refactor-file-scan-task
Jun 28, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
79699fc
API: Refactor FileScanTask
aokolnychyi 895f08b
Review feedback, round 1
aokolnychyi 0786c1e
Fix typo
aokolnychyi 9d7a79b
Rename method
aokolnychyi 3e7f6dd
Feedback
aokolnychyi f393393
More changes
aokolnychyi 1cf1caf
Use Collection
aokolnychyi 75e4589
Clean up
aokolnychyi 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
62 changes: 62 additions & 0 deletions
62
api/src/main/java/org/apache/iceberg/BaseScanTaskGroup.java
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 |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Joiner; | ||
| import org.apache.iceberg.relocated.com.google.common.base.MoreObjects; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
|
|
||
| public class BaseScanTaskGroup<T extends ScanTask> implements ScanTaskGroup<T> { | ||
| private final Object[] tasks; | ||
| private transient volatile List<T> taskList; | ||
|
|
||
| public BaseScanTaskGroup(Collection<T> tasks) { | ||
| Preconditions.checkNotNull(tasks, "tasks cannot be null"); | ||
| this.tasks = tasks.toArray(); | ||
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings("unchecked") | ||
| public Collection<T> tasks() { | ||
| if (taskList == null) { | ||
| synchronized (this) { | ||
| if (taskList == null) { | ||
| ImmutableList.Builder<T> listBuilder = ImmutableList.builderWithExpectedSize(tasks.length); | ||
| for (Object task : tasks) { | ||
| listBuilder.add((T) task); | ||
| } | ||
| taskList = listBuilder.build(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return taskList; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return MoreObjects.toStringHelper(this) | ||
| .add("tasks", Joiner.on(", ").join(tasks)) | ||
| .toString(); | ||
| } | ||
| } | ||
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
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 |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| import org.apache.iceberg.expressions.Expression; | ||
|
|
||
| /** | ||
| * A scan task over a range of bytes in a content file. | ||
| * | ||
| * @param <F> the Java class of the content file | ||
| */ | ||
| public interface ContentScanTask<F extends ContentFile<F>> extends ScanTask { | ||
aokolnychyi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * The {@link ContentFile file} to scan. | ||
| * | ||
| * @return the file to scan | ||
| */ | ||
| F file(); | ||
|
|
||
| /** | ||
| * The {@link PartitionSpec spec} used to store this file. | ||
| * | ||
| * @return the partition spec from this file's manifest | ||
| */ | ||
| PartitionSpec spec(); | ||
|
|
||
| /** | ||
| * The starting position of this scan range in the file. | ||
| * | ||
| * @return the start position of this scan range | ||
| */ | ||
| long start(); | ||
|
|
||
| /** | ||
| * The number of bytes to scan from the {@link #start()} position in the file. | ||
| * | ||
| * @return the length of this scan range in bytes | ||
| */ | ||
| long length(); | ||
|
|
||
| /** | ||
| * Returns the residual expression that should be applied to rows in this file scan. | ||
| * <p> | ||
| * The residual expression for a file is a filter expression created by partially evaluating the scan's filter | ||
| * using the file's partition data. | ||
| * | ||
| * @return a residual expression to apply to rows from this scan | ||
| */ | ||
| Expression residual(); | ||
| } | ||
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
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
45 changes: 45 additions & 0 deletions
45
api/src/main/java/org/apache/iceberg/MergeableScanTask.java
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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| /** | ||
| * A scan task that can be potentially merged with other scan tasks. | ||
| * | ||
| * @param <ThisT> the child Java API class | ||
| */ | ||
| public interface MergeableScanTask<ThisT> extends ScanTask { | ||
|
Contributor
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. I kept it separate from |
||
| /** | ||
| * Checks if this task can merge with a given task. | ||
| * | ||
| * @param other another task | ||
| * @return whether the tasks can be merged | ||
| */ | ||
| boolean canMerge(ScanTask other); | ||
|
|
||
| /** | ||
| * Merges this task with a given task. | ||
| * <p> | ||
| * Note this method will be called only if {@link #canMerge(ScanTask)} returns true. | ||
| * | ||
| * @param other another task | ||
| * @return a new merged task | ||
| */ | ||
| ThisT merge(ScanTask other); | ||
| } | ||
Oops, something went wrong.
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.
I don't have a problem with this, but do you really expect this to be accessed from different threads after construction?
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.
I did it just in case given how hard it would be debug such issues. Better be safe than sorry :)