-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[flink] Support stream read Chain Table #8262
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
yunfengzhou-hub
wants to merge
6
commits into
apache:master
Choose a base branch
from
yunfengzhou-hub:chain-table-streaming
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.
+2,523
−4
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
85e05e7
[flink] Support stream read Chain Table
yunfengzhou-hub 9098815
Fix comments
yunfengzhou-hub 4d1287d
Fix check for consumer mode
yunfengzhou-hub 7ad4c30
Fix leaking partition filter
yunfengzhou-hub 6140c4b
Fix document for changelog and consumer
yunfengzhou-hub 39d46f1
Fix handling strategy for fallback split
yunfengzhou-hub 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
219 changes: 219 additions & 0 deletions
219
paimon-core/src/main/java/org/apache/paimon/table/ChainTableFileStoreTable.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,219 @@ | ||
| /* | ||
| * 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.paimon.table; | ||
|
|
||
| import org.apache.paimon.CoreOptions; | ||
| import org.apache.paimon.CoreOptions.StartupMode; | ||
| import org.apache.paimon.data.InternalRow; | ||
| import org.apache.paimon.disk.IOManager; | ||
| import org.apache.paimon.predicate.Predicate; | ||
| import org.apache.paimon.reader.RecordReader; | ||
| import org.apache.paimon.schema.TableSchema; | ||
| import org.apache.paimon.table.source.ChainSplit; | ||
| import org.apache.paimon.table.source.DataSplit; | ||
| import org.apache.paimon.table.source.InnerTableRead; | ||
| import org.apache.paimon.table.source.Split; | ||
| import org.apache.paimon.table.source.StreamDataTableScan; | ||
| import org.apache.paimon.table.source.TableRead; | ||
| import org.apache.paimon.types.RowType; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Chain-table-aware extension of {@link FallbackReadFileStoreTable}. Inherits the batch read | ||
| * behavior (partition-level fallback between the current branch and {@link ChainGroupReadTable}), | ||
| * and additionally overrides {@link #newStreamScan()} to return a chain-aware {@link | ||
| * ChainTableStreamScan} that performs a partition-level full load followed by incremental | ||
| * delta-only streaming. | ||
| */ | ||
| public class ChainTableFileStoreTable extends FallbackReadFileStoreTable { | ||
|
|
||
| public ChainTableFileStoreTable(FileStoreTable wrapped, FileStoreTable other) { | ||
| super(wrapped, other, true); | ||
| } | ||
|
|
||
| @Override | ||
| public StreamDataTableScan newStreamScan() { | ||
| CoreOptions coreOptions = wrapped.coreOptions(); | ||
|
|
||
| StartupMode effectiveMode = coreOptions.startupMode(); | ||
| boolean hasConsumer = coreOptions.consumerId() != null; | ||
| if (effectiveMode != StartupMode.LATEST_FULL || hasConsumer) { | ||
| String reason = describeUnsupportedMode(coreOptions, effectiveMode, hasConsumer); | ||
| throw new UnsupportedOperationException( | ||
| "Chain table streaming read does not support startup mode '" | ||
| + reason | ||
| + "'. " | ||
| + "Chain table streaming only supports the default 'latest-full' mode, which first " | ||
| + "produces a partition-level full result and then continuously reads incremental " | ||
| + "data from the delta branch.\n" | ||
| + "Suggestions:\n" | ||
| + " - To use chain table streaming: remove the explicit scan mode/position settings " | ||
| + "so that the default 'latest-full' mode is used.\n" | ||
| + " - To use standard streaming read without chain table logic: read from a " | ||
| + "specific branch table (e.g., 't$branch_delta') instead of the main table."); | ||
| } | ||
|
|
||
| // Inherited other() returns the ChainGroupReadTable directly. | ||
| ChainGroupReadTable chainGroupReadTable = (ChainGroupReadTable) other(); | ||
|
|
||
| return new ChainTableStreamScan(chainGroupReadTable); | ||
| } | ||
|
|
||
| private static String describeUnsupportedMode( | ||
| CoreOptions coreOptions, StartupMode effectiveMode, boolean hasConsumer) { | ||
| if (hasConsumer) { | ||
| return "consumer mode (consumer-id='" + coreOptions.consumerId() + "')"; | ||
| } | ||
| switch (effectiveMode) { | ||
| case LATEST: | ||
| return "scan.mode=latest"; | ||
| case FROM_SNAPSHOT: | ||
| if (coreOptions.scanSnapshotId() != null) { | ||
| return "scan.snapshot-id=" + coreOptions.scanSnapshotId(); | ||
| } | ||
| if (coreOptions.scanTagName() != null) { | ||
| return "scan.tag-name=" + coreOptions.scanTagName(); | ||
| } | ||
| if (coreOptions.scanWatermark() != null) { | ||
| return "scan.watermark=" + coreOptions.scanWatermark(); | ||
| } | ||
| return "from-snapshot"; | ||
| case FROM_TIMESTAMP: | ||
| if (coreOptions.scanTimestampMills() != null) { | ||
| return "scan.timestamp-millis=" + coreOptions.scanTimestampMills(); | ||
| } | ||
| if (coreOptions.scanTimestamp() != null) { | ||
| return "scan.timestamp=" + coreOptions.scanTimestamp(); | ||
| } | ||
| return "from-timestamp"; | ||
| default: | ||
| return effectiveMode.name().toLowerCase().replace('_', '-'); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public InnerTableRead newRead() { | ||
| return new ChainTableRead(); | ||
| } | ||
|
|
||
| @Override | ||
| public FileStoreTable copy(Map<String, String> dynamicOptions) { | ||
| return new ChainTableFileStoreTable( | ||
| wrapped.copy(dynamicOptions), other().copy(rewriteOtherOptions(dynamicOptions))); | ||
| } | ||
|
|
||
| @Override | ||
| public FileStoreTable copy(TableSchema newTableSchema) { | ||
| return new ChainTableFileStoreTable( | ||
| wrapped.copy(newTableSchema), | ||
| other().copy(newTableSchema.copy(rewriteOtherOptions(newTableSchema.options())))); | ||
| } | ||
|
|
||
| @Override | ||
| public FileStoreTable copyWithoutTimeTravel(Map<String, String> dynamicOptions) { | ||
| return new ChainTableFileStoreTable( | ||
| wrapped.copyWithoutTimeTravel(dynamicOptions), | ||
| other().copyWithoutTimeTravel(rewriteOtherOptions(dynamicOptions))); | ||
| } | ||
|
|
||
| @Override | ||
| public FileStoreTable copyWithLatestSchema() { | ||
| return new ChainTableFileStoreTable( | ||
| wrapped.copyWithLatestSchema(), other().copyWithLatestSchema()); | ||
| } | ||
|
|
||
| @Override | ||
| public FileStoreTable switchToBranch(String branchName) { | ||
| return new ChainTableFileStoreTable(switchWrappedToBranch(branchName), other()); | ||
| } | ||
|
|
||
| /** | ||
| * Chain-aware read implementation that pairs with {@link ChainTableStreamScan}. Routes splits | ||
| * based on type: | ||
| * | ||
| * <ul> | ||
| * <li><b>ChainSplit / DataSplit:</b> Streaming read splits. Routed to {@link | ||
| * ChainGroupReadTable}'s read which uses {@link | ||
| * org.apache.paimon.io.ChainKeyValueFileReaderFactory} (both branch schemas for | ||
| * ChainSplit) or delta branch read (DataSplit with correct schema). | ||
| * <li><b>FallbackSplit:</b> Batch read fallback splits. Routed to inherited {@link | ||
| * FallbackReadFileStoreTable} read for partition-level fallback logic. | ||
| * </ul> | ||
| */ | ||
| private class ChainTableRead implements InnerTableRead { | ||
|
|
||
| private final InnerTableRead chainGroupRead; | ||
| private final InnerTableRead fallbackRead; | ||
|
|
||
| private ChainTableRead() { | ||
| this.chainGroupRead = other().newRead(); | ||
| this.fallbackRead = ChainTableFileStoreTable.super.newRead(); | ||
| } | ||
|
|
||
| @Override | ||
| public InnerTableRead withFilter(Predicate predicate) { | ||
| chainGroupRead.withFilter(predicate); | ||
| fallbackRead.withFilter(predicate); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public InnerTableRead withReadType(RowType readType) { | ||
| chainGroupRead.withReadType(readType); | ||
| fallbackRead.withReadType(readType); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public InnerTableRead forceKeepDelete() { | ||
| chainGroupRead.forceKeepDelete(); | ||
| fallbackRead.forceKeepDelete(); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public TableRead executeFilter() { | ||
| chainGroupRead.executeFilter(); | ||
| fallbackRead.executeFilter(); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public TableRead withIOManager(IOManager ioManager) { | ||
| chainGroupRead.withIOManager(ioManager); | ||
| fallbackRead.withIOManager(ioManager); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public RecordReader<InternalRow> createReader(Split split) throws IOException { | ||
| if (split instanceof FallbackSplit) { | ||
| // FallbackSplit (including FallbackDataSplit): use inherited fallback read logic | ||
| return fallbackRead.createReader(split); | ||
| } | ||
| if (split instanceof ChainSplit || split instanceof DataSplit) { | ||
| return chainGroupRead.createReader(split); | ||
| } | ||
| // Other split types: use inherited fallback read logic | ||
| return fallbackRead.createReader(split); | ||
| } | ||
| } | ||
| } | ||
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.
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.
This also catches
FallbackDataSplit, becauseFallbackDataSplitextendsDataSplit. For a normal batch chain-table scan, main-branch partitions are wrapped asFallbackDataSplit(isFallback=false), but this branch sends them tochainGroupRead.createReader.ChainGroupReadTable.Readthen routes ordinaryDataSplits to its delta-branch reader, so complete main-branch partitions are read with the delta branch reader/schema instead of the original main reader. That can break existing batch fallback reads when branch schemas/schema ids diverge. Please handleFallbackSplitbefore theDataSplitbranch (or only send non-fallback streamingDataSplits throughchainGroupRead) so the inheritedFallbackReadFileStoreTablerouting remains intact.