-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-6687: restrict DSL to allow only Streams from the same source topics #9609
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 1 commit
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,71 @@ | ||
| /* | ||
| * 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.internals.graph; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
| import java.util.regex.Pattern; | ||
| import org.apache.kafka.common.serialization.Serde; | ||
| import org.apache.kafka.streams.kstream.internals.ConsumedInternal; | ||
|
|
||
| abstract public class SourceGraphNode<K, V> extends StreamsGraphNode { | ||
|
|
||
| private Collection<String> topicNames; | ||
|
ableegoldman marked this conversation as resolved.
Outdated
|
||
| private Pattern topicPattern; | ||
|
ableegoldman marked this conversation as resolved.
Outdated
|
||
| private final ConsumedInternal<K, V> consumedInternal; | ||
|
|
||
| public SourceGraphNode(final String nodeName, | ||
| final Collection<String> topicNames, | ||
|
ableegoldman marked this conversation as resolved.
Outdated
|
||
| final ConsumedInternal<K, V> consumedInternal) { | ||
| super(nodeName); | ||
|
|
||
| this.topicNames = topicNames; | ||
| this.consumedInternal = consumedInternal; | ||
| } | ||
|
|
||
| public SourceGraphNode(final String nodeName, | ||
| final Pattern topicPattern, | ||
| final ConsumedInternal<K, V> consumedInternal) { | ||
|
|
||
| super(nodeName); | ||
|
|
||
| this.topicPattern = topicPattern; | ||
| this.consumedInternal = consumedInternal; | ||
| } | ||
|
|
||
| public Set<String> topicNames() { | ||
| return new HashSet<>(topicNames); | ||
|
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. Should we already demand a set of topics in the constructors of
Member
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'm not sure I understand exactly what you're asking, but I made a few changes to this topic collection/method. Please lmk if it hasn't addressed your question
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. I like your changes. What I meant is that we could change the constructor of and the one of In this way, we have a set of topics as soon as possible in the code path from the public API. I think this makes it clearer that it is not possible to have duplicates of topics internally. To keep this PR small, I would propose to just do the changes for
Member
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. Ah ok you meant making it a Set vs a Collection -- I do agree with the principle, and I did push the Set-ification of the topics up one level so that the actual class field is a Set. But I don't think it's really worth it to push it up another layer and Set-ify the constructor argument. For one thing we would just have to do the same conversion to a Set but in more places, and more importantly, the actual callers of the constructor don't care at all whether it's a Set or any other Collection. So I think it actually does make sense to convert to a Set inside the constructor body
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. Fair enough and I think that this is nothing urgent or absolute necessary. However, I would like to explain my line of thoughts. I think an interface of a class should also describe the constraints on the the object and as far as I see it does not make any sense to pass the same topic name multiple times to a source node. I am not sure I can follow your other argument
Do you refer to the creation of the singleton collection in the callers? As I said, I do not say we need to follow my proposal. I just wanted to argue in favor of a cleaner and more descriptive interface.
Member
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.
Ah ok, I didn't notice that. I guess I only looked at
This I totally agree with. I suspect the intention was just for convenience, so users don't have to do a list->set conversion themselves, but I personally don't find that to be a very strong argument. It doesn't seem worth doing a KIP over, but maybe if we rewrite some large parts of the DSL in the future, we can fix this as well By "callers" I meant the method body of But I see your point. If I touch on some related code in a future PR I can fix this on the side, or I'd be happy to review a PR if you want to submit one. Thanks for the discussion |
||
| } | ||
|
|
||
| public Pattern topicPattern() { | ||
| return topicPattern; | ||
| } | ||
|
|
||
| public ConsumedInternal<K, V> consumedInternal() { | ||
| return consumedInternal; | ||
| } | ||
|
|
||
| public Serde<K> keySerde() { | ||
| return consumedInternal.keySerde(); | ||
| } | ||
|
|
||
| public Serde<V> valueSerde() { | ||
| return consumedInternal.valueSerde(); | ||
| } | ||
|
|
||
| } | ||
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.
Can we also rename
StreamsGraphNodetoGraphNode? TheStreamsprefix is a bit confusing, IMO, becauseStreamSourceNodeandStreamsGraphNodeseem really similar although they are quite different.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.
Ok, but don't come crying when the PR blows up in length 😉 (but yeah that makes sense to me)
Uh oh!
There was an error while loading. Please reload this page.
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.
I have never said you need to do it in this PR 😉 . Jokes apart, I think in general it would be better to do such things in a separate PR, but when I wrote my comment, I completely forgot about it. Sorry about that!