-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Improve][Connector-V2][Kafka Sink]custom partition #2889
Conversation
Sure, I'll finish writing the documentation.Thanks for your review. |
Please solve the conflicting files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please check your code style:
mvn checkstyle:check -T 1C
- Resolving code conflicts:
git rebase refs/remotes/${apache remote-name}/dev
git push --force-with-lease
Thanks for your comment, I will fix it. |
Thanks for your review, I will follow your instructions. |
It maybe cause by #2907. After #2907 has been merged, I will rerun the failed jobs. |
Thank you for your reply, it answered my doubts. |
I have fixed it, please review it again.Thanks. |
this.topic = topic; | ||
this.partation = partation; | ||
this.jsonSerializationSchema = new JsonSerializationSchema(seaTunnelRowType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.topic = topic; | |
this.partation = partation; | |
this.jsonSerializationSchema = new JsonSerializationSchema(seaTunnelRowType); | |
this(topic, seaTunnelRowType); | |
this.partation = partation; |
} | ||
} | ||
//Choose one of the remaining partitions according to the hashcode. | ||
return (Math.abs(message.hashCode()) % (numPartitions - assignPartitionsSize)) + assignPartitionsSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Math.abs(message.hashCode()) -> message.hashCode() & Integer.MAX_VALUE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reference
private static List<String> ASSIGNPARTATIONS; | ||
|
||
public static List<String> getASSIGNPARTATIONS() { | ||
return ASSIGNPARTATIONS; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
this.partition = pluginConfig.getInt(PARTITION); | ||
} | ||
if (pluginConfig.hasPath(ASSIGN_PARTITIONS)) { | ||
ASSIGNPARTATIONS = pluginConfig.getStringList(ASSIGN_PARTITIONS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ASSIGNPARTATIONS = pluginConfig.getStringList(ASSIGN_PARTITIONS); | |
CustomPartitioner.setAssignPartitions(pluginConfig.getStringList(ASSIGN_PARTITIONS)); |
/** | ||
* Determine the partition to send based on the content of the message. | ||
*/ | ||
public static final String ASSIGN_PARTITIONS = "assign_partitions"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
...afka/src/main/java/org/apache/seatunnel/connectors/seatunnel/kafka/sink/KafkaSinkWriter.java
Outdated
Show resolved
Hide resolved
…nto par � Conflicts: � docs/en/connector-v2/source/IoTDB.md
This reverts commit 8442fd7
docs/en/connector-v2/sink/kafka.md
Outdated
|
||
Kafka Brokers List. | ||
|
||
### producer [string] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with ### kafka.* [kafka producer config]
.
@hailin0 PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class CustomPartitioner implements Partitioner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename CustomPartitioner
to MessageContentPartitioner
docs/en/connector-v2/sink/kafka.md
Outdated
|
||
Then the message containing "shoe" will be sent to partition zero ,because "shoe" is subscripted as zero in assign_partitions, and the message containing "clothing" will be sent to partition one.For other messages, the hash algorithm will be used to divide them into the remaining partitions. | ||
|
||
This function by `CustomPartitioner` class implements `org.apache.kafka.clients.producer.Partitioner` interface.If we need custom partitions, we need to implement this interface as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename CustomPartitioner
?
Purpose of this pull request
Link #2787
The following code supports two user-defined partition functions:
The first type: the user specifies the partition to send through the partition field in the config (for example, if partition 2 is specified, then the messages are sent to partition 2)
The second: the user customizes the partition through the assign_partitions field in the config
For example, there are 5 partitions in total, and the assign_partitions field in config is as follows:
assignpartitions = ["shoe", "clothing"]
Then the message containing "shoe" will be sent to partition 0 (because "shoe" is subscripted as 0 in assign_partitions), and the message containing "clothing" will be sent to partition 1,
For other messages, the hash algorithm will be used to divide them into the remaining partitions.
Check list
New License Guide