-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Flink: Incrementally rewrite data files in streaming. #3323
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
Closed
Closed
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
24d8691
Flink: init streaming rewrite.
Reo-LEI 4d94772
Merge remote-tracking branch 'community/master' into flink-streaming-…
Reo-LEI c9c125b
refactor rewrite files committer.
Reo-LEI 1df1814
Add rewrite parallelism config.
Reo-LEI d96704f
Add unittest for stream rewriter.
Reo-LEI 98e2832
Add unittest for rewrite rile committer.
Reo-LEI 0ff66bf
Add unittest for file committer.
Reo-LEI 69689e5
Merge remote-tracking branch 'community/master' into flink-streaming-…
Reo-LEI c5ca44b
Fix unittest.
Reo-LEI 47f4765
Fix unittest.
Reo-LEI d8a7f69
Fix unittest.
Reo-LEI 6439bbb
Fix rewrite commit error when no rewrite result.
Reo-LEI 5a1739d
Merge remote-tracking branch 'community/master' into flink-streaming-…
Reo-LEI 8fadd91
Merge remote-tracking branch 'community/master' into flink-streaming-…
Reo-LEI 971d1c7
Move to flink v1.13.
Reo-LEI 682a2b2
Wrap PartitionData by StructLikeWrapper.
Reo-LEI 11814e9
Merge branch 'apache:master' into flink-streaming-rewrite
Reo-LEI 25a2a90
support to emit all needed files for restore and concurrent writer.
Reo-LEI 2a52cd5
Fix unittest.
Reo-LEI 189c946
Merge remote-tracking branch 'origin/master' into flink-streaming-rew…
Reo-LEI 268392a
fix class not found.
Reo-LEI 25a93e0
not swallow exception when rewrite fail.
Reo-LEI 328c876
port to flink 0.14
Reo-LEI 1e5c7a5
Flink: fix streaming rewrite kryo serialization error for partition b…
Reo-LEI 7d131f3
Flink: refactor streaming rewrite.
Reo-LEI 521d62f
Merge branch 'master' into flink-streaming-rewrite
Reo-LEI 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
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
125 changes: 125 additions & 0 deletions
125
core/src/main/java/org/apache/iceberg/StaticDataTableScan.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,125 @@ | ||
| /* | ||
| * 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.List; | ||
| import org.apache.iceberg.events.Listeners; | ||
| import org.apache.iceberg.events.ScanEvent; | ||
| import org.apache.iceberg.expressions.Expression; | ||
| import org.apache.iceberg.io.CloseableIterable; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
| import org.apache.iceberg.util.ThreadPools; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class StaticDataTableScan extends DataTableScan { | ||
| private static final Logger LOG = LoggerFactory.getLogger(StaticDataTableScan.class); | ||
|
|
||
| private static final long DUMMY_SNAPSHOT_ID = 0L; | ||
|
|
||
| private final List<ManifestFile> dataManifests; | ||
| private final List<ManifestFile> deleteManifests; | ||
|
|
||
| private StaticDataTableScan(Table table, | ||
| TableOperations ops) { | ||
| super(ops, table); | ||
| this.dataManifests = Lists.newArrayList(); | ||
| this.deleteManifests = Lists.newArrayList(); | ||
| } | ||
|
|
||
| @Override | ||
| public TableScan useSnapshot(long scanSnapshotId) { | ||
| throw new UnsupportedOperationException(String.format( | ||
| "Scan table using scan snapshot id %s is not supported", scanSnapshotId)); | ||
| } | ||
|
|
||
| @Override | ||
| public TableScan asOfTime(long timestampMillis) { | ||
| throw new UnsupportedOperationException(String.format( | ||
| "Scan table as of time %s is not supported", timestampMillis)); | ||
| } | ||
|
|
||
| @Override | ||
| public TableScan appendsBetween(long fromSnapshotId, long toSnapshotId) { | ||
| throw new UnsupportedOperationException("Incremental scan is not supported"); | ||
| } | ||
|
|
||
| @Override | ||
| public TableScan appendsAfter(long fromSnapshotId) { | ||
| throw new UnsupportedOperationException("Incremental scan is not supported"); | ||
| } | ||
|
|
||
| @Override | ||
| public Snapshot snapshot() { | ||
| return null; | ||
| } | ||
|
|
||
| public TableScan scan(Iterable<ManifestFile> newManifests) { | ||
| for (ManifestFile manifestFile : newManifests) { | ||
| Preconditions.checkArgument(manifestFile != null, "Cannot scan a null manifest file"); | ||
| switch (manifestFile.content()) { | ||
| case DATA: | ||
| dataManifests.add(manifestFile); | ||
| break; | ||
| case DELETES: | ||
| deleteManifests.add(manifestFile); | ||
| break; | ||
| default: throw new IllegalArgumentException("Unknown ManifestContent type: " + manifestFile.content()); | ||
| } | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public CloseableIterable<FileScanTask> planFiles() { | ||
| LOG.info("Scanning table {} partially with filter {}", table(), context().rowFilter()); | ||
|
|
||
| Listeners.notifyAll(new ScanEvent(table().name(), DUMMY_SNAPSHOT_ID, context().rowFilter(), schema())); | ||
|
Reo-LEI marked this conversation as resolved.
Outdated
|
||
|
|
||
| return planFiles(tableOps(), null, | ||
| context().rowFilter(), context().ignoreResiduals(), context().caseSensitive(), context().returnColumnStats()); | ||
| } | ||
|
|
||
| @Override | ||
| public CloseableIterable<FileScanTask> planFiles(TableOperations ops, Snapshot snapshot, Expression rowFilter, | ||
| boolean ignoreResiduals, boolean caseSensitive, boolean colStats) { | ||
| ManifestGroup manifestGroup = new ManifestGroup(ops.io(), dataManifests, deleteManifests) | ||
| .caseSensitive(caseSensitive) | ||
| .select(colStats ? SCAN_WITH_STATS_COLUMNS : SCAN_COLUMNS) | ||
| .filterData(rowFilter) | ||
| .specsById(ops.current().specsById()) | ||
| .ignoreDeleted(); | ||
|
|
||
| if (ignoreResiduals) { | ||
| manifestGroup = manifestGroup.ignoreResiduals(); | ||
| } | ||
|
|
||
| if (PLAN_SCANS_WITH_WORKER_POOL && dataManifests.size() > 1) { | ||
| manifestGroup = manifestGroup.planWith(ThreadPools.getWorkerPool()); | ||
| } | ||
|
|
||
| return manifestGroup.planFiles(); | ||
| } | ||
|
|
||
| public static StaticDataTableScan of(Table table, TableOperations ops) { | ||
| return new StaticDataTableScan(table, ops); | ||
| } | ||
| } | ||
114 changes: 114 additions & 0 deletions
114
flink/src/main/java/org/apache/iceberg/flink/sink/CommitResult.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,114 @@ | ||
| /* | ||
| * 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.flink.sink; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.Collection; | ||
| import org.apache.iceberg.DataFile; | ||
| import org.apache.iceberg.DeleteFile; | ||
| import org.apache.iceberg.StructLike; | ||
| import org.apache.iceberg.io.WriteResult; | ||
|
|
||
| class CommitResult implements Serializable { | ||
|
|
||
| private final long snapshotId; | ||
| private final long sequenceNumber; | ||
| private final int specId; | ||
| private final StructLike partition; | ||
| private final WriteResult writeResult; | ||
|
|
||
| private CommitResult(long snapshotId, | ||
| long sequenceNumber, | ||
| int specId, | ||
| StructLike partition, | ||
| WriteResult writeResult) { | ||
| this.snapshotId = snapshotId; | ||
| this.sequenceNumber = sequenceNumber; | ||
| this.specId = specId; | ||
| this.partition = partition; | ||
| this.writeResult = writeResult; | ||
| } | ||
|
|
||
| long snapshotId() { | ||
| return snapshotId; | ||
| } | ||
|
|
||
| long sequenceNumber() { | ||
| return sequenceNumber; | ||
| } | ||
|
|
||
| public int specId() { | ||
| return specId; | ||
| } | ||
|
|
||
| StructLike partition() { | ||
| return partition; | ||
| } | ||
|
|
||
| WriteResult writeResult() { | ||
| return writeResult; | ||
| } | ||
|
|
||
| static Builder builder(long snapshotId, long sequenceNumber) { | ||
| return new Builder(snapshotId, sequenceNumber); | ||
| } | ||
|
|
||
| static class Builder { | ||
|
|
||
| private final long snapshotId; | ||
| private final long sequenceNumber; | ||
| private int specId; | ||
| private StructLike partition; | ||
| private final WriteResult.Builder writeResult; | ||
|
|
||
| private Builder(long snapshotId, long sequenceNumber) { | ||
| this.snapshotId = snapshotId; | ||
| this.sequenceNumber = sequenceNumber; | ||
| this.specId = 0; | ||
| this.partition = null; | ||
| this.writeResult = WriteResult.builder(); | ||
| } | ||
|
|
||
| Builder partition(int newSpecId, StructLike newPartition) { | ||
| this.specId = newSpecId; | ||
| this.partition = newPartition; | ||
| return this; | ||
| } | ||
|
|
||
| Builder addDataFile(Collection<DataFile> files) { | ||
| writeResult.addDataFiles(files); | ||
| return this; | ||
| } | ||
|
|
||
| Builder addDeleteFile(Collection<DeleteFile> files) { | ||
| writeResult.addDeleteFiles(files); | ||
| return this; | ||
| } | ||
|
|
||
| Builder addReferencedDataFile(Collection<CharSequence> files) { | ||
| writeResult.addReferencedDataFiles(files); | ||
|
Reo-LEI marked this conversation as resolved.
Outdated
|
||
| return this; | ||
| } | ||
|
|
||
| CommitResult build() { | ||
| return new CommitResult(snapshotId, sequenceNumber, specId, partition, writeResult.build()); | ||
| } | ||
| } | ||
| } | ||
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.