Hisoka-X commented on code in PR #9002: URL: https://github.com/apache/seatunnel/pull/9002#discussion_r2004749617
########## seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/SplitMode.java: ########## @@ -0,0 +1,43 @@ +/* + * 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.jdbc.source; + +public enum SplitMode { Review Comment: ```suggestion public enum StringSplitMode { ``` ########## seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/SplitMode.java: ########## @@ -0,0 +1,43 @@ +/* + * 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.jdbc.source; + +public enum SplitMode { + LEGACY("legacy"), + + CHARSET_BASED("charsetBased"); Review Comment: ```suggestion CHARSET_BASED("charset_based"); ``` ########## seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/CharsetBasedSplitterTest.java: ########## @@ -0,0 +1,181 @@ +/* + * 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.jdbc.source; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class CharsetBasedSplitterTest { + + private static final String DEFAULT_CHARSET = "0123456789abcdefghijklmnopqrstuvwxyz"; + + @Test + @DisplayName("测试最小值和最大值的编码") + public void testMinMax() { + String minStr = "00000"; + String maxStr = "1"; + int maxLen = Math.max(minStr.length(), maxStr.length()); + String orderedCharset = "012a34b56789"; + BigInteger minBigInt = + CollationBasedSplitter.encodeStringToNumericRange( + minStr, maxLen, true, true, orderedCharset, orderedCharset.length() + 1); + System.out.println("最小值编码: " + minBigInt); Review Comment: please use log. ########## seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/CharsetBasedSplitterTest.java: ########## @@ -0,0 +1,181 @@ +/* + * 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.jdbc.source; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class CharsetBasedSplitterTest { + + private static final String DEFAULT_CHARSET = "0123456789abcdefghijklmnopqrstuvwxyz"; + + @Test + @DisplayName("测试最小值和最大值的编码") Review Comment: Please use english. ########## seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/FixedChunkSplitter.java: ########## @@ -50,6 +51,9 @@ @Slf4j public class FixedChunkSplitter extends ChunkSplitter { + private final boolean useNewStringSplitter = Review Comment: ```suggestion private final boolean useCharsetBasedStringSplitter = ``` ########## seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/config/JdbcOptions.java: ########## @@ -225,4 +224,13 @@ public interface JdbcOptions { .mapType() .noDefaultValue() .withDescription("additional connection configuration parameters"); + + Option<String> STRING_SPLIT_MODE = + Options.key("string_split_mode") + .stringType() Review Comment: ```suggestion .enumType() ``` ########## seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/SplitMode.java: ########## @@ -0,0 +1,43 @@ +/* + * 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.jdbc.source; + +public enum SplitMode { + LEGACY("legacy"), Review Comment: ```suggestion SAMPLE("sample"), ``` ########## seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/config/JdbcOptions.java: ########## @@ -225,4 +224,13 @@ public interface JdbcOptions { .mapType() .noDefaultValue() .withDescription("additional connection configuration parameters"); + + Option<String> STRING_SPLIT_MODE = + Options.key("string_split_mode") + .stringType() + .noDefaultValue() + .withDescription("stringSplitMode"); + + Option<String> COLLATE = Review Comment: ```suggestion Option<String> STRING_SPLIT_MODE_COLLATE = ``` ########## seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/DynamicChunkSplitter.java: ########## @@ -134,6 +143,93 @@ private List<ChunkRange> splitTableIntoChunks( } } + private List<ChunkRange> stringColumnSplitChunks( Review Comment: ```suggestion private List<ChunkRange> charsetBasedColumnSplitChunks( ``` ########## docs/en/connector-v2/source/Jdbc.md: ########## @@ -68,6 +68,8 @@ supports query SQL and can achieve projection effect. | split.sample-sharding.threshold | Int | No | 1000 | This configuration specifies the threshold of estimated shard count to trigger the sample sharding strategy. When the distribution factor is outside the bounds specified by `chunk-key.even-distribution.factor.upper-bound` and `chunk-key.even-distribution.factor.lower-bound`, and the estimated shard count (calculated as approximate row count / chunk size) exceeds this threshold, the sample sharding strategy will be used. This can help to handle large datasets more efficiently. The default value is 1000 shards. | | split.inverse-sampling.rate | Int | No | 1000 | The inverse of the sampling rate used in the sample sharding strategy. For example, if this value is set to 1000, it means a 1/1000 sampling rate is applied during the sampling process. This option provides flexibility in controlling the granularity of the sampling, thus affecting the final number of shards. It's especially useful when dealing with very large datasets where a lower sampling rate is preferred. The default value is 1000. | | common-options | | No | - | Source plugin common parameters, please refer to [Source Common Options](../source-common-options.md) for details. | +| string_split_mode | String | No | - | When set to "charsetBased", enables charset-based string splitting algorithm. The algorithm assumes characters of partition_column are within ASCII range 32-126, which covers most character-based splitting scenarios. | Review Comment: 1. which ones value I can set? 2. which database supported this feature? Dose all? ########## seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/DynamicChunkSplitter.java: ########## @@ -169,42 +265,63 @@ private List<ChunkRange> evenlyColumnSplitChunks( return splitEvenlySizedChunks( tablePath, min, max, approximateRowCnt, chunkSize, dynamicChunkSize); } else { - int shardCount = (int) (approximateRowCnt / chunkSize); - int inverseSamplingRate = config.getSplitInverseSamplingRate(); - if (sampleShardingThreshold < shardCount) { - // It is necessary to ensure that the number of data rows sampled by the - // sampling rate is greater than the number of shards. - // Otherwise, if the sampling rate is too low, it may result in an insufficient - // number of data rows for the shards, leading to an inadequate number of - // shards. - // Therefore, inverseSamplingRate should be less than chunkSize - if (inverseSamplingRate > chunkSize) { - log.warn( - "The inverseSamplingRate is {}, which is greater than chunkSize {}, so we set inverseSamplingRate to chunkSize", - inverseSamplingRate, - chunkSize); - inverseSamplingRate = chunkSize; - } - log.info( - "Use sampling sharding for table {}, the sampling rate is {}", - tablePath, - inverseSamplingRate); - Object[] sample = - jdbcDialect.sampleDataFromColumn( - getOrEstablishConnection(), - table, - splitColumnName, - inverseSamplingRate, - config.getFetchSize()); - log.info( - "Sample data from table {} end, the sample size is {}", - tablePath, - sample.length); - return efficientShardingThroughSampling( - tablePath, sample, approximateRowCnt, shardCount); + return getChunkRanges( + table, + splitColumnName, + min, + max, + chunkSize, + tablePath, + sampleShardingThreshold, + approximateRowCnt); + } + } + + private List<ChunkRange> getChunkRanges( Review Comment: ```suggestion private List<ChunkRange> getChunkRangesWithUnevenlyData( ``` -- 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-unsubscr...@seatunnel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org