-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-26508][Core][SQL] Address warning messages in Java reported at lgtm.com #23420
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.
Is this safe change? Looks like behavior change when throwing exception.
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.
Thank you, this is my mistake. I will revert 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.
We need a space after casts. I suppose the point is to avoid overflow when the result is going to be a double anyway, at the cost of precision maybe. I tested, and the precision issue won't matter, but then again, there's no reason this method should return double. There is no such thing as 0.5 bytes.
I think we can just fix that for Spark 3; its value is used as a long or int everywhere anyway.
While here, I think I'd also fix the expressions like (long) Math.pow(1024L, 2L) above. The multipliers should be 1L << 10, 1L << 20, ... 1L << 50. There's again no point there in using floating point math.
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.
I agree with chaniging the precision. I will use long here.
I will also use 1L << 10, ... in enum ByteUnit.
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.
Hm, really? what does it return? type-wise the numbers should easily fit into a long. 2 TiB = 2199023255552 bytes. I'm missing where the failure is here.
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.
Write 100.0 here for extra clarity, and put spaces after all the casts here. Otherwise, what's the issue with this expression?
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.
lgtm.com and I are afraind (...) * chunkFetchHandlerThreadsPercent may cause overflow since it is int * int. After this change, it will be double * double.
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.
Oh it's because it's really (threads * percent) / 100. Maybe this can be simplified by breaking out the (this.serverThreads() ...) into a local variable, then writing as threads * (percent / 100.0)
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.
oops looks like I missed this comment, sorry for the duplicate.
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.
What's the purpose of this change?
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, I will revert 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.
I'd put the cast on line 183 and make n an int. length and next are nonnegative ints.
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.
i see
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 could probably just improve this by creating this class name string once above line 321, and putting something like "no message" instead of null, while we're here.
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.
Sure
|
Test build #100588 has finished for PR 23420 at commit
|
|
reopen this |
|
retest this please |
|
Test build #100598 has finished for PR 23420 at commit
|
holdenk
left a comment
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.
I'm not sure about the cast with the division, could we simplify it?
| return (int)Math.ceil( | ||
| (this.serverThreads() > 0 ? this.serverThreads() : 2 * NettyRuntime.availableProcessors()) * | ||
| chunkFetchHandlerThreadsPercent/(double)100); | ||
| (double) chunkFetchHandlerThreadsPercent/100); |
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.
I'm not so sure about moving this cast, why are doing that? Would it make more sense to write this as chunkFetchHandlerThreadsPercent / 100.0 ?
fix test failure
|
Test build #100606 has finished for PR 23420 at commit
|
|
retest this please |
srowen
left a comment
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.
Looks fine pending tests, with one tiny request
|
|
||
| private long getElementOffset(int ordinal) { | ||
| return startingOffset + headerInBytes + ordinal * elementSize; | ||
| return startingOffset + headerInBytes + ordinal * (long)elementSize; |
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.
Nit: space after cast
|
Test build #100623 has finished for PR 23420 at commit
|
|
Test build #100628 has finished for PR 23420 at commit
|
|
Merged to master |
… lgtm.com ## What changes were proposed in this pull request? This PR addresses warning messages in Java files reported at [lgtm.com](https://lgtm.com). [lgtm.com](https://lgtm.com) provides automated code review of Java/Python/JavaScript files for OSS projects. [Here](https://lgtm.com/projects/g/apache/spark/alerts/?mode=list&severity=warning) are warning messages regarding Apache Spark project. This PR addresses the following warnings: - Result of multiplication cast to wider type - Implicit narrowing conversion in compound assignment - Boxed variable is never null - Useless null check NOTE: `Potential input resource leak` looks false positive for now. ## How was this patch tested? Existing UTs Closes apache#23420 from kiszk/SPARK-26508. Authored-by: Kazuaki Ishizaki <[email protected]> Signed-off-by: Sean Owen <[email protected]>
What changes were proposed in this pull request?
This PR addresses warning messages in Java files reported at lgtm.com.
lgtm.com provides automated code review of Java/Python/JavaScript files for OSS projects. Here are warning messages regarding Apache Spark project.
This PR addresses the following warnings:
NOTE:
Potential input resource leaklooks false positive for now.How was this patch tested?
Existing UTs