-
Notifications
You must be signed in to change notification settings - Fork 5.5k
feat: Distributed Procedure Support Part 2/X - iceberg part changes #26374
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
Open
hantangwangd
wants to merge
4
commits into
prestodb:master
Choose a base branch
from
hantangwangd:support_call_distributed_procedure_part2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f584e47
Refactor Iceberg connector to support call distributed procedure
hantangwangd 34ad180
Support Iceberg procedure `rewrite_data_files`
hantangwangd 68a3b76
[native] Relevant changes of presto protocol for iceberg
hantangwangd 9959e0c
Address review comments
hantangwangd 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
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
137 changes: 137 additions & 0 deletions
137
...ceberg/src/main/java/com/facebook/presto/iceberg/CallDistributedProcedureSplitSource.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,137 @@ | ||
| /* | ||
| * Licensed 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 com.facebook.presto.iceberg; | ||
|
|
||
| import com.facebook.presto.iceberg.delete.DeleteFile; | ||
| import com.facebook.presto.spi.ConnectorSession; | ||
| import com.facebook.presto.spi.ConnectorSplit; | ||
| import com.facebook.presto.spi.ConnectorSplitSource; | ||
| import com.facebook.presto.spi.SplitWeight; | ||
| import com.facebook.presto.spi.connector.ConnectorPartitionHandle; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.io.Closer; | ||
| import org.apache.iceberg.FileScanTask; | ||
| import org.apache.iceberg.PartitionSpec; | ||
| import org.apache.iceberg.PartitionSpecParser; | ||
| import org.apache.iceberg.TableScan; | ||
| import org.apache.iceberg.io.CloseableIterable; | ||
| import org.apache.iceberg.io.CloseableIterator; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.function.Consumer; | ||
|
|
||
| import static com.facebook.presto.hive.HiveCommonSessionProperties.getAffinitySchedulingFileSectionSize; | ||
| import static com.facebook.presto.hive.HiveCommonSessionProperties.getNodeSelectionStrategy; | ||
| import static com.facebook.presto.iceberg.FileFormat.fromIcebergFileFormat; | ||
| import static com.facebook.presto.iceberg.IcebergUtil.getDataSequenceNumber; | ||
| import static com.facebook.presto.iceberg.IcebergUtil.getPartitionKeys; | ||
| import static com.facebook.presto.iceberg.IcebergUtil.partitionDataFromStructLike; | ||
| import static com.google.common.collect.ImmutableList.toImmutableList; | ||
| import static com.google.common.collect.Iterators.limit; | ||
| import static java.util.Objects.requireNonNull; | ||
| import static java.util.concurrent.CompletableFuture.completedFuture; | ||
|
|
||
| public class CallDistributedProcedureSplitSource | ||
| implements ConnectorSplitSource | ||
| { | ||
| private CloseableIterator<FileScanTask> fileScanTaskIterator; | ||
| private Optional<Consumer<FileScanTask>> fileScanTaskConsumer; | ||
|
|
||
| private final TableScan tableScan; | ||
| private final Closer closer = Closer.create(); | ||
| private final double minimumAssignedSplitWeight; | ||
| private final ConnectorSession session; | ||
|
|
||
| public CallDistributedProcedureSplitSource( | ||
| ConnectorSession session, | ||
| TableScan tableScan, | ||
| CloseableIterable<FileScanTask> fileScanTaskIterable, | ||
| Optional<Consumer<FileScanTask>> fileScanTaskConsumer, | ||
| double minimumAssignedSplitWeight) | ||
| { | ||
| this.session = requireNonNull(session, "session is null"); | ||
| this.tableScan = requireNonNull(tableScan, "tableScan is null"); | ||
| this.fileScanTaskIterator = fileScanTaskIterable.iterator(); | ||
| this.fileScanTaskConsumer = requireNonNull(fileScanTaskConsumer, "fileScanTaskConsumer is null"); | ||
| this.minimumAssignedSplitWeight = minimumAssignedSplitWeight; | ||
| closer.register(fileScanTaskIterator); | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableFuture<ConnectorSplitBatch> getNextBatch(ConnectorPartitionHandle partitionHandle, int maxSize) | ||
| { | ||
| // TODO: move this to a background thread | ||
| List<ConnectorSplit> splits = new ArrayList<>(); | ||
| Iterator<FileScanTask> iterator = limit(fileScanTaskIterator, maxSize); | ||
| while (iterator.hasNext()) { | ||
| FileScanTask task = iterator.next(); | ||
| fileScanTaskConsumer.ifPresent(consumer -> consumer.accept(task)); | ||
| splits.add(toIcebergSplit(task)); | ||
| } | ||
| return completedFuture(new ConnectorSplitBatch(splits, isFinished())); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isFinished() | ||
| { | ||
| return !fileScanTaskIterator.hasNext(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() | ||
| { | ||
| try { | ||
| closer.close(); | ||
| // TODO: remove this after org.apache.iceberg.io.CloseableIterator'withClose | ||
| // correct release resources holds by iterator. | ||
| fileScanTaskIterator = CloseableIterator.empty(); | ||
| } | ||
| catch (IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| } | ||
| } | ||
|
|
||
| private ConnectorSplit toIcebergSplit(FileScanTask task) | ||
| { | ||
| PartitionSpec spec = task.spec(); | ||
| Optional<PartitionData> partitionData = partitionDataFromStructLike(spec, task.file().partition()); | ||
|
|
||
| // TODO: We should leverage residual expression and convert that to TupleDomain. | ||
| // The predicate here is used by readers for predicate push down at reader level, | ||
| // so when we do not use residual expression, we are just wasting CPU cycles | ||
| // on reader side evaluating a condition that we know will always be true. | ||
|
|
||
| return new IcebergSplit( | ||
| task.file().path().toString(), | ||
| task.start(), | ||
| task.length(), | ||
| fromIcebergFileFormat(task.file().format()), | ||
| ImmutableList.of(), | ||
| getPartitionKeys(task), | ||
| PartitionSpecParser.toJson(spec), | ||
| partitionData.map(PartitionData::toJson), | ||
| getNodeSelectionStrategy(session), | ||
| SplitWeight.fromProportion(Math.min(Math.max((double) task.length() / tableScan.targetSplitSize(), minimumAssignedSplitWeight), 1.0)), | ||
| task.deletes().stream().map(DeleteFile::fromIceberg).collect(toImmutableList()), | ||
| Optional.empty(), | ||
| getDataSequenceNumber(task.file()), | ||
| getAffinitySchedulingFileSectionSize(session).toBytes()); | ||
| } | ||
| } |
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
53 changes: 53 additions & 0 deletions
53
...-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergDistributedProcedureHandle.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,53 @@ | ||
| /* | ||
| * Licensed 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 com.facebook.presto.iceberg; | ||
|
|
||
| import com.facebook.presto.hive.HiveCompressionCodec; | ||
| import com.facebook.presto.spi.ConnectorDistributedProcedureHandle; | ||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.google.common.collect.ImmutableList; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class IcebergDistributedProcedureHandle | ||
| extends IcebergWritableTableHandle | ||
| implements ConnectorDistributedProcedureHandle | ||
| { | ||
| @JsonCreator | ||
| public IcebergDistributedProcedureHandle( | ||
| @JsonProperty("schemaName") String schemaName, | ||
| @JsonProperty("tableName") IcebergTableName tableName, | ||
| @JsonProperty("schema") PrestoIcebergSchema schema, | ||
| @JsonProperty("partitionSpec") PrestoIcebergPartitionSpec partitionSpec, | ||
| @JsonProperty("inputColumns") List<IcebergColumnHandle> inputColumns, | ||
| @JsonProperty("outputPath") String outputPath, | ||
| @JsonProperty("fileFormat") FileFormat fileFormat, | ||
| @JsonProperty("compressionCodec") HiveCompressionCodec compressionCodec, | ||
| @JsonProperty("storageProperties") Map<String, String> storageProperties) | ||
| { | ||
| super( | ||
| schemaName, | ||
| tableName, | ||
| schema, | ||
| partitionSpec, | ||
| inputColumns, | ||
| outputPath, | ||
| fileFormat, | ||
| compressionCodec, | ||
| storageProperties, | ||
| ImmutableList.of()); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.