-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KIP-221 / Add KStream#repartition operation #7170
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
Changes from all commits
7bc0e41
597fb18
457d824
771e8e6
261aafd
ae73bee
56887ee
c3e4bd1
6fac93f
0c369e1
f641eb9
ef4fa8d
595736d
a4a661a
2ee3c31
33050f2
2dd9bbe
4f1a58b
e9a7818
ff90d5f
ebd77b5
317bd94
cffd3ec
e24d773
0918c51
a752f3f
6187f50
b029835
2f7b690
185e26b
55acc80
cb7b2df
37b393a
463a237
e6d6598
6570215
934f831
f331291
dfaccd2
1af73c9
2ccfa1e
47e338b
1bf7a15
8a9d70c
b205af8
9bdf443
a8b7b16
0fb703f
e3208eb
3180780
88886b7
83f264f
068bf52
254728c
3b25b49
d35bb44
e897952
f211f80
79812a0
8b71413
0930e5e
d3d48f9
4895ee6
4e3d695
0cbaca7
a5b41a4
de1d14d
c9979b2
765d4f4
be534f0
9efe7fc
66717dc
1d582dd
0cb229b
f2abeae
e271938
a8e3ebf
a69aad4
f2f16b0
a73b211
cfad394
1f1d1eb
69cbb68
8a5e23d
e37af65
bb4a119
f4b32fc
ed21945
6448ea9
ebeb327
162b554
5b4e415
5054ef1
6c81be8
cdbd24c
591e8ff
9fdc7ec
f2bcdfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| /* | ||
| * 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.kafka.streams.kstream; | ||
|
|
||
| import org.apache.kafka.clients.producer.internals.DefaultPartitioner; | ||
| import org.apache.kafka.common.serialization.Serde; | ||
| import org.apache.kafka.streams.kstream.internals.WindowedSerializer; | ||
| import org.apache.kafka.streams.kstream.internals.WindowedStreamPartitioner; | ||
| import org.apache.kafka.streams.processor.StreamPartitioner; | ||
|
|
||
| /** | ||
| * This class is used to provide the optional parameters for internal repartition topics. | ||
| * | ||
| * @param <K> key type | ||
| * @param <V> value type | ||
| * @see KStream#repartition() | ||
| * @see KStream#repartition(Repartitioned) | ||
| */ | ||
| public class Repartitioned<K, V> implements NamedOperation<Repartitioned<K, V>> { | ||
|
|
||
| protected final String name; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for avoiding mutable state in this class!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I agree that immutability is great, I am wondering about consistency. The other configuration classes are mutable. Do we think that might be of any concern? should we just update all other configuration classes an make them immutable, too? (Of course not in this PR...) \cc @vvcephei
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mjsax I've created JIRA ticket for it: https://issues.apache.org/jira/browse/KAFKA-9342 |
||
| protected final Serde<K> keySerde; | ||
| protected final Serde<V> valueSerde; | ||
| protected final Integer numberOfPartitions; | ||
| protected final StreamPartitioner<K, V> partitioner; | ||
|
|
||
| private Repartitioned(final String name, | ||
| final Serde<K> keySerde, | ||
| final Serde<V> valueSerde, | ||
| final Integer numberOfPartitions, | ||
| final StreamPartitioner<K, V> partitioner) { | ||
| this.name = name; | ||
| this.keySerde = keySerde; | ||
| this.valueSerde = valueSerde; | ||
| this.numberOfPartitions = numberOfPartitions; | ||
| this.partitioner = partitioner; | ||
| } | ||
|
|
||
| protected Repartitioned(final Repartitioned<K, V> repartitioned) { | ||
| this( | ||
| repartitioned.name, | ||
| repartitioned.keySerde, | ||
| repartitioned.valueSerde, | ||
| repartitioned.numberOfPartitions, | ||
| repartitioned.partitioner | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Create a {@code Repartitioned} instance with the provided name used as part of the repartition topic. | ||
| * | ||
| * @param name the name used as a processor named and part of the repartition topic name. | ||
| * @param <K> key type | ||
| * @param <V> value type | ||
| * @return A new {@code Repartitioned} instance configured with processor name and repartition topic name | ||
| * @see KStream#repartition(Repartitioned) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: do we need to add the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've followed same standard as other configurations classes (Produced, Grouped, etc). To keep things consistent maybe worth cleaning up all the config classes with redundant
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. Was just a general inquire and we don't really have a guideline for it... If you are interested, it would be great to draft some guidelines (maybe just for Kafka Streams first, and we could propose them for other client APIs, later) as a wiki page and we could discuss them on the dev mailing list? |
||
| */ | ||
| public static <K, V> Repartitioned<K, V> as(final String name) { | ||
| return new Repartitioned<>(name, null, null, null, null); | ||
| } | ||
|
|
||
| /** | ||
| * Create a {@code Repartitioned} instance with provided key serde and value serde. | ||
| * | ||
| * @param keySerde Serde to use for serializing the key | ||
| * @param valueSerde Serde to use for serializing the value | ||
| * @param <K> key type | ||
| * @param <V> value type | ||
| * @return A new {@code Repartitioned} instance configured with key serde and value serde | ||
| * @see KStream#repartition(Repartitioned) | ||
| */ | ||
| public static <K, V> Repartitioned<K, V> with(final Serde<K> keySerde, | ||
| final Serde<V> valueSerde) { | ||
| return new Repartitioned<>(null, keySerde, valueSerde, null, null); | ||
| } | ||
|
|
||
| /** | ||
| * Create a {@code Repartitioned} instance with provided partitioner. | ||
| * | ||
| * @param partitioner the function used to determine how records are distributed among partitions of the topic, | ||
| * if not specified and the key serde provides a {@link WindowedSerializer} for the key | ||
| * {@link WindowedStreamPartitioner} will be used—otherwise {@link DefaultPartitioner} will be used | ||
| * @param <K> key type | ||
| * @param <V> value type | ||
| * @return A new {@code Repartitioned} instance configured with partitioner | ||
| * @see KStream#repartition(Repartitioned) | ||
| */ | ||
| public static <K, V> Repartitioned<K, V> streamPartitioner(final StreamPartitioner<K, V> partitioner) { | ||
|
lkokhreidze marked this conversation as resolved.
|
||
| return new Repartitioned<>(null, null, null, null, partitioner); | ||
| } | ||
|
|
||
| /** | ||
| * Create a {@code Repartitioned} instance with provided number of partitions for repartition topic. | ||
| * | ||
| * @param numberOfPartitions number of partitions used when creating repartition topic | ||
| * @param <K> key type | ||
| * @param <V> value type | ||
| * @return A new {@code Repartitioned} instance configured number of partitions | ||
| * @see KStream#repartition(Repartitioned) | ||
| */ | ||
| public static <K, V> Repartitioned<K, V> numberOfPartitions(final int numberOfPartitions) { | ||
| return new Repartitioned<>(null, null, null, numberOfPartitions, null); | ||
| } | ||
|
|
||
| /** | ||
| * Create a new instance of {@code Repartitioned} with the provided name used as part of repartition topic and processor name. | ||
| * | ||
| * @param name the name used for the processor name and as part of the repartition topic | ||
| * @return a new {@code Repartitioned} instance configured with the name | ||
| */ | ||
| @Override | ||
| public Repartitioned<K, V> withName(final String name) { | ||
| return new Repartitioned<>(name, keySerde, valueSerde, numberOfPartitions, partitioner); | ||
| } | ||
|
|
||
| /** | ||
| * Create a new instance of {@code Repartitioned} with the provided number of partitions for repartition topic. | ||
| * | ||
| * @param numberOfPartitions the name used for the processor name and as part of the repartition topic name | ||
| * @return a new {@code Repartitioned} instance configured with the number of partitions | ||
| */ | ||
| public Repartitioned<K, V> withNumberOfPartitions(final int numberOfPartitions) { | ||
| return new Repartitioned<>(name, keySerde, valueSerde, numberOfPartitions, partitioner); | ||
| } | ||
|
|
||
| /** | ||
| * Create a new instance of {@code Repartitioned} with the provided key serde. | ||
| * | ||
| * @param keySerde Serde to use for serializing the key | ||
| * @return a new {@code Repartitioned} instance configured with the key serde | ||
| */ | ||
| public Repartitioned<K, V> withKeySerde(final Serde<K> keySerde) { | ||
| return new Repartitioned<>(name, keySerde, valueSerde, numberOfPartitions, partitioner); | ||
| } | ||
|
|
||
| /** | ||
| * Create a new instance of {@code Repartitioned} with the provided value serde. | ||
| * | ||
| * @param valueSerde Serde to use for serializing the value | ||
| * @return a new {@code Repartitioned} instance configured with the value serde | ||
| */ | ||
| public Repartitioned<K, V> withValueSerde(final Serde<V> valueSerde) { | ||
| return new Repartitioned<>(name, keySerde, valueSerde, numberOfPartitions, partitioner); | ||
| } | ||
|
|
||
| /** | ||
| * Create a new instance of {@code Repartitioned} with the provided partitioner. | ||
| * | ||
| * @param partitioner the function used to determine how records are distributed among partitions of the topic, | ||
| * if not specified and the key serde provides a {@link WindowedSerializer} for the key | ||
| * {@link WindowedStreamPartitioner} will be used—otherwise {@link DefaultPartitioner} wil be used | ||
| * @return a new {@code Repartitioned} instance configured with provided partitioner | ||
| */ | ||
| public Repartitioned<K, V> withStreamPartitioner(final StreamPartitioner<K, V> partitioner) { | ||
|
lkokhreidze marked this conversation as resolved.
|
||
| return new Repartitioned<>(name, keySerde, valueSerde, numberOfPartitions, partitioner); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.