-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[MINOR] Remove inappropriate type notation and extra anonymous closure within functional transformations #12413
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 5 commits
f075df3
2ede93e
ff93278
4aa5ce6
bd7dec4
03eabb3
85ace0e
5394138
c6b3cb8
0ffb4d7
08de54d
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 |
|---|---|---|
|
|
@@ -131,7 +131,7 @@ trait JavaRDDLike[T, This <: JavaRDDLike[T, This]] extends Serializable { | |
| */ | ||
| def flatMapToDouble(f: DoubleFlatMapFunction[T]): JavaDoubleRDD = { | ||
| def fn: (T) => Iterator[jl.Double] = (x: T) => f.call(x).asScala | ||
| new JavaDoubleRDD(rdd.flatMap(fn).map((x: jl.Double) => x.doubleValue())) | ||
| new JavaDoubleRDD(rdd.flatMap(fn).map(x => x.doubleValue())) | ||
|
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. We can even write
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. Thanks! I just wanted to be a bit careful because it looks it uses a variable name |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -173,7 +173,7 @@ trait JavaRDDLike[T, This <: JavaRDDLike[T, This]] extends Serializable { | |
| def fn: (Iterator[T]) => Iterator[jl.Double] = { | ||
| (x: Iterator[T]) => f.call(x.asJava).asScala | ||
| } | ||
| new JavaDoubleRDD(rdd.mapPartitions(fn).map((x: jl.Double) => x.doubleValue())) | ||
| new JavaDoubleRDD(rdd.mapPartitions(fn).map(x => x.doubleValue())) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -431,7 +431,7 @@ private[sql] object StatFunctions extends Logging { | |
| s"exceed 1e4. Currently $columnSize") | ||
| val table = counts.groupBy(_.get(0)).map { case (col1Item, rows) => | ||
| val countsRow = new GenericMutableRow(columnSize + 1) | ||
| rows.foreach { (row: Row) => | ||
| rows.foreach { row => | ||
|
Contributor
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. here it is definitely unclear what the input type is
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. Yeah, but there are a thousand places in the code where a local val's type isn't obvious (e.g. what's
Contributor
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. So you are agreeing with me that it is not obvious, and making the type more explicit is good here, but yet you are arguing we should change it to make it less obvious?
Contributor
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. BTW in Spark SQL there are internal row types and external row types, so it is actually really not obvious what the row type is here.
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 agree the type isn't obvious, but that can't be the standard, or else we'd write types almost everywhere in Scala. While I don't see the reason this is a special case (you identify a decent reason right above though), I also would not have changed it just for its own sake. I personally would accept the change if the line were being modified, but it wasn't. Hence on a second look I'd be neutral, and wouldn't oppose undoing this, even if I think it's really 6 of one, half-dozen of the other.
Contributor
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 agree the type isn't obvious, but that can't be the standard" That should be the standard.
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. This seems like a tiny point but is actually a decent opportunity to talk about how we collectively should write the most readable code. As I say, either you mean all the types in this method are obvious to you (they aren't to me!), or you mean you'd actually write just about every type in this method, and I dare say no Scala programmer would. Putting aside cases where the type is essential (methods, or where the inferred reference type must be overridden), this is why I'd say the standard is certainly readability, not strictly whether the type is obvious. I bet we mean the same thing. It's going to be a judgment call that deserves relatively wide latitude, but that does argue against changing a call in the first place unless it seems materially better, and that standard was not met on this line, I agree in retrospect. While I might undo this, not some others you're pointing out, if you feel strongly about reverting a few of these types of changes and that lets us close this out, that LGTM |
||
| // row.get(0) is column 1 | ||
| // row.get(1) is column 2 | ||
| // row.get(2) is the frequency | ||
|
|
||
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.
Question: in this case, it could even be
flatMap(w => Option(w.exception)). Is this different at all as far as Scala is concerned, without the braces at all? I could look it up but figured you might already know.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.
It must be my mistake (while trying to be careful). Let me correct this soon. Thank you.