Uh oh!
There was an error while loading. Please reload this page.
SPARK-22896 Improvement in String interpolation - #20070
Conversation
srowen
commented
Dec 26, 2017
OK, we can do this for consistency. In general we don't spend a ton of time on changes like this, because there is already way too much else to review. Please make one change only (this one) that updates all examples in one go. |
chetkhatri
commented
Dec 26, 2017
@srowen Absolutely correct, this all in one shot. I did changes in all. |
chetkhatri
commented
Dec 26, 2017
@srowen also i did merge another similiar PR with graphx to here. so Just FYI - we are good. |
srowen
commented
Dec 26, 2017
I think there are many more examples of this; a quick search suggests there are about 40 example files that have some string concatenation. |
chetkhatri
commented
Dec 26, 2017
In scala ? I don't think so. I am re-iterating and doing double check. |
chetkhatri
commented
Dec 26, 2017
You're correct - I missed other packages. I will re-confirm soon. Thanks. |
chetkhatri
commented
Dec 26, 2017
@srowen I rechecked all scala examples and this is commulative PR for the same. |
srowen
left a comment
There was a problem hiding this comment.
A few small comments here but looking fine as an improvement. Also have a look for more old .format() calls if you like; we could update those.
| .partitionBy(partitionStrategy.getOrElse(RandomVertexCut)).cache() | ||
| val triangles = TriangleCount.run(graph) | ||
| println("Triangles: " + triangles.vertices.map { | ||
| println(s"Triangles: ${triangles.vertices.map { |
There was a problem hiding this comment.
This is probably more readable if the expression is stored in a local val first. Anything nontrivial like this gets hard to parse in an interpolated string. While we're here, worth fixing up.
| println("pValues = " + chi.getAs[Vector](0)) | ||
| println("degreesOfFreedom = " + chi.getSeq[Int](1).mkString("[", ",", "]")) | ||
| println("statistics = " + chi.getAs[Vector](2)) | ||
| println(s"pValues = ${chi.getAs[Vector](0)}") |
There was a problem hiding this comment.
I think this is OK; anything more complex I might suggest breaking out the expression into a val.
| val df = data.map(Tuple1.apply).toDF("features") | ||
| val Row(coeff1: Matrix) = Correlation.corr(df, "features").head | ||
| println("Pearson correlation matrix:\n" + coeff1.toString) | ||
| println(s"Pearson correlation matrix:\n ${coeff1.toString}") |
There was a problem hiding this comment.
Another thing we could improve: .toString is redundant here I believe
| } | ||
| /** Number of classes the label can take. 2 indicates binary classification. */ | ||
| // Number of classes the label can take. 2 indicates binary classification. |
There was a problem hiding this comment.
Yeah, good to make this a standard comment, not scaladoc style
| // $example on$ | ||
| val data = Array((0, 18.0), (1, 19.0), (2, 8.0), (3, 5.0), (4, 2.2)) | ||
| val df = spark.createDataFrame(data).toDF("id", "hour") | ||
| val df = spark.createDataFrame(data).toDF("id", "hour").repartition(1) |
There was a problem hiding this comment.
Although it looks weird, I think the author intended the repartition(1) to not appear in the body of the example that's copied into the docs. I wouldn't change this.
| var userInput: String = null | ||
| try { | ||
| logInfo("Connecting to " + host + ":" + port) | ||
| logInfo(s"Connecting to $host $port") |
There was a problem hiding this comment.
Nit: we could make the string consistent with the one two lines below by adding a colon
SparkQA
commented
Dec 28, 2017
Test build #4026 has finished for PR 20070 at commit
|
| } | ||
| // scalastyle:on println | ||
| // scalastyle:on println No newline at end of file |
There was a problem hiding this comment.
It didn't like the lack of newline at the end of this file
left a comment
There was a problem hiding this comment.
@srowen apologize for delay :) I have addressed suggestion. thanks
| } | ||
| // scalastyle:on println | ||
| // scalastyle:on println No newline at end of file |
| var userInput: String = null | ||
| try { | ||
| logInfo("Connecting to " + host + ":" + port) | ||
| logInfo(s"Connecting to $host $port") |
commented
Dec 29, 2017
Test build #4028 has finished for PR 20070 at commit
|
commented
Dec 29, 2017
@srowen please do re-run the build. |
commented
Dec 29, 2017
Test build #4029 has finished for PR 20070 at commit
|
| println(s"Chose ${categoricalFeatures.size} categorical features: " + | ||
| categoricalFeatures.mkString(", ")) | ||
| println(s"Chose ${categoricalFeatures.size} " + | ||
| s"categorical features: {$categoricalFeatures.mkString(", ")}") |
There was a problem hiding this comment.
Typo here. Please make sure build/test/style passes locally before pushing again, or else this takes a lot of work to review.
There was a problem hiding this comment.
I did fixed this. Can you please give me steps as a check list before commit for test.
commented
Dec 30, 2017
Test build #4031 has finished for PR 20070 at commit
|
commented
Dec 30, 2017
@srowen Okey. current status looks good |
| val result = discretizer.fit(df).transform(df) | ||
| result.show() | ||
| result.show(false) |
There was a problem hiding this comment.
One more question - is it necessary to make this not truncate?
There was a problem hiding this comment.
We're following same style in other examples so it is good to do.
There was a problem hiding this comment.
Which other examples? most do not set this, and the Java equivalent doesn't either. If there's a good reason that the output needs to be untruncated, that's fine, just also change the Java example.
There was a problem hiding this comment.
@srowen correct either way it works for ex. examples/ml/LDAExamples.scala
| val featureTestResults: Array[ChiSqTestResult] = Statistics.chiSqTest(obs) | ||
| featureTestResults.zipWithIndex.foreach { case (k, v) => | ||
| println("Column " + (v + 1).toString + ":") | ||
| println(s"Column ${(v + 1).toString} :") |
There was a problem hiding this comment.
.toString is redundant here and elsewhere with interpolation. I think that should be simplified.
| print("Topic " + topic + ":") | ||
| for (word <- Range(0, ldaModel.vocabSize)) { print(" " + topics(word, topic)); } | ||
| print(s"Topic $topic :") | ||
| for (word <- Range(0, ldaModel.vocabSize)) { print(s" ${topics(word, topic)}") } |
There was a problem hiding this comment.
Go ahead and put the print on a new line (I know it wasn't before)
There was a problem hiding this comment.
@srowen Thanks for suggestion, it has been addressed.
| val result = discretizer.fit(df).transform(df) | ||
| result.show() | ||
| result.show(false) |
There was a problem hiding this comment.
Which other examples? most do not set this, and the Java equivalent doesn't either. If there's a good reason that the output needs to be untruncated, that's fine, just also change the Java example.
| print(s"Topic $topic :") | ||
| for (word <- Range(0, ldaModel.vocabSize)) { print(s" ${topics(word, topic)}") } | ||
| for (word <- Range(0, ldaModel.vocabSize)) | ||
| { |
There was a problem hiding this comment.
No, we put the open brace on the preceding line with for, and don't triple indent. See any other for loop in the code.
commented
Jan 3, 2018
@srowen Request for review when you get on this. |
commented
Jan 3, 2018
Test build #4033 has finished for PR 20070 at commit
|
commented
Jan 3, 2018 •
Merged to master/2.3 |
What changes were proposed in this pull request?
How was this patch tested?