You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fluss.apache.org by "raminqaf (via GitHub)" <gi...@apache.org> on 2026/10/14 06:49:04 UTC

[PR] [flink] Respect DISTRIBUTED BY when creating tables and materialized tables [fluss]

raminqaf opened a new pull request, #4635:
URL: https://github.com/apache/fluss/pull/4635

   <!--
   *Thank you very much for contributing to Fluss - we are happy that you want to help us improve Fluss. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GitHub issue](https://github.com/apache/fluss/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no issue.
   
     - Name the pull request in the format "[component] Title of the pull request", where *[component]* should be replaced by the name of the component being changed. Typically, this corresponds to the component label assigned to the issue (e.g., [kv], [log], [client], [flink], [rust], [python], [c++], [elixir]). Skip *[component]* if you are unsure about which is the best component.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
   
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes.
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
   
     - **Generative AI disclosure:** Indicate whether generative AI tools were used in authoring this PR. If yes, specify the tool below.
       - [ ] No generative AI tools used
       - [x] Yes (Claude Code 2.1.296, Claude Opus 5.5)
   
   **(The sections below can be removed for hotfixes or typos)**
   -->
   
   <!--
   Generated-by: Claude Code 2.1.296 (Claude Opus 5.5) following [the guidelines](https://github.com/apache/fluss/blob/main/AGENTS.md)
   -->
   
   ### Purpose
   
   Linked issue: close #ISSUE
   
   The Fluss catalog dropped the `DISTRIBUTED BY` clause, so tables got the default bucket count and bucket key:
   
   ```sql
   CREATE TABLE orders (
     id INT, region STRING, amt INT, PRIMARY KEY (id, region) NOT ENFORCED
   ) DISTRIBUTED BY HASH(id) INTO 4 BUCKETS;
   ```
   
   | DDL                                       | Before                                 | After                                                                              |
   |-------------------------------------------|----------------------------------------|------------------------------------------------------------------------------------|
   | `DISTRIBUTED BY HASH(id) INTO 4 BUCKETS`  | Bucket key `id, region`, default count | Bucket key `id`, 4 buckets                                                         |
   | `DISTRIBUTED INTO 2 BUCKETS`              | Default count                          | 2 buckets, default bucket key                                                      |
   | `DISTRIBUTED BY RANGE(id) INTO 2 BUCKETS` | Accepted, clause dropped               | `Fluss only supports hash distribution, but got DISTRIBUTED BY RANGE.`             |
   | `DISTRIBUTED BY ...` plus `'bucket.num'`  | Accepted, clause dropped               | `Cannot use DISTRIBUTED BY together with the 'bucket.key' or 'bucket.num' option.` |
   
   This applies to `CREATE TABLE` on Flink 1.20+, and to CTAS and `CREATE MATERIALIZED TABLE` on Flink 2.2+. Flink 1.20's parser rejects `DISTRIBUTED BY` in CTAS on its own (FLINK-35717 lifted that in 2.0).
   
   ### Brief change log
   
   - `CatalogTableAdapter#toFlussDistribution` reads the distribution of a table, or of a materialized table through `CatalogMaterializedTableAdapter#getDistribution`. The Flink 1.18 and 1.19 adapters return empty, since those versions have no `DISTRIBUTED BY`.
   - `FlinkConversions#toFlussTable` prefers the clause over the options and rejects tables that use both.
   - The read path is unchanged: `getTable` still reports buckets through the `bucket.key` and `bucket.num` options. Returning a distribution would make Flink require `SupportsBucketing` on `FlinkTableSink` for every insert. That would be a separate change.
   - `ALTER TABLE ... ADD/MODIFY/DROP DISTRIBUTION` still fails with "Unsupported flink table change".
   
   ### Tests
   
   - `FlinkCatalogITCase#testCreateTableWithDistributedBy` covers a PK table, a log table, RANGE and the option conflict on Flink 1.20.
   - `Flink22CatalogITCase` and `Flink23CatalogITCase` cover CTAS (`testCreateTableAsSelectWithDistributedBy`) and materialized tables (`testCreateMaterializedTableWithDistributedBy`).
   - The existing multi-version catalog ITCases on Flink 1.18 and 1.19 exercise the new no-op adapters.
   
   ### API and Format
   
   No change to storage or RPC. Users who declared `DISTRIBUTED BY` before now get the buckets they asked for, or an error for RANGE or the option conflict.
   
   ### Documentation
   
   Added a "Bucketing with DISTRIBUTED BY" section to `website/docs/engine-flink/ddl.md`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [flink] Respect DISTRIBUTED BY when creating tables and materialized tables [fluss]

Posted by "fresh-borzoni (via GitHub)" <gi...@apache.org>.
fresh-borzoni merged PR #4635:
URL: https://github.com/apache/fluss/pull/4635


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [flink] Respect DISTRIBUTED BY when creating tables and materialized tables [fluss]

Posted by "raminqaf (via GitHub)" <gi...@apache.org>.
raminqaf commented on PR #4635:
URL: https://github.com/apache/fluss/pull/4635#issuecomment-6212626511

   Thanks for testing it on all three versions, @fresh-borzoni! Rebased.
   
   Good catch. Both cases come from the read path. `getTable` returns the buckets as `bucket.num` and `bucket.key` options and adds `bootstrap.servers` and the storage configs. Flink 2.3 turns each of them into a `reset` on `CREATE OR ALTER`, and `LIKE` copies them next to `DISTRIBUTED BY`.
   
   I agree that returning `DISTRIBUTED BY` on read is the right fix. It needs `SupportsBucketing` on the sink, so I'd keep it out of this PR. I opened #4667 to track it and can pick it up next. Until then, `LIKE t1 (EXCLUDING OPTIONS)` works around the second case.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org