You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "wuxizhi777 (via GitHub)" <gi...@apache.org> on 2023/08/06 13:07:32 UTC
[GitHub] [seatunnel] wuxizhi777 opened a new pull request, #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
wuxizhi777 opened a new pull request, #4772:
URL: https://github.com/apache/seatunnel/pull/4772
<!--
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/incubator-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
https://github.com/apache/incubator-seatunnel/issues/4770
<!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
## Check list
* [ ] Code changed are covered with tests, or it does not need tests for reason:
* [ ] If any new Jar binary package adding in your PR, please add License Notice according
[New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/contribution/new-license.md)
* [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
* [ ] If you are contributing the connector code, please check that the following files are updated:
1. Update change log that in connector document. For more details you can refer to [connector-v2](https://github.com/apache/incubator-seatunnel/tree/dev/docs/en/connector-v2)
2. Update [plugin-mapping.properties](https://github.com/apache/incubator-seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
3. Update the pom file of [seatunnel-dist](https://github.com/apache/incubator-seatunnel/blob/dev/seatunnel-dist/pom.xml)
* [ ] Update the [`release-note`](https://github.com/apache/incubator-seatunnel/blob/dev/release-note.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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [seatunnel] 1309637127 commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "1309637127 (via GitHub)" <gi...@apache.org>.
1309637127 commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1591106417
This cause 2 problems:
1、Seatunnel push data to only part of the nodes
We have 6 nodes in the product environment and only 4 nodes have data, the other have no data.
2、We expect the xxHash have the same xxHash result as Clickhouse
We have further ETL job in Clickhouse, we use cust_no as the sharding key, we expect all the data concerning with the same cust_no stay in the same node, but we've test the xxHash result with Clickhouse result they are not equal.
Below is the java xxHash and Clickhouse xxHash result "00000186620663":
java xxHash: -1055457840867779448
java xxHash & Long.MAX result: 8167914195986996360
Clickhouse xxHash: 17391286232841772168
And with the xxHash result seatunnel push the customer to shard0 and in clickhouse put the customer is in shard 5
--
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
[GitHub] [seatunnel] Carl-Zhou-CN commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "Carl-Zhou-CN (via GitHub)" <gi...@apache.org>.
Carl-Zhou-CN commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1580245968
> > @Hisoka-X ,@zhilinli123 My guess is that it may be due to the conversion of a long to an int, which resulted in a negative number.
>
> I put the results of the execution on top
I am just explaining the reason for the appearance of negative numbers.
--
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
[GitHub] [seatunnel] Hisoka-X commented on a diff in pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#discussion_r1226294038
##########
seatunnel-connectors-v2/connector-clickhouse/src/test/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/ClickhouseFactoryTest.java:
##########
@@ -24,12 +24,43 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import net.jpountz.xxhash.XXHash64;
+import net.jpountz.xxhash.XXHashFactory;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
public class ClickhouseFactoryTest {
+ private static final XXHash64 HASH_INSTANCE = XXHashFactory.fastestInstance().hash64();
@Test
public void testOptionRule() {
Assertions.assertNotNull((new ClickhouseSourceFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseSinkFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseFileSinkFactory()).optionRule());
}
+
+ public int getShard(Object shardValue) {
+ int shardWeightCount = 6;
+ int offset =
+ (int)
+ ((HASH_INSTANCE.hash(
+ ByteBuffer.wrap(
+ shardValue
+ .toString()
+ .getBytes(StandardCharsets.UTF_8)),
+ 0)
+ & Long.MAX_VALUE)
+ % shardWeightCount);
+ return offset;
+ }
+
+ @Test
+ public void testShared() {
+ String a = "a,b,c,d,e,f";
+ for (Object o : Arrays.stream(a.split(",")).toArray()) {
+ System.out.println(getShard(o));
Review Comment:
Please use `Assertions` to make sure to result are right. Also please provide the test case to make sure to all shard can be selected. Tips: make we can use 10000 keys with random string to invoke `getShard` then get each shard index count which return by `getShard`. I believe when the number of keys more large, the shard index will be more balanced.
--
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
[GitHub] [seatunnel] Hisoka-X commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1579767171
@zhilinli123 Any reason for negative result?
--
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
[GitHub] [seatunnel] Hisoka-X commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1578010602
Good catch! Can you add UT for `getShard` method? Thanks
--
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
[GitHub] [seatunnel] zhilinli123 commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1578021152
> Good catch! Can you add UT for `getShard` method? Thanks
<img width="1033" alt="image" src="https://github.com/apache/seatunnel/assets/76689593/18fb6751-7399-4c15-b990-6a10a63dca18">
It's not a negative number, right?
--
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] [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key [seatunnel]
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#discussion_r1640607412
##########
seatunnel-connectors-v2/connector-clickhouse/src/test/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/ClickhouseFactoryTest.java:
##########
@@ -24,12 +24,56 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import net.jpountz.xxhash.XXHash64;
+import net.jpountz.xxhash.XXHashFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
public class ClickhouseFactoryTest {
+ private static final XXHash64 HASH_INSTANCE = XXHashFactory.fastestInstance().hash64();
@Test
public void testOptionRule() {
Assertions.assertNotNull((new ClickhouseSourceFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseSinkFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseFileSinkFactory()).optionRule());
}
+
+ @Test
+ public void testShared() {
Review Comment:
The test case look weird, it only prove the logic of `(hashValue & Long.MAX_VALUE) % modulo` are right. But can not make sure the `getShard` method return right result. I think the test case should test `getShard` method.
--
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
[GitHub] [seatunnel] Hisoka-X commented on a diff in pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#discussion_r1226294038
##########
seatunnel-connectors-v2/connector-clickhouse/src/test/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/ClickhouseFactoryTest.java:
##########
@@ -24,12 +24,43 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import net.jpountz.xxhash.XXHash64;
+import net.jpountz.xxhash.XXHashFactory;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
public class ClickhouseFactoryTest {
+ private static final XXHash64 HASH_INSTANCE = XXHashFactory.fastestInstance().hash64();
@Test
public void testOptionRule() {
Assertions.assertNotNull((new ClickhouseSourceFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseSinkFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseFileSinkFactory()).optionRule());
}
+
+ public int getShard(Object shardValue) {
+ int shardWeightCount = 6;
+ int offset =
+ (int)
+ ((HASH_INSTANCE.hash(
+ ByteBuffer.wrap(
+ shardValue
+ .toString()
+ .getBytes(StandardCharsets.UTF_8)),
+ 0)
+ & Long.MAX_VALUE)
+ % shardWeightCount);
+ return offset;
+ }
+
+ @Test
+ public void testShared() {
+ String a = "a,b,c,d,e,f";
+ for (Object o : Arrays.stream(a.split(",")).toArray()) {
+ System.out.println(getShard(o));
Review Comment:
Please use `Assertions` to make sure to result are right. Also please provide the test case to make sure to all shard can be selected. Tips: maybe we can use 10000 keys with random string to invoke `getShard` then get each shard index count which return by `getShard`. I believe when the number of keys more large, the shard index will be more balanced.
--
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] [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key [seatunnel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-3100149484
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
[GitHub] [seatunnel] ic4y closed pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "ic4y (via GitHub)" <gi...@apache.org>.
ic4y closed pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
URL: https://github.com/apache/seatunnel/pull/4772
--
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
[GitHub] [seatunnel] Hisoka-X commented on a diff in pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#discussion_r1227719054
##########
seatunnel-connectors-v2/connector-clickhouse/src/test/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/ClickhouseFactoryTest.java:
##########
@@ -24,12 +24,43 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import net.jpountz.xxhash.XXHash64;
+import net.jpountz.xxhash.XXHashFactory;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
public class ClickhouseFactoryTest {
+ private static final XXHash64 HASH_INSTANCE = XXHashFactory.fastestInstance().hash64();
@Test
public void testOptionRule() {
Assertions.assertNotNull((new ClickhouseSourceFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseSinkFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseFileSinkFactory()).optionRule());
}
+
+ public int getShard(Object shardValue) {
+ int shardWeightCount = 6;
+ int offset =
+ (int)
+ ((HASH_INSTANCE.hash(
+ ByteBuffer.wrap(
+ shardValue
+ .toString()
+ .getBytes(StandardCharsets.UTF_8)),
+ 0)
+ & Long.MAX_VALUE)
+ % shardWeightCount);
+ return offset;
+ }
+
+ @Test
+ public void testShared() {
+ String a = "a,b,c,d,e,f";
+ for (Object o : Arrays.stream(a.split(",")).toArray()) {
+ System.out.println(getShard(o));
Review Comment:
Great, please add this part test code to branch. Also remember, `Please use Assertions`
--
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
[GitHub] [seatunnel] Carl-Zhou-CN commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "Carl-Zhou-CN (via GitHub)" <gi...@apache.org>.
Carl-Zhou-CN commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1579991123
@Hisoka-X ,@zhilinli123 I think it's probably a long strong int, which makes it a negative number
--
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
[GitHub] [seatunnel] zhilinli123 commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1578004515
PTAL : @Hisoka-X
--
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
[GitHub] [seatunnel] zhilinli123 commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1578052292
> > It's not a negative number, right? @Hisoka-X
>
> @zhilinli123 It can't be negative. I suggest compare two result of change before and change after.
```
@Test
public void testHashValue() {
String a = "a,b,c,d,e,f";
for (Object o : Arrays.stream(a.split(",")).toArray()) {
System.out.println(getShard(o));
}
}
public int getShard(Object shardValue) {
int offset =
(int)
(HASH_INSTANCE.hash(
ByteBuffer.wrap(
shardValue
.toString()
.getBytes(StandardCharsets.UTF_8)),
0)
& Long.MAX_VALUE % 6);
return offset;
}
```
```
// Before After
// 1 -5
// 1 3
// 1 -5
// 0 2
// 0 4
// 1 -3
```
--
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
[GitHub] [seatunnel] zhilinli123 commented on a diff in pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on code in PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#discussion_r1226857544
##########
seatunnel-connectors-v2/connector-clickhouse/src/test/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/ClickhouseFactoryTest.java:
##########
@@ -24,12 +24,43 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import net.jpountz.xxhash.XXHash64;
+import net.jpountz.xxhash.XXHashFactory;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
public class ClickhouseFactoryTest {
+ private static final XXHash64 HASH_INSTANCE = XXHashFactory.fastestInstance().hash64();
@Test
public void testOptionRule() {
Assertions.assertNotNull((new ClickhouseSourceFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseSinkFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseFileSinkFactory()).optionRule());
}
+
+ public int getShard(Object shardValue) {
+ int shardWeightCount = 6;
+ int offset =
+ (int)
+ ((HASH_INSTANCE.hash(
+ ByteBuffer.wrap(
+ shardValue
+ .toString()
+ .getBytes(StandardCharsets.UTF_8)),
+ 0)
+ & Long.MAX_VALUE)
+ % shardWeightCount);
+ return offset;
+ }
+
+ @Test
+ public void testShared() {
+ String a = "a,b,c,d,e,f";
+ for (Object o : Arrays.stream(a.split(",")).toArray()) {
+ System.out.println(getShard(o));
Review Comment:
> Please use `Assertions` to make sure to result are right. Also please provide the test case to make sure to all shard can be selected. Tips: maybe we can use 10000 keys with random string to invoke `getShard` then get each shard index count which return by `getShard`. I believe when the number of keys more large, the shard index will be more balanced.
```
public static void main(String[] args) {
// Create an instance of the XXHash64 algorithm
XXHashFactory factory = XXHashFactory.fastestInstance();
XXHash64 hash64 = factory.hash64();
// Define your input data
byte[] input;
ArrayList<String> strings = new ArrayList<>();
Map<Long, Long> resultCount = new HashMap<>();
for (int i = 1; i <= 100000; i++) {
input = UUID.randomUUID().toString().getBytes();
// Calculate the hash value
long hashValue = hash64.hash(input, 0, input.length, 0);
// Apply modulo operation to get a non-negative result
int modulo = 6;
long nonNegativeResult = (hashValue & Long.MAX_VALUE) % modulo;
Long keyValue = resultCount.get(nonNegativeResult); /
if (keyValue != null) {
resultCount.put(nonNegativeResult, keyValue + 1L);
} else {
resultCount.put(nonNegativeResult, 1L);
}
// Print the non-negative result
// System.out.println("Non-negative result: " + nonNegativeResult);
}
Long totalResult = 0L;
for (Long key : resultCount.keySet()) {
System.out.println("Key:"+key+" count:"+resultCount.get(key));
totalResult+=resultCount.get(key);
}
System.out.println("Sum:"+totalResult);
// Console Result:
// Key:0 count:16651
// Key:1 count:16595
// Key:2 count:16648
// Key:3 count:16650
// Key:4 count:16946
// Key:5 count:16510
// Sum:100000
}
```
Looks good, PTAL
--
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
[GitHub] [seatunnel] zhilinli123 commented on a diff in pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on code in PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#discussion_r1226857544
##########
seatunnel-connectors-v2/connector-clickhouse/src/test/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/ClickhouseFactoryTest.java:
##########
@@ -24,12 +24,43 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import net.jpountz.xxhash.XXHash64;
+import net.jpountz.xxhash.XXHashFactory;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
public class ClickhouseFactoryTest {
+ private static final XXHash64 HASH_INSTANCE = XXHashFactory.fastestInstance().hash64();
@Test
public void testOptionRule() {
Assertions.assertNotNull((new ClickhouseSourceFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseSinkFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseFileSinkFactory()).optionRule());
}
+
+ public int getShard(Object shardValue) {
+ int shardWeightCount = 6;
+ int offset =
+ (int)
+ ((HASH_INSTANCE.hash(
+ ByteBuffer.wrap(
+ shardValue
+ .toString()
+ .getBytes(StandardCharsets.UTF_8)),
+ 0)
+ & Long.MAX_VALUE)
+ % shardWeightCount);
+ return offset;
+ }
+
+ @Test
+ public void testShared() {
+ String a = "a,b,c,d,e,f";
+ for (Object o : Arrays.stream(a.split(",")).toArray()) {
+ System.out.println(getShard(o));
Review Comment:
> Please use `Assertions` to make sure to result are right. Also please provide the test case to make sure to all shard can be selected. Tips: maybe we can use 10000 keys with random string to invoke `getShard` then get each shard index count which return by `getShard`. I believe when the number of keys more large, the shard index will be more balanced.
```
public static void main(String[] args) {
// Create an instance of the XXHash64 algorithm
XXHashFactory factory = XXHashFactory.fastestInstance();
XXHash64 hash64 = factory.hash64();
// Define your input data
byte[] input;
ArrayList<String> strings = new ArrayList<>();
Map<Long, Long> resultCount = new HashMap<>();
for (int i = 1; i <= 100000; i++) {
input = UUID.randomUUID().toString().getBytes();
// Calculate the hash value
long hashValue = hash64.hash(input, 0, input.length, 0);
// Apply modulo operation to get a non-negative result
int modulo = 6;
long nonNegativeResult = (hashValue & Long.MAX_VALUE) % modulo;
Long keyValue = resultCount.get(nonNegativeResult); // 获取当前键值对应的值
if (keyValue != null) {
resultCount.put(nonNegativeResult, keyValue + 1L);
} else {
resultCount.put(nonNegativeResult, 1L);
}
// Print the non-negative result
// System.out.println("Non-negative result: " + nonNegativeResult);
}
Long totalResult = 0L;
for (Long key : resultCount.keySet()) {
System.out.println("Key:"+key+" count:"+resultCount.get(key));
totalResult+=resultCount.get(key);
}
System.out.println("Sum:"+totalResult);
// Console Result:
// Key:0 count:16651
// Key:1 count:16595
// Key:2 count:16648
// Key:3 count:16650
// Key:4 count:16946
// Key:5 count:16510
// Sum:100000
}
```
Looks good, PTAL
--
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
[GitHub] [seatunnel] zhilinli123 commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1578863668
> > It's not a negative number, right? @Hisoka-X
>
> @zhilinli123 It can't be negative. I suggest compare two result of change before and change after.
```
public static void main(String[] args) {
// Create an instance of the XXHash64 algorithm
XXHashFactory factory = XXHashFactory.fastestInstance();
XXHash64 hash64 = factory.hash64();
// Define your input data
byte[] input ;
String a = "a,b,c,d,e,f";
for (String inputs : a.split(",")) {
input = inputs.getBytes();
// Calculate the hash value
long hashValue = hash64.hash(input, 0, input.length, 0);
// Apply modulo operation to get a non-negative result
int modulo = 6;
long nonNegativeResult = (hashValue & Long.MAX_VALUE) % modulo;
// Print the non-negative result
System.out.println("Non-negative result: " + nonNegativeResult);
}
}
```
I have written a simple test demo about this problem, please help to see if it meets the expectations
@Hisoka-X
--
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
[GitHub] [seatunnel] Hisoka-X commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1578027014
> It's not a negative number, right? @Hisoka-X
@zhilinli123 It can't be negative. I suggest compare two result of change before and change after.
--
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] [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key [seatunnel]
Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on code in PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#discussion_r1371481646
##########
.idea/vcs.xml:
##########
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
Review Comment:
revert this file
--
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] [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key [seatunnel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-3067449772
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
[GitHub] [seatunnel] TyrantLucifer commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "TyrantLucifer (via GitHub)" <gi...@apache.org>.
TyrantLucifer commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1585628049
@Hisoka-X PTAL.
--
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
[GitHub] [seatunnel] wuxizhi777 commented on a diff in pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "wuxizhi777 (via GitHub)" <gi...@apache.org>.
wuxizhi777 commented on code in PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#discussion_r1228242470
##########
seatunnel-connectors-v2/connector-clickhouse/src/test/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/ClickhouseFactoryTest.java:
##########
@@ -24,12 +24,43 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import net.jpountz.xxhash.XXHash64;
+import net.jpountz.xxhash.XXHashFactory;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
public class ClickhouseFactoryTest {
+ private static final XXHash64 HASH_INSTANCE = XXHashFactory.fastestInstance().hash64();
@Test
public void testOptionRule() {
Assertions.assertNotNull((new ClickhouseSourceFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseSinkFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseFileSinkFactory()).optionRule());
}
+
+ public int getShard(Object shardValue) {
+ int shardWeightCount = 6;
+ int offset =
+ (int)
+ ((HASH_INSTANCE.hash(
+ ByteBuffer.wrap(
+ shardValue
+ .toString()
+ .getBytes(StandardCharsets.UTF_8)),
+ 0)
+ & Long.MAX_VALUE)
+ % shardWeightCount);
+ return offset;
+ }
+
+ @Test
+ public void testShared() {
+ String a = "a,b,c,d,e,f";
+ for (Object o : Arrays.stream(a.split(",")).toArray()) {
+ System.out.println(getShard(o));
Review Comment:
ok, boss, I hown
--
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
[GitHub] [seatunnel] zhilinli123 commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1667120538
PTAL: @Hisoka-X
--
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
[GitHub] [seatunnel] Carl-Zhou-CN commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "Carl-Zhou-CN (via GitHub)" <gi...@apache.org>.
Carl-Zhou-CN commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1581832902
@wuxizhi777 You're right. Can you help add this test case to 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
[GitHub] [seatunnel] Carl-Zhou-CN commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "Carl-Zhou-CN (via GitHub)" <gi...@apache.org>.
Carl-Zhou-CN commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1580253394
I think
int offset =
(int)
(HASH_INSTANCE.hash(
ByteBuffer.wrap(
shardValue
.toString()
.getBytes(StandardCharsets.UTF_8)),
0)
& Integer.MAX_VALUE) % 6 ;
--
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
[GitHub] [seatunnel] wuxizhi777 commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "wuxizhi777 (via GitHub)" <gi...@apache.org>.
wuxizhi777 commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1581822978
public class test {
private static final XXHash64 HASH_INSTANCE = XXHashFactory.fastestInstance().hash64();
public int getShard(Object shardValue){
int shardWeightCount = 6;
int offset =
(int)
((HASH_INSTANCE.hash(
ByteBuffer.wrap(
shardValue
.toString()
.getBytes(StandardCharsets.UTF_8)),
0)
& Long.MAX_VALUE)
% shardWeightCount);
return offset;
}
@Test
public void testShared(){
String a = "a,b,c,d,e,f";
for(Object o: Arrays.stream(a.split(",")).toArray()){
System.out.println(getShard(o));
}
}
}
===================
the result is :
3
3
3
2
4
5
--
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
[GitHub] [seatunnel] zhilinli123 commented on pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#issuecomment-1580177497
> @Hisoka-X ,@zhilinli123 My guess is that it may be due to the conversion of a long to an int, which resulted in a negative number.
I put the results of the execution on top
--
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
[GitHub] [seatunnel] zhilinli123 commented on a diff in pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on code in PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#discussion_r1227781494
##########
seatunnel-connectors-v2/connector-clickhouse/src/test/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/ClickhouseFactoryTest.java:
##########
@@ -24,12 +24,43 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import net.jpountz.xxhash.XXHash64;
+import net.jpountz.xxhash.XXHashFactory;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
public class ClickhouseFactoryTest {
+ private static final XXHash64 HASH_INSTANCE = XXHashFactory.fastestInstance().hash64();
@Test
public void testOptionRule() {
Assertions.assertNotNull((new ClickhouseSourceFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseSinkFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseFileSinkFactory()).optionRule());
}
+
+ public int getShard(Object shardValue) {
+ int shardWeightCount = 6;
+ int offset =
+ (int)
+ ((HASH_INSTANCE.hash(
+ ByteBuffer.wrap(
+ shardValue
+ .toString()
+ .getBytes(StandardCharsets.UTF_8)),
+ 0)
+ & Long.MAX_VALUE)
+ % shardWeightCount);
+ return offset;
+ }
+
+ @Test
+ public void testShared() {
+ String a = "a,b,c,d,e,f";
+ for (Object o : Arrays.stream(a.split(",")).toArray()) {
+ System.out.println(getShard(o));
Review Comment:
> Great, please add this part test code to branch. Also remember, `Please use Assertions`
CC @wuxizhi777
--
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] [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key [seatunnel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #4772: [Bug] [seatunnel-connectors] [seatunnel-connector-spark-clickhouse] Data cannot be imported to all nodes by configuring split_mode and sharding_key
URL: https://github.com/apache/seatunnel/pull/4772
--
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