-
Notifications
You must be signed in to change notification settings - Fork 28.9k
SPARK-22830 Scala Coding style has been improved in Spark Examples #20016
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
Conversation
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.
Not sure if it's worth. String interpolation might be closer to Scala syntax vs I wonder if it makes users to understand it more easily, in particular, who are not used to Scala.
I think I don't have a strong preference between them and I'd just leave them out.
|
@HyukjinKwon I agree with you ! But since Spark is scala project - A lot's of developers refer examples available here and if those are Java Developers they might don't understand that this is right way to do in Scala ! I had a same discussion in Scala Days with developers and I think it does make sense here too. |
|
| parseArgs(args) | ||
|
|
||
| println("Performing local word count") | ||
| println(s"Performing local word count") |
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.
There is no interpolation here; revert changes like this.
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.
@srowen Thanks for review, I did addressed changes. Please review
| println(s"Success! Local Word Count ($localWordCount) " + | ||
| s"and DFS Word Count ($dfsWordCount) agree.") | ||
| println(s"Success! Local Word Count ($localWordCount) | ||
| and DFS Word Count ($dfsWordCount) agree.") |
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.
This should be reverted; you've added a bunch of space to the string.
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.
@srowen Thanks for review, I did addressed changes. Please review.
| // Initialize w to a random value | ||
| val w = DenseVector.fill(D) {2 * rand.nextDouble - 1} | ||
| println("Initial w: " + w) | ||
| println(s"Initial w: ${w}") |
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.
You can just write $w in cases like this
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.
@srowen Thanks for review, I did addressed changes. Please review
|
|
||
| for (i <- 0 until 3) { | ||
| println("Iteration " + i) | ||
| println(s"Iteration ${i}") |
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.
Beyond the unnecessary { } that @srowen has already mentioned, this isn't really a style improvement. "a string " + anotherString is arguably at least as good stylistically as using string interpolation for such simple concatenations of a string reference to the end of a string literal. It's only when there are multiple concatenations and/or multiple string references that interpolation is clearly the better way.
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.
@markhamstra Thank you for valueable suggestion, I am addressed and did new commit.
| "\n" + | ||
| "localFile - (string) local file to use in test\n" + | ||
| "dfsDir - (string) DFS directory for read/write tests\n" | ||
| val usage = s"""DFS Read-Write Test |
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.
here you should use
"""
|...
""".stripMargin
otherwise you introduce a lot of spaces
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.
@mgaido91 Thank you for feedback, changed addressed.
| def showWarning() { | ||
| System.err.println( | ||
| """WARN: This is a naive implementation of ALS and is given as an example! | ||
| s"""WARN: This is a naive implementation of ALS and is given as an example! |
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.
please here revert the change and do the same in all similar places, since there is no variable to interpolate
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.
@mgaido91 Thank you for feedback, changed addressed.
| for (x <- mapped) { x + 2 } | ||
| val end = System.currentTimeMillis() | ||
| println("Iteration " + iter + " took " + (end-start) + " ms") | ||
| println(s"Iteration ${iter} took ${(end-start)} ms") |
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.
Let's just write as $iter and $end-start
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.
@HyukjinKwon $end-start won't work, both are different variables see. I made changes.
| def showWarning() { | ||
| System.err.println( | ||
| """WARN: This is a naive implementation of ALS and is given as an example! | ||
| s"""WARN: This is a naive implementation of ALS and is given as an example! |
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.
Seems we don't need s.
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.
@HyukjinKwon Addressed ! Kindly do review
| slices = slices_.getOrElse("2").toInt | ||
| case _ => | ||
| System.err.println("Usage: SparkALS [M] [U] [F] [iters] [partitions]") | ||
| System.err.println(s"Usage: SparkALS [M] [U] [F] [iters] [partitions]") |
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.
ditto for s.
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.
@HyukjinKwon Addressed ! Kindly do review
|
@HyukjinKwon @mgaido91 @srowen All the changes are addressed and committed, please do review and needful. |
|
Test build #4018 has finished for PR 20016 at commit
|
|
@srowen why only recent commit is going to merge, can't we get "squash merge" ? |
|
@chetkhatri not sure what you mean. The whole change here is considered, and doesn't pass style checks. Look at the test results and fix the errors. |
|
@srowen Thanks for response, correct - i went through error of jenkins and found error Online[https://amplab.cs.berkeley.edu/jenkins/job/NewSparkPullRequestBuilder/4018/console] which fixed accordingly to me and committed so please take a look, if not correct please suggest the same. |
|
Test build #4019 has finished for PR 20016 at commit
|
|
@srowen Thank you for re-run, now it passes all. |
|
@srowen I think, we can merge this now. |
|
Merged to master |
What changes were proposed in this pull request?
How was this patch tested?
Since, All changes proposed are re-writing println statements in scala way, manual run used to test println.