-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[python] Improve the consumer_manager API and support in file_store_table #7415
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
JingsongLi
merged 8 commits into
apache:master
from
xuzifu666:py_consumer_manager_detail
Mar 12, 2026
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ba6155f
[python] Improve the consumer_manager API and support it in file_stor…
xuzifu666 15f04bc
fix styles
xuzifu666 b50f04e
fix styles
xuzifu666 627eb53
fix styles
xuzifu666 b90133a
fix docs
xuzifu666 f7d83ad
addressed
xuzifu666 7163aca
change docs and consumer_manager
xuzifu666 af0ce14
fix docs
xuzifu666 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -591,6 +591,125 @@ to the appropriate rollback logic. | |
| | f is not in [l1, l2] | PredicateBuilder.is_not_in(f, [l1, l2]) | | ||
| | lower <= f <= upper | PredicateBuilder.between(f, lower, upper) | | ||
|
|
||
| ## Consumer Management | ||
|
|
||
| Consumer management allows you to track consumption progress, prevent snapshot expiration, and resume from breakpoints. | ||
|
|
||
| ### Create ConsumerManager | ||
|
|
||
| ```python | ||
| from pypaimon import CatalogFactory | ||
| from pypaimon.consumer.consumer_manager import ConsumerManager | ||
|
|
||
| # Get table and file_io | ||
| catalog = CatalogFactory.create({'warehouse': 'file:///path/to/warehouse'}) | ||
| table = catalog.get_table('database_name.table_name') | ||
| file_io = table.file_io() | ||
|
|
||
| # Create consumer manager | ||
| manager = table.consumer_manager | ||
|
Contributor
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. table.consumer_manager() |
||
| ``` | ||
|
|
||
| ### Get Consumer | ||
|
|
||
| Retrieve a consumer by its ID: | ||
|
|
||
| ```python | ||
| from pypaimon.consumer.consumer import Consumer | ||
|
|
||
| consumer = manager.consumer('consumer_id') | ||
| if consumer: | ||
| print(f"Next snapshot: {consumer.next_snapshot}") | ||
| else: | ||
| print("Consumer not found") | ||
| ``` | ||
|
|
||
| ### Reset Consumer | ||
|
|
||
| Create or reset a consumer with a new snapshot ID: | ||
|
|
||
| ```python | ||
| # Reset consumer to snapshot 10 | ||
| manager.reset_consumer('consumer_id', Consumer(next_snapshot=10)) | ||
| ``` | ||
|
|
||
| ### Delete Consumer | ||
|
|
||
| Delete a consumer by its ID: | ||
|
|
||
| ```python | ||
| manager.delete_consumer('consumer_id') | ||
| ``` | ||
|
|
||
| ### List Consumers | ||
|
|
||
| Get all consumers with their next snapshot IDs: | ||
|
|
||
| ```python | ||
| consumers = manager.consumers() | ||
| for consumer_id, next_snapshot in consumers.items(): | ||
| print(f"Consumer {consumer_id}: next snapshot {next_snapshot}") | ||
| ``` | ||
|
|
||
| ### List All Consumer IDs | ||
|
|
||
| List all consumer IDs: | ||
|
|
||
| ```python | ||
| consumer_ids = manager.list_all_ids() | ||
| for consumer_id in consumer_ids: | ||
| print(consumer_id) | ||
| ``` | ||
|
|
||
| ### Get Minimum Next Snapshot | ||
|
|
||
| Get the minimum next snapshot across all consumers: | ||
|
|
||
| ```python | ||
| min_snapshot = manager.min_next_snapshot() | ||
| if min_snapshot: | ||
| print(f"Minimum next snapshot: {min_snapshot}") | ||
| ``` | ||
|
|
||
| ### Expire Consumers | ||
|
|
||
| Expire consumers modified before a given datetime: | ||
|
|
||
| ```python | ||
| from datetime import datetime, timedelta | ||
|
|
||
| # Expire consumers older than 1 day | ||
| expire_time = datetime.now() - timedelta(days=1) | ||
| manager.expire(expire_time) | ||
| ``` | ||
|
|
||
| ### Clear Consumers | ||
|
|
||
| Clear consumers matching regular expression patterns: | ||
|
|
||
| ```python | ||
| # Clear all consumers starting with "test_" | ||
| manager.clear_consumers('test_.*') | ||
|
|
||
| # Clear all consumers except those starting with "prod_" | ||
| manager.clear_consumers( | ||
| '.*', | ||
| 'prod_.*' | ||
| ) | ||
| ``` | ||
|
|
||
| ### Branch Support | ||
|
|
||
| ConsumerManager supports multiple branches: | ||
|
|
||
| ```python | ||
| # Custom branch | ||
| branch_manager = manager.with_branch('feature_branch') | ||
|
|
||
| # Each branch maintains its own consumers | ||
| print(branch_manager.consumers()) # Consumers on feature branch | ||
| ``` | ||
|
|
||
| ## Supported Features | ||
|
|
||
| The following shows the supported features of Python Paimon compared to Java Paimon: | ||
|
|
||
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
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.
No need to import?