-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-6958: Allow to name operation using parameter classes #6410
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
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 |
|---|---|---|
|
|
@@ -29,9 +29,9 @@ | |
| * @param <K> the key type | ||
| * @param <V> the value type | ||
| */ | ||
| public class Grouped<K, V> { | ||
| public class Grouped<K, V> implements NamedOperation<Grouped<K, V>> { | ||
|
|
||
| protected final Serde<K> keySerde; | ||
| protected final Serde<K> keySerde; | ||
| protected final Serde<V> valueSerde; | ||
| protected final String name; | ||
|
|
||
|
|
@@ -128,9 +128,10 @@ public static <K, V> Grouped<K, V> with(final Serde<K> keySerde, | |
| * Perform the grouping operation with the name for a repartition topic if required. Note | ||
| * that Kafka Streams does not always create repartition topics for grouping operations. | ||
| * | ||
| * @param name the name used as part of the repartition topic name if required | ||
| * @param name the name used for the processor name and as part of the repartition topic name if required | ||
| * @return a new {@link Grouped} instance configured with the name | ||
| * */ | ||
| @Override | ||
| public Grouped<K, V> withName(final String name) { | ||
|
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. Because |
||
| return new Grouped<>(name, keySerde, valueSerde); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * 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.streams.errors.TopologyException; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class Named implements NamedOperation<Named> { | ||
|
|
||
| private static final int MAX_NAME_LENGTH = 249; | ||
|
|
||
| protected String name; | ||
|
|
||
| protected Named(final String name) { | ||
| this.name = name; | ||
| if (name != null) { | ||
| validate(name); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create a Named instance with provided name. | ||
| * | ||
| * @param name the processor name to be used. If {@code null} a default processor name will be generated. | ||
| * @return A new {@link Named} instance configured with name | ||
| * | ||
| * @throws TopologyException if an invalid name is specified; valid characters are ASCII alphanumerics, '.', '_' and '-'. | ||
| */ | ||
| public static Named as(final String name) { | ||
| Objects.requireNonNull(name, "name can't be null"); | ||
|
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. Seems not to align with the JavaDoc. I think passing in |
||
| return new Named(name); | ||
| } | ||
|
|
||
| @Override | ||
| public Named withName(final String name) { | ||
| return new Named(name); | ||
| } | ||
|
|
||
| static void validate(final String name) { | ||
| if (name.isEmpty()) | ||
| throw new TopologyException("Name is illegal, it can't be empty"); | ||
| if (name.equals(".") || name.equals("..")) | ||
| throw new TopologyException("Name cannot be \".\" or \"..\""); | ||
| if (name.length() > MAX_NAME_LENGTH) | ||
| throw new TopologyException("Name is illegal, it can't be longer than " + MAX_NAME_LENGTH + | ||
| " characters, name: " + name); | ||
| if (!containsValidPattern(name)) | ||
| throw new TopologyException("Name \"" + name + "\" is illegal, it contains a character other than " + | ||
| "ASCII alphanumerics, '.', '_' and '-'"); | ||
| } | ||
|
|
||
| /** | ||
| * Valid characters for Kafka topics are the ASCII alphanumerics, '.', '_', and '-' | ||
| */ | ||
| private static boolean containsValidPattern(final String topic) { | ||
| for (int i = 0; i < topic.length(); ++i) { | ||
| final char c = topic.charAt(i); | ||
|
|
||
| // We don't use Character.isLetterOrDigit(c) because it's slower | ||
| final boolean validLetterOrDigit = (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'); | ||
| final boolean validChar = validLetterOrDigit || c == '.' || c == '_' || c == '-'; | ||
| if (!validChar) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,9 +31,10 @@ | |
| * @param <V> value type | ||
| * @see KStream#print(Printed) | ||
| */ | ||
| public class Printed<K, V> { | ||
| public class Printed<K, V> implements NamedOperation<Printed<K, V>> { | ||
|
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. According to the KIP
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. @bbejeck If we add a method I think we should not add the
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. That sounds good to me, and if I recall correctly we had similar reasons for not adding
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. SGTM. If we update the KIP, we should send a follow up email to the VOTE thread summarizing the changes (we can do this after all PRs are merged in case there is more) |
||
| protected final OutputStream outputStream; | ||
| protected String label; | ||
| protected String processorName; | ||
| protected KeyValueMapper<? super K, ? super V, String> mapper = new KeyValueMapper<K, V, String>() { | ||
| @Override | ||
| public String apply(final K key, final V value) { | ||
|
|
@@ -53,6 +54,7 @@ protected Printed(final Printed<K, V> printed) { | |
| this.outputStream = printed.outputStream; | ||
| this.label = printed.label; | ||
| this.mapper = printed.mapper; | ||
| this.processorName = printed.processorName; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -122,4 +124,16 @@ public Printed<K, V> withKeyValueMapper(final KeyValueMapper<? super K, ? super | |
| this.mapper = mapper; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Print the records of a {@link KStream} with provided processor name. | ||
| * | ||
| * @param processorName the processor name to be used. If {@code null} a default processor name will be generated | ||
| ** @return this | ||
| */ | ||
| @Override | ||
| public Printed<K, V> withName(final String processorName) { | ||
|
fhussonnois marked this conversation as resolved.
Outdated
|
||
| this.processorName = processorName; | ||
| return this; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.