Skip to content
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

[SPARK-34059][SQL][CORE][2.4] Use for/foreach rather than map to make sure execute it eagerly #31139

Closed
wants to merge 1 commit into from

Conversation

HyukjinKwon
Copy link
Member

What changes were proposed in this pull request?

This is a backport of #31110. I ran intelliJ inspection again in this branch.

This PR is basically a followup of #14332.
Calling map alone might leave it not executed due to lazy evaluation, e.g.)

scala> val foo = Seq(1,2,3)
foo: Seq[Int] = List(1, 2, 3)

scala> foo.map(println)
1
2
3
res0: Seq[Unit] = List((), (), ())

scala> foo.view.map(println)
res1: scala.collection.SeqView[Unit,Seq[_]] = SeqViewM(...)

scala> foo.view.foreach(println)
1
2
3

We should better use foreach to make sure it's executed where the output is unused or Unit.

Why are the changes needed?

To prevent the potential issues by not executing map.

Does this PR introduce any user-facing change?

No, the current codes look not causing any problem for now.

How was this patch tested?

I found these item by running IntelliJ inspection, double checked one by one, and fixed them. These should be all instances across the codebase ideally.

@HyukjinKwon
Copy link
Member Author

cc @mridulm and @srowen FYI

@SparkQA
Copy link

SparkQA commented Jan 12, 2021

Test build #133950 has finished for PR 31139 at commit da4385e.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@HyukjinKwon
Copy link
Member Author

Merged to branch-2.4.

HyukjinKwon added a commit that referenced this pull request Jan 12, 2021
… sure execute it eagerly

### What changes were proposed in this pull request?

This is a backport of #31110. I ran intelliJ inspection again in this branch.

This PR is basically a followup of #14332.
Calling `map` alone might leave it not executed due to lazy evaluation, e.g.)

```
scala> val foo = Seq(1,2,3)
foo: Seq[Int] = List(1, 2, 3)

scala> foo.map(println)
1
2
3
res0: Seq[Unit] = List((), (), ())

scala> foo.view.map(println)
res1: scala.collection.SeqView[Unit,Seq[_]] = SeqViewM(...)

scala> foo.view.foreach(println)
1
2
3
```

We should better use `foreach` to make sure it's executed where the output is unused or `Unit`.

### Why are the changes needed?

To prevent the potential issues by not executing `map`.

### Does this PR introduce _any_ user-facing change?

No, the current codes look not causing any problem for now.

### How was this patch tested?

I found these item by running IntelliJ inspection, double checked one by one, and fixed them. These should be all instances across the codebase ideally.

Closes #31139 from HyukjinKwon/SPARK-34059-2.4.

Authored-by: HyukjinKwon <gurwls223@apache.org>
Signed-off-by: HyukjinKwon <gurwls223@apache.org>
@mridulm
Copy link
Contributor

mridulm commented Jan 12, 2021

+1
Thanks for backporting this @HyukjinKwon !

@HyukjinKwon HyukjinKwon deleted the SPARK-34059-2.4 branch January 4, 2022 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants