You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "mrtisttt (via GitHub)" <gi...@apache.org> on 2025/06/10 19:14:10 UTC

[PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

mrtisttt opened a new pull request, #9421:
URL: https://github.com/apache/seatunnel/pull/9421

   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/seatunnel/issues).
     - Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   -->
   
   ### Purpose of this pull request
   
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   closed https://github.com/apache/seatunnel/issues/9338
   
   
   ### Does this PR introduce _any_ user-facing change?
   
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released SeaTunnel versions or within the unreleased branches such as dev.
   If no, write 'No'.
   If you are adding/modifying connector documents, please follow our new specifications: https://github.com/apache/seatunnel/issues/4544.
   -->
   
   Yes, tt provides a new feature that enables parallel reading support for ClickHouse.
   
   
   ### How was this patch tested?
   
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If you are adding E2E test cases, maybe refer to https://github.com/apache/seatunnel/blob/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-cdc-mysql-e2e/src/test/resources/mysqlcdc_to_mysql.conf, here is a good example.
   -->
   
   Add connector unit tests and e2e tests.
   
   
   ### Check list
   
   * [ ] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [ ] If you are contributing the connector code, please check that the following files are updated:
     1. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
     2. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
     3. Add ci label in [label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
     4. Add e2e testcase in [seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
     5. Update connector [plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "JeremyXin (via GitHub)" <gi...@apache.org>.
JeremyXin commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968869305

   @Hisoka-X Hi, I have thought of a reading method. For the case of query_table, all the parts are obtained through the system table (system.parts), and then the part data is directly read from table, similar to how doris reads the tablet. For filtering situations, filtering can be carried out through the partition list. This approach is similar to the implementation of doris and does not require writing sql to achieve concurrent reading of data tables.
   
   Is this a feasible plan? At present, I have implemented the above-mentioned functions and conducted tests in practical applications.


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #9421: [Feature][Connector-V2] ClickHouse source support parallelism
URL: https://github.com/apache/seatunnel/pull/9421


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "mrtisttt (via GitHub)" <gi...@apache.org>.
mrtisttt commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968943524

   > > > @Hisoka-X In this case, do we still need to implement the query-based DynamicChunkSpillter?
   > > 
   > > 
   > > Yes please, query can cover many more scenarios than table_path. We can also use the ability of table_path to read metadata to optimize the query reading sharding, which is also done in JDBC.
   > 
   > +1: In some scenarios, SQL can only be completed in distributed tables and cannot be done locally
   
   OK, that makes the thinking very clear.


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "mrtisttt (via GitHub)" <gi...@apache.org>.
mrtisttt commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2961194325

   > I notice you use chunk splitter of jdbc. It's a not bad choice. But maybe use
   > 
   > https://github.com/apache/seatunnel/blob/f4178c72f1d217b5b2c177f4b8b1d804fdde20ad/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/DynamicChunkSplitter.java#L58
   > 
   > is a better way. Then connector can split partition by itself without user config.
   
   Hi @Hisoka-X Thank you sincerely for your review.
   
   Certainly, the splitter in ClickHouse refers to the implementation of JDBC's `FixedChunkSplitter` and has undergone specific adaptations, optimizations, and fixes tailored for ClickHouse, making its functionality more stable and reliable.
   
   I have indeed noticed the `DynamicChunkSplitter` and reserved extensible approaches when implementing the `FixedChunkSplitter`. However, considering that ClickHouse did not support basic parallel reading previously, and the implementation of both `FixedChunkSplitter` and `DynamicChunkSplitter` would involve significant code development and testing efforts, it has not been implemented for the time being. 
   
   
   The `FixedChunkSplitter` has stable functionality and allows users a certain degree of flexibility. On the basis of retaining the `FixedChunkSplitter`, I will submit a PR in the future to support the `DynamicChunkSplitter`. How about this?
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "Carl-Zhou-CN (via GitHub)" <gi...@apache.org>.
Carl-Zhou-CN commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968924302

   > @Hisoka-X @mrtisttt I will submit the preliminary code as soon as possible to see if it is a suitable reading scheme. @mrtisttt Or maybe you can continue to develop code based on DynamicChunkSplitter? If there are any questions, welcome to communicate together.
   
   Looking forward to your submission. I think the two are not in conflict and users can have more choices


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "mrtisttt (via GitHub)" <gi...@apache.org>.
mrtisttt commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968924423

   > @Hisoka-X @mrtisttt I will submit the preliminary code as soon as possible to see if it is a suitable reading scheme. @mrtisttt Or maybe you can continue to develop code based on DynamicChunkSplitter? If there are any questions, welcome to communicate together.
   
   @Hisoka-X In this case, do we still need to implement the query-based DynamicChunkSpillter?
   分享


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "mrtisttt (via GitHub)" <gi...@apache.org>.
mrtisttt commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968900045

   > > @Hisoka-X Hi, I have thought of a reading method. For the case of query_table, all the parts are obtained through the system table (system.parts), and then the part data is directly read from table, similar to how doris reads the tablet. For filtering situations, filtering can be carried out through the partition list. This approach is similar to the implementation of doris and does not require writing sql to achieve concurrent reading of data tables.
   > > Is this a feasible plan? At present, I have implemented the above-mentioned functions and conducted tests in practical applications.
   > 
   > Good idea. Does it support distributed tables?
   
   Yes, I've also thought about this issue. In ClickHouse, distributed tables pose a significant challenge, which is exactly why I mentioned the strong dependency on `query_table`.


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "mrtisttt (via GitHub)" <gi...@apache.org>.
mrtisttt commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968863872

   @Hisoka-X I have considered this model, but there is a problem: does the approach of `query_table + query` mean that the table name written in the user's query must be exactly the table in `query_table`? In this case, performing validation would be very difficult.


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "Carl-Zhou-CN (via GitHub)" <gi...@apache.org>.
Carl-Zhou-CN commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968935499

   > > @Hisoka-X In this case, do we still need to implement the query-based DynamicChunkSpillter?
   > 
   > Yes please, query can cover many more scenarios than table_path. We can also use the ability of table_path to read metadata to optimize the query reading sharding, which is also done in JDBC.
   
   +1: In some scenarios, SQL can only be completed in distributed tables and cannot be done locally


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-3393771563

   This pull request has been automatically marked as stale because it has not had recent activity for 120 days. It will be closed in 7 days if no further activity occurs.


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "mrtisttt (via GitHub)" <gi...@apache.org>.
mrtisttt commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2967714347

   @Hisoka-X Since clickhouse source connector still use sql query to read source tables and there are still many imperfections, in the subsequent implementation, I will also implement:
    - **query_table**(just like jdbc or doris, use table_path option or similar)
    - **where_condition**(just like jdbc or doris, use filter.query option or similar)
    - **read_filed**(just like doris, use read_filed or similary)
   
   to better support DynamicChunkSpiltter. This is also preparing for the subsequent implementation of multi-table reading. At the same time, perhaps in the future, we can remove the option to use sql query to read source data tables.
   
   How about this idea?
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "mrtisttt (via GitHub)" <gi...@apache.org>.
mrtisttt commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968904196

   @Hisoka-X @Carl-Zhou-CN @JeremyXin So, how about we first implement the query_table approach? Or should we first implement the query-based DynamicChunkSplitter following the ClickHouse source connector's pattern?
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-3419098746

   This pull request has been closed because it has not had recent activity. You could reopen it if you try to continue your work, and anyone who are interested in it are encouraged to continue work on this pull request.


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "JeremyXin (via GitHub)" <gi...@apache.org>.
JeremyXin commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968898449

   
   > > @Hisoka-X Hi, I have thought of a reading method. For the case of query_table, all the parts are obtained through the system table (system.parts), and then the part data is directly read from table, similar to how doris reads the tablet. For filtering situations, filtering can be carried out through the partition list. This approach is similar to the implementation of doris and does not require writing sql to achieve concurrent reading of data tables.
   > > Is this a feasible plan? At present, I have implemented the above-mentioned functions and conducted tests in practical applications.
   > 
   > Good idea. Does it support distributed tables?
   
   Yes,for distributed tables, reading is actually still performed on the local table. The part under each shard will be obtained and read concurrently.


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "JeremyXin (via GitHub)" <gi...@apache.org>.
JeremyXin commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968918726

   @Hisoka-X @mrtisttt I will submit the preliminary code as soon as possible to see if it is a suitable reading scheme. @mrtisttt  
   Or maybe you can continue to develop code based on DynamicChunkSplitter? If there are any questions, welcome to communicate together.
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "mrtisttt (via GitHub)" <gi...@apache.org>.
mrtisttt commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968927915

   > > @Hisoka-X @mrtisttt I will submit the preliminary code as soon as possible to see if it is a suitable reading scheme. @mrtisttt Or maybe you can continue to develop code based on DynamicChunkSplitter? If there are any questions, welcome to communicate together.
   > 
   > Looking forward to your submission. I think the two are not in conflict and users can have more choices
   
   Okay, I understand. Then I'll submit the implementation of DynamicChunkSpillter first. This will indeed provide users with an additional option.


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "mrtisttt (via GitHub)" <gi...@apache.org>.
mrtisttt commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2965122318

   @Hisoka-X Hi, Would it be appropriate for me to submit a PR to support the DynamicChunkSplitter in the upcoming period?


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "Carl-Zhou-CN (via GitHub)" <gi...@apache.org>.
Carl-Zhou-CN commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968878441

   > @Hisoka-X你好,我想到了一种读取方式。对于query_table的情况,通过系统表(system.parts)获取所有parts,然后直接从table中读取parts数据,类似doris读取tablet的方式。对于过滤的情况,可以通过partition列表进行过滤。这种方式和doris的实现类似,不需要写sql来实现数据表的并发读取。
   > 
   > 这是一个可行的方案吗?目前我已经实现了上述功能,并在实际应用中进行了测试。
   
   Does it support distributed tables?


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#discussion_r2139021681


##########
seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/source/ClickhouseSourceSplitEnumerator.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.clickhouse.source;
+
+import org.apache.seatunnel.api.source.SourceSplitEnumerator;
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.common.exception.CommonErrorCode;
+import org.apache.seatunnel.connectors.seatunnel.clickhouse.config.ClickhouseSourceConfig;
+import org.apache.seatunnel.connectors.seatunnel.clickhouse.exception.ClickhouseConnectorException;
+import org.apache.seatunnel.connectors.seatunnel.clickhouse.state.ClickhouseSourceState;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@Slf4j
+public class ClickhouseSourceSplitEnumerator
+        implements SourceSplitEnumerator<ClickHouseSourceSplit, ClickhouseSourceState> {
+
+    private final Context<ClickHouseSourceSplit> context;
+    private final ClickhouseSourceConfig sourceConfig;
+    private final CatalogTable catalogTable;
+    private final ClickhouseChunkSplitter splitter;
+    private final Map<Integer, List<ClickHouseSourceSplit>> pendingSplits;
+    private final Object stateLock = new Object();
+
+    public ClickhouseSourceSplitEnumerator(
+            Context<ClickHouseSourceSplit> context,
+            ClickhouseSourceConfig sourceConfig,
+            CatalogTable catalogTable) {
+        this.context = context;
+        this.sourceConfig = sourceConfig;
+        this.catalogTable = catalogTable;
+        this.splitter = new ClickhouseChunkSplitter();
+        this.pendingSplits = new HashMap<>();
+    }
+
+    @Override
+    public void open() {}
+
+    @Override
+    public void run() throws Exception {
+        log.info("Starting split enumerator.");
+
+        Set<Integer> readers = context.registeredReaders();
+
+        synchronized (stateLock) {
+            Collection<ClickHouseSourceSplit> splits =
+                    splitter.generateSplits(sourceConfig, catalogTable);
+            addPendingSplit(splits);
+        }
+
+        synchronized (stateLock) {
+            assignSplit(readers);
+        }
+
+        log.info("No more splits to assign." + " Sending NoMoreSplitsEvent to reader {}.", readers);
+        readers.forEach(context::signalNoMoreSplits);
+    }
+
+    private void assignSplit(Collection<Integer> readers) {
+        log.info("Assign pendingSplits to readers {}", readers);
+
+        for (int reader : readers) {
+            List<ClickHouseSourceSplit> splits = pendingSplits.remove(reader);
+            if (splits != null && !splits.isEmpty()) {
+                String splitIds =
+                        splits.stream()
+                                .map(ClickHouseSourceSplit::getSplitId)
+                                .collect(Collectors.joining(", "));
+                log.info("Assign splits {} to reader {}", splitIds, reader);
+                context.assignSplit(reader, splits);
+            }
+        }
+    }
+
+    @Override
+    public void close() throws IOException {}
+
+    @Override
+    public void addSplitsBack(List<ClickHouseSourceSplit> splits, int subtaskId) {}
+
+    @Override
+    public int currentUnassignedSplitSize() {
+        return 0;
+    }
+
+    @Override
+    public void handleSplitRequest(int subtaskId) {
+        throw new ClickhouseConnectorException(
+                CommonErrorCode.UNSUPPORTED_METHOD,
+                String.format("Unsupported handleSplitRequest: %d", subtaskId));
+    }
+
+    @Override
+    public void registerReader(int subtaskId) {
+        log.info("Register reader {} to ClickhouseSourceSplitEnumerator.", subtaskId);
+    }
+
+    @Override
+    public ClickhouseSourceState snapshotState(long checkpointId) throws Exception {
+        synchronized (stateLock) {
+            return new ClickhouseSourceState();
+        }
+    }
+
+    @Override
+    public void notifyCheckpointComplete(long checkpointId) throws Exception {}
+
+    private void addPendingSplit(Collection<ClickHouseSourceSplit> splits) {
+        int readerCount = context.currentParallelism();
+        for (ClickHouseSourceSplit split : splits) {
+            int ownerReader = getSplitOwner(split.splitId(), readerCount);
+
+            pendingSplits.computeIfAbsent(ownerReader, r -> new ArrayList<>()).add(split);
+        }
+    }
+
+    private static int getSplitOwner(String splitId, int numReaders) {
+        return splitId.hashCode() % numReaders;

Review Comment:
   Using `hashCode() % numReaders` can yield negative indices when `hashCode()` is negative. Consider using `Math.floorMod(splitId.hashCode(), numReaders)` to ensure non-negative reader assignment.
   ```suggestion
           return Math.floorMod(splitId.hashCode(), numReaders);
   ```



##########
seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/source/ClickhouseSourceSplitEnumerator.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.clickhouse.source;
+
+import org.apache.seatunnel.api.source.SourceSplitEnumerator;
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.common.exception.CommonErrorCode;
+import org.apache.seatunnel.connectors.seatunnel.clickhouse.config.ClickhouseSourceConfig;
+import org.apache.seatunnel.connectors.seatunnel.clickhouse.exception.ClickhouseConnectorException;
+import org.apache.seatunnel.connectors.seatunnel.clickhouse.state.ClickhouseSourceState;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@Slf4j
+public class ClickhouseSourceSplitEnumerator
+        implements SourceSplitEnumerator<ClickHouseSourceSplit, ClickhouseSourceState> {
+
+    private final Context<ClickHouseSourceSplit> context;
+    private final ClickhouseSourceConfig sourceConfig;
+    private final CatalogTable catalogTable;
+    private final ClickhouseChunkSplitter splitter;
+    private final Map<Integer, List<ClickHouseSourceSplit>> pendingSplits;
+    private final Object stateLock = new Object();
+
+    public ClickhouseSourceSplitEnumerator(
+            Context<ClickHouseSourceSplit> context,
+            ClickhouseSourceConfig sourceConfig,
+            CatalogTable catalogTable) {
+        this.context = context;
+        this.sourceConfig = sourceConfig;
+        this.catalogTable = catalogTable;
+        this.splitter = new ClickhouseChunkSplitter();
+        this.pendingSplits = new HashMap<>();
+    }
+
+    @Override
+    public void open() {}
+
+    @Override
+    public void run() throws Exception {
+        log.info("Starting split enumerator.");
+
+        Set<Integer> readers = context.registeredReaders();
+
+        synchronized (stateLock) {
+            Collection<ClickHouseSourceSplit> splits =
+                    splitter.generateSplits(sourceConfig, catalogTable);
+            addPendingSplit(splits);
+        }
+
+        synchronized (stateLock) {
+            assignSplit(readers);
+        }
+
+        log.info("No more splits to assign." + " Sending NoMoreSplitsEvent to reader {}.", readers);
+        readers.forEach(context::signalNoMoreSplits);
+    }
+
+    private void assignSplit(Collection<Integer> readers) {
+        log.info("Assign pendingSplits to readers {}", readers);
+
+        for (int reader : readers) {
+            List<ClickHouseSourceSplit> splits = pendingSplits.remove(reader);
+            if (splits != null && !splits.isEmpty()) {
+                String splitIds =
+                        splits.stream()
+                                .map(ClickHouseSourceSplit::getSplitId)
+                                .collect(Collectors.joining(", "));
+                log.info("Assign splits {} to reader {}", splitIds, reader);
+                context.assignSplit(reader, splits);
+            }
+        }
+    }
+
+    @Override
+    public void close() throws IOException {}
+
+    @Override
+    public void addSplitsBack(List<ClickHouseSourceSplit> splits, int subtaskId) {}

Review Comment:
   The `addSplitsBack` method is left empty, so splits returned on failure won’t be reassigned. Implement logic to re-add these splits to `pendingSplits` to support recovery.
   ```suggestion
       public void addSplitsBack(List<ClickHouseSourceSplit> splits, int subtaskId) {
           synchronized (stateLock) {
               log.info("Adding splits back for subtask {}: {}", subtaskId, splits);
               pendingSplits.computeIfAbsent(subtaskId, k -> new ArrayList<>()).addAll(splits);
           }
       }
   ```



##########
seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/source/ClickhouseSourceSplitEnumerator.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.clickhouse.source;
+
+import org.apache.seatunnel.api.source.SourceSplitEnumerator;
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.common.exception.CommonErrorCode;
+import org.apache.seatunnel.connectors.seatunnel.clickhouse.config.ClickhouseSourceConfig;
+import org.apache.seatunnel.connectors.seatunnel.clickhouse.exception.ClickhouseConnectorException;
+import org.apache.seatunnel.connectors.seatunnel.clickhouse.state.ClickhouseSourceState;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@Slf4j
+public class ClickhouseSourceSplitEnumerator
+        implements SourceSplitEnumerator<ClickHouseSourceSplit, ClickhouseSourceState> {
+
+    private final Context<ClickHouseSourceSplit> context;
+    private final ClickhouseSourceConfig sourceConfig;
+    private final CatalogTable catalogTable;
+    private final ClickhouseChunkSplitter splitter;
+    private final Map<Integer, List<ClickHouseSourceSplit>> pendingSplits;
+    private final Object stateLock = new Object();
+
+    public ClickhouseSourceSplitEnumerator(
+            Context<ClickHouseSourceSplit> context,
+            ClickhouseSourceConfig sourceConfig,
+            CatalogTable catalogTable) {
+        this.context = context;
+        this.sourceConfig = sourceConfig;
+        this.catalogTable = catalogTable;
+        this.splitter = new ClickhouseChunkSplitter();
+        this.pendingSplits = new HashMap<>();
+    }
+
+    @Override
+    public void open() {}
+
+    @Override
+    public void run() throws Exception {
+        log.info("Starting split enumerator.");
+
+        Set<Integer> readers = context.registeredReaders();
+
+        synchronized (stateLock) {
+            Collection<ClickHouseSourceSplit> splits =
+                    splitter.generateSplits(sourceConfig, catalogTable);
+            addPendingSplit(splits);
+        }
+
+        synchronized (stateLock) {
+            assignSplit(readers);
+        }
+
+        log.info("No more splits to assign." + " Sending NoMoreSplitsEvent to reader {}.", readers);
+        readers.forEach(context::signalNoMoreSplits);
+    }
+
+    private void assignSplit(Collection<Integer> readers) {
+        log.info("Assign pendingSplits to readers {}", readers);
+
+        for (int reader : readers) {
+            List<ClickHouseSourceSplit> splits = pendingSplits.remove(reader);
+            if (splits != null && !splits.isEmpty()) {
+                String splitIds =
+                        splits.stream()
+                                .map(ClickHouseSourceSplit::getSplitId)
+                                .collect(Collectors.joining(", "));
+                log.info("Assign splits {} to reader {}", splitIds, reader);
+                context.assignSplit(reader, splits);
+            }
+        }
+    }
+
+    @Override
+    public void close() throws IOException {}
+
+    @Override
+    public void addSplitsBack(List<ClickHouseSourceSplit> splits, int subtaskId) {}
+
+    @Override
+    public int currentUnassignedSplitSize() {
+        return 0;

Review Comment:
   `currentUnassignedSplitSize` always returns 0; consider returning the total count of unassigned splits (e.g., sum of sizes in `pendingSplits`) to accurately report backlog.
   ```suggestion
           synchronized (stateLock) {
               return pendingSplits.values().stream()
                       .mapToInt(List::size)
                       .sum();
           }
   ```



-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2965866302

   Yes, please use DynamicChunkSplitter to reduce unnecessary configuration. In fact, the FixedChunkSplitter is a legacy in JDBC and is not recommended.


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968894525

   > For the case of query_table, all the parts are obtained through the system table (system.parts), and then the part data is directly read from table, similar to how doris reads the tablet. For filtering situations, filtering can be carried out through the partition list. 
   
   @JeremyXin Yes, it's a good way for query_table.
   
   > At present, I have implemented the above-mentioned functions and conducted tests in practical applications.
   
   Welcome to contribute!
   
   > I have considered this model, but there is a problem: does the approach of query_table + query mean that the table name written in the user's query must be exactly the table in query_table? 
   
   @mrtisttt We have a processing priority. If query and table_path are configured at the same time, we get data through query and get meta information through table_path. Please refer
   https://github.com/apache/seatunnel/blob/8a9e8add15a40c96ece5b4f337d84aa598630b73/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/utils/JdbcCatalogUtils.java#L175-L199
   
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "Carl-Zhou-CN (via GitHub)" <gi...@apache.org>.
Carl-Zhou-CN commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968881422

   > @Hisoka-X Hi, I have thought of a reading method. For the case of query_table, all the parts are obtained through the system table (system.parts), and then the part data is directly read from table, similar to how doris reads the tablet. For filtering situations, filtering can be carried out through the partition list. This approach is similar to the implementation of doris and does not require writing sql to achieve concurrent reading of data tables.
   > 
   > Is this a feasible plan? At present, I have implemented the above-mentioned functions and conducted tests in practical applications.
   
   Good idea. Does it support distributed tables?


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968839444

   > query_table(just like jdbc or doris, use table_path option or similar)
   
   +1 for this, this way can better identify the metadata of the table, thereby improving read performance.
   
   > where_condition(just like jdbc or doris, use filter.query option or similar)
   > read_filed(just like doris, use read_filed or similary)
   
   This way is not necessary at present, and the filter conditions and field selection can actually be reflected in the query.
   
   Moreover, query can preprocess data, which cannot be done by other ways, such as join.
   
   So let support query with `DynamicChunkSpiltter` first, then support `query_table` .
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968909009

   > @Hisoka-X @Carl-Zhou-CN @JeremyXin So, how about we first implement the query_table approach? Or should we first implement the query-based DynamicChunkSplitter following the ClickHouse source connector's pattern?
   
   +1. Overall, `table_path` (let's align its name with the other connectors) is more important.


-- 
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: commits-unsubscribe@seatunnel.apache.org

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


Re: [PR] [Feature][Connector-V2] ClickHouse source support parallelism [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #9421:
URL: https://github.com/apache/seatunnel/pull/9421#issuecomment-2968928587

   > @Hisoka-X In this case, do we still need to implement the query-based DynamicChunkSpillter?
   
   Yes please, query can cover many more scenarios than table_path. We can also use the ability of table_path to read metadata to optimize the query reading sharding, which is also done in JDBC.


-- 
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: commits-unsubscribe@seatunnel.apache.org

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