Repository navigation
[flink] Add $buckets virtual table for bucket metadata - #4379
Conversation
|
Hi @swuferhong , this PR is the Flink procedure follow-up to #4029. It exposes the describe-buckets API through Could you please take a look when you have time? Thanks! |
|
@coding-otter-bot review |
Automated code reviewProblemExpose the existing Admin#describeBuckets bucket-metadata API to Flink SQL users via a new sys.describe_buckets system procedure, supporting all buckets of a table and optional complete/partial partition-spec filtering, with input validation, documentation, and tests. ApproachAdds DescribeBucketsProcedure (ProcedureBase subclass with two @ProcedureHint overloads: (table_path) and (table_path, partition_spec)) that parses the table path and a key=value[/key=value...] spec into a PartitionSpec, delegates to Admin#describeBuckets, and maps List to Row<table_path, table_id, partition_id, partition_name, bucket_id, leader_id, leader_epoch, bucket_epoch, replicas ARRAY, isr ARRAY>. Registers the procedure in ProcedureManager, adds unit and ITCase coverage, and a docs section. Review coverageComplete: the material changed paths and review hypotheses were resolved. ConclusionNo actionable code issues were found in this static review. From the reviewed code paths, no change is required before merge. CI results and maintainer approval still apply. FindingsNo actionable findings survived the final audit. |
Automated code review could not completeThe review for commit Failure code: After the problem is resolved, post a new comment to retry:
|
|
hi @swuferhong , could you please help review this PR when you have time? thanks! |
|
Thanks @fhan688 for the contribution, what do you think about supporting this via |
Thanks for the suggestion. I agree that bucket metadata is a better fit for a system table because it is read-only relational Fluss already has the virtual-table mechanism used by
Standard SQL filtering will work in this PR. Partition predicate pushdown to the partition-specific Admin API can be added as a follow-up optimization to keep the initial implementation focused. |
|
Thanks, @fhan688, for the update. I like the new API. Will take a closer look later. Btw, I suggest that we also refactor the previously introduced |
Thanks @wuchong, that makes sense. I’ll keep this PR focused on the The follow-up can introduce a read-only, bounded I’ll wait for feedback from @Kaixuan-Duan and @platinumhamburg on whether the existing procedure should be removed directly or kept for a compatibility period. |
|
+1 to @wuchong's suggestion. Query-like metadata fits a virtual table better than a CALL procedure: it composes naturally with standard SQL (projection, filtering, aggregation), the schema is discoverable via DESCRIBE. Aligning $partitions with the $buckets design also keeps a consistent mental model — tables for queries, procedures for actions. Thanks @fhan688, on removing sys.list_partition_infos: since it has already shipped in v1.0.0, I'd favor deprecating it first rather than removing it in the same PR — mark it deprecated in the release that introduces $partitions, and remove it in a later one. This gives existing users a migration window instead of breaking their scripts on upgrade. cc @platinumhamburg. |
| @Override | ||
| public DataStream<RowData> produceDataStream( | ||
| ProviderContext providerContext, StreamExecutionEnvironment execEnv) { | ||
| return execEnv.fromCollection(loadBucketRows(), resultTypeInfo) |
There was a problem hiding this comment.
Could we defer fetching bucket metadata until runtime? Calling loadBucketRows() here embeds the current bucket data in the source transformation. When SQL Gateway plan caching is enabled, its cached DQLCachedPlan reuses these transformations, so subsequent executions do not call describeBuckets() again and can return stale metadata.
I reproduced this with Flink 1.20.3: after adding a partition, a freshly planned query returned 4 buckets, while executing the cached plan still returned the original 2.
Paimon's $buckets implementation avoids this by creating a split containing only the filter predicates during planning and reading the metadata in BucketsRead.createReader(). Could we use a lightweight bounded source with a single split and call Admin.describeBuckets() in the reader? This would refresh the metadata on each execution and avoid serializing all bucket rows into the JobGraph. WDYT @loserwang1024 ?
There was a problem hiding this comment.
Could we defer fetching bucket metadata until runtime? Calling
loadBucketRows()here embeds the current bucket data in the source transformation. When SQL Gateway plan caching is enabled, its cachedDQLCachedPlanreuses these transformations, so subsequent executions do not calldescribeBuckets()again and can return stale metadata.I reproduced this with Flink 1.20.3: after adding a partition, a freshly planned query returned 4 buckets, while executing the cached plan still returned the original 2.
Paimon's $buckets implementation avoids this by creating a split containing only the filter predicates during planning and reading the metadata in
BucketsRead.createReader(). Could we use a lightweight bounded source with a single split and callAdmin.describeBuckets()in the reader? This would refresh the metadata on each execution and avoid serializing all bucket rows into the JobGraph. WDYT @loserwang1024 ?
Thanks for catching this and for the detailed reproduction. I agree that calling loadBucketRows() from produceDataStream() materializes the metadata while building the transformations, so a cached DQLCachedPlan can reuse stale bucket rows.
I’ll rework this into a lightweight bounded source with a single split and move Admin#describeBuckets() into the source reader, so the metadata is fetched once per execution rather than during planning. The split can remain empty for now since predicate pushdown is still a follow-up optimization.
I’ll also add regression coverage that executes the same DQL with SQL Gateway plan caching enabled, updates the partitions out of band, and verifies that the second execution observes the new buckets.
+1 to @wuchong and @Kaixuan-Duan. A $partitions virtual table would make metadata queries consistent with $buckets and easier to compose with standard SQL. |
|
@Kaixuan-Duan @platinumhamburg thanks, I agree. Let's deprecate |
wuchong
left a comment
There was a problem hiding this comment.
LGTM.
I have some concerns regarding code reuse, particularly the 400+ lines of source implementation, as introducing more virtual tables could create a significant maintenance burden. However, this can be optimized in follow-up PRs.
Purpose
Linked issue: close #3436
PR #4029 introduced the Admin API and RPC support for retrieving bucket metadata. This pull request exposes that functionality to Flink SQL users through the read-only
$bucketsvirtual table.For example:
Compared with a system procedure, the virtual table integrates naturally with standard SQL operations such as projection and filtering, and can be inspected using commands such as
DESCRIBE my_table$buckets.Brief change log
Add the
$bucketsvirtual table for Fluss tables.Expose the following bucket metadata columns:
Add a bounded, insert-only Flink table source that retrieves the current bucket metadata snapshot through
Admin#describeBuckets.Support both partitioned and non-partitioned tables:
Allow standard SQL projection and filtering, for example:
$bucketsas a read-only virtual table and reject sink creation, table mutation, and partition mutation.$lakeseparator.sys.describe_bucketsprocedure implementation in this PR with the$bucketsvirtual-table approach.The current implementation retrieves the complete bucket metadata snapshot before Flink evaluates SQL predicates. Predicate pushdown is not included in this pull request.
Tests
API and Format
This pull request introduces the
$bucketsFlink SQL virtual-table interface.It does not change the Java Admin API, RPC protocol, server implementation, or storage format. The virtual table delegates to the existing Admin#describeBuckets API introduced by PR #4029.
Documentation
Added
$bucketsto the virtual-table documentation, including: