Skip to content

Fix Streams Scala foreach recursive call#5539

Merged
guozhangwang merged 1 commit intoapache:trunkfrom
joan38:fix-foreach
Aug 24, 2018
Merged

Fix Streams Scala foreach recursive call#5539
guozhangwang merged 1 commit intoapache:trunkfrom
joan38:fix-foreach

Conversation

@joan38
Copy link
Copy Markdown
Contributor

@joan38 joan38 commented Aug 20, 2018

Due to lack of conversion to kstream Predicate, existing foreach method in KStream.scala would result in StackOverflowError.

This PR fixes the bug and adds testing for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😉

@guozhangwang
Copy link
Copy Markdown
Contributor

@vvcephei could you take a look?

@joan38
Copy link
Copy Markdown
Contributor Author

joan38 commented Aug 22, 2018

This PR is good to go.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this is a public interface change, and would require a KIP.

Note that we don't really need the implicit; it just makes the internal implementation nicer. You could instead do:

def foreach(action: (K, V) => Unit): Unit =
    inner.foreach(new ForeachAction[K, V] {
      override def apply(key: K, value: V): Unit = action(key, value)
    })

right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we could.

@vvcephei
Copy link
Copy Markdown
Contributor

Can you explain the mechanism by which the call becomes recursive? I feel like I'm missing it...

@vvcephei
Copy link
Copy Markdown
Contributor

Can you please add a brief description? The description will become the commit message when we squash and merge.

Also, does it make sense to reference KAFKA-7316 also in this PR's title? You could drop a quick comment on that ticket that forEach is also affected.

@joan38
Copy link
Copy Markdown
Contributor Author

joan38 commented Aug 22, 2018

Basically it's doing an implicit conversion back to the Scala API threw the ImplicitConversions._ import

@joan38 joan38 force-pushed the fix-foreach branch 2 times, most recently from 4d8de11 to 211abd0 Compare August 22, 2018 21:58
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it's not public anymore

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I misread this before. This class was already defaulted to public visibility, and we can't retract it now, without a KIP.

I recommend moving the private[streams] to just the new method.

Sorry for the confusion.

( I wish I had noticed before that the whole object was public unnecessarily )

@vvcephei
Copy link
Copy Markdown
Contributor

Oh, I get it. I'd forgotten that we have (e.g.) implicit def wrapKStream[K, V](inner: KStreamJ[K, V]): KStream[K, V]

@joan38
Copy link
Copy Markdown
Contributor Author

joan38 commented Aug 23, 2018

Are we good with this one @vvcephei ?

@guozhangwang
Copy link
Copy Markdown
Contributor

@joan38 last commit causes some conflicts, you'd need to rebase this PR again.

@joan38
Copy link
Copy Markdown
Contributor Author

joan38 commented Aug 23, 2018

I will, in an hour or so.

@vvcephei
Copy link
Copy Markdown
Contributor

@joan38 Also, please see my note on privatizing FunctionConversions. I misread it yesterday.

@joan38
Copy link
Copy Markdown
Contributor Author

joan38 commented Aug 23, 2018

Sure I can do that.

@joan38
Copy link
Copy Markdown
Contributor Author

joan38 commented Aug 23, 2018

@guozhangwang All good to merge

@guozhangwang guozhangwang merged commit b8559de into apache:trunk Aug 24, 2018
@joan38 joan38 deleted the fix-foreach branch August 24, 2018 00:41
@vvcephei
Copy link
Copy Markdown
Contributor

@guozhangwang This needs to be cherry-picked to 2.0

guozhangwang pushed a commit that referenced this pull request Aug 29, 2018
Reviewers: Guozhang Wang <guozhang@confluent.io>, John Roesler <john@confluent.io>
@guozhangwang
Copy link
Copy Markdown
Contributor

Thanks for the reminder! Just did it.

pengxiaolong pushed a commit to pengxiaolong/kafka that referenced this pull request Jun 14, 2019
Reviewers: Guozhang Wang <guozhang@confluent.io>, John Roesler <john@confluent.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants