Skip to content

Conversation

@Fokko
Copy link
Contributor

@Fokko Fokko commented Sep 11, 2018

While working on another PR, I noticed that there is quite some legacy Java in there that can be beautified. For example the use og features from Java8, such as:

  • Collection libraries
  • Try-with-resource blocks

No code has been changed

What are your thoughts on this?

This makes code easier to read, and using try-with-resource makes is less likely to forget to close something.

What changes were proposed in this pull request?

(Please fill in changes proposed in this fix)

How was this patch tested?

(Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests)
(If this patch involves UI changes, please attach a screenshot; otherwise, remove this)

Please review http://spark.apache.org/contributing.html before opening a pull request.

@AmplabJenkins
Copy link

Can one of the admins verify this patch?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are already changing this, I would also suggest to add static imports to shorten the code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this sort of thing is worth changing. I know, IntelliJ suggests it. Unless the mutability is an issue, I'd leave it as a shorter idiom. I wouldn't use static imports here personally.

there's also a very small cost of changes in that they create potential merge conflicts for other changes later, so I tend to have a very low but finite minimum bar for value of code scrubbing like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I don't really care about moving to Collections.

@TomaszGaweda
Copy link

I like this idea :) +1 as it's only refactor, without logic change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this sort of thing is worth changing. I know, IntelliJ suggests it. Unless the mutability is an issue, I'd leave it as a shorter idiom. I wouldn't use static imports here personally.

there's also a very small cost of changes in that they create potential merge conflicts for other changes later, so I tend to have a very low but finite minimum bar for value of code scrubbing like this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: space after try

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about space above; I'd also indent the continuation 4 spaces for clarity

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent is now too deep here. I have the same general kind of doubt here.. it's touching a lot of lines for little actual gain. Still, I'd like to be able to improve code a bit here and there. If this is only going to master and Spark 3, the back-port issue lessens, because it's more unlikely to backport from 3.x to 2.x.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are merge conflicts, it is easy to pick theirs, and wrap the try-with-resources around it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scenario is something like: later, a line or two in this block is changed. That change is cherry-picked to a branch before this change here. It's a merge conflict, and choosing "theirs" overwrites your change here. It would have to be manually merged. If you know that this is all that has happened, sure, not hard. But it relies on the committer figuring that out and not missing another subtle change during the manual merge. That's definitely the most time-consuming part for me. For Spark 3.x vs 2.x I am less worried, and would like a freer hand to make small improvements. Within a major release I am reluctant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't collapse these

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't bother with this; we don't really do it consistently, it's not a JDK standard class, and it doesn't really save much, while adding to the dependency on commons/io

Copy link
Contributor

@vanzin vanzin Sep 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module should not have any non-JRE dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wan't aware of this requirement, reverted the change.

Copy link
Member

@HyukjinKwon HyukjinKwon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was just looking through this out of curiosity. just few nits.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shell we stick to 2spaced indentation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto for indentation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation ..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is horrible yes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks unused.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to add a space after try?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: fix indentation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after try

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@Fokko Fokko force-pushed the SPARK-25408 branch 5 times, most recently from 1062ca6 to a4ee101 Compare September 12, 2018 09:44
@Fokko
Copy link
Contributor Author

Fokko commented Sep 12, 2018

Thanks for the feedback guys, I was relying too much on Scalastyle :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need try at line 149?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need try at line 149?

Copy link
Contributor Author

@Fokko Fokko Sep 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one, thanks. Missed it for some reason.

@Fokko
Copy link
Contributor Author

Fokko commented Sep 17, 2018

Addressed comments and rebased onto master, no merge conflicts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we put this line into try since this line was originally executed after clientFactory.createClient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we can't, since the res is returned by the function :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any time

@Fokko
Copy link
Contributor Author

Fokko commented Sep 20, 2018

@srowen Any incentive to move this forward? Or are PR's like these not appreciated? Let me know.

Most of the changes are cosmetic, but having <Java8 in the codebase give a bad example to newcomers to the Spark project. Also adding the Closeable to the RowBasedKeyValueBatchSuite.java:
https://github.com/apache/spark/pull/22399/files#diff-6c2c45f79666e2e52eb9f9411fa8b4baR49
makes the codebase a bit nicer in my opinion, since the class already has a .close() method, it makes sense to also implement the Closeable interface.

@srowen
Copy link
Member

srowen commented Sep 20, 2018

I think this is fine (though see https://github.com/apache/spark/pull/22399/files#r218121426 ). As a practical matter I might wait until we're done with the 2.4 release to start a lot of changes like this. It isn't tied to Spark 2.5 or 3.0 but might just be simpler to hold this for a bit, while we might be wanting to quickly backport a few changes from master to 2.4.

@Fokko
Copy link
Contributor Author

Fokko commented Sep 20, 2018

Cool, makes sense. Thanks for the clarification @srowen

Use features from Java8 such as:
- Try-with-resource blocks
@Fokko
Copy link
Contributor Author

Fokko commented Oct 4, 2018

Rebased onto master

@srowen
Copy link
Member

srowen commented Oct 5, 2018

Merged to master

@asfgit asfgit closed this in 44c1e1a Oct 5, 2018
@gatorsmile
Copy link
Member

It sounds like the build is broken after merging this PR

@gatorsmile
Copy link
Member

@gatorsmile
Copy link
Member

@cloud-fan
Copy link
Contributor

Jenkins was not triggered in this PR, I'm reverting it. Please re-open it and make sure jenkins pass, thanks!

@srowen
Copy link
Member

srowen commented Oct 5, 2018

Oh no, I got mixed up and didn't realize this one hadn't actually had a jenkins run. Sorry about this, that is my mistake. I will follow up.

@srowen
Copy link
Member

srowen commented Oct 5, 2018

Sorry @Fokko can you recreate this change in a new PR, after addressing...

[error] /home/jenkins/workspace/spark-master-compile-maven-hadoop-2.6/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/CLIService.java:149: error: incompatible types: try-with-resources not applicable to variable type
[error]     try (IMetaStoreClient metastoreClient = new HiveMetaStoreClient(hiveConf)) {
[error]                           ^
[error]     (IMetaStoreClient cannot be converted to AutoCloseable)
[error] /home/jenkins/workspace/spark-master-compile-maven-hadoop-2.6/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/operation/OperationManager.java:200: error: incompatible types: try-with-resources not applicable to variable type
[error]     try (Operation operation = removeOperation(opHandle)) {
[error]                    ^
[error]     (Operation cannot be converted to AutoCloseable)

@Fokko
Copy link
Contributor Author

Fokko commented Oct 5, 2018

Thanks @srowen for pointing out the errors. Weird that it did not come up as a merge conflict. Let me open a new PR.

@srowen
Copy link
Member

srowen commented Oct 5, 2018

It wasn't a merge conflict. I failed to notice this had not actually been tested. To check locally you'd have to make sure you enable more profiles like Hive to build some of the code that changed here.

@HyukjinKwon
Copy link
Member

@Fokko, Let's follow the PR format next time BTW, for instance, "How was this patch tested?"

@Fokko
Copy link
Contributor Author

Fokko commented Oct 5, 2018

Oh I see, could we test the next PR using Jenkins?

@HyukjinKwon
Copy link
Member

Let me trigger it in the next PR.

@Fokko
Copy link
Contributor Author

Fokko commented Oct 5, 2018

@HyukjinKwon I've opened a new PR under #22637. Would be nice if you can trigger Travis 👍

jackylee-ch pushed a commit to jackylee-ch/spark that referenced this pull request Feb 18, 2019
While working on another PR, I noticed that there is quite some legacy Java in there that can be beautified. For example the use og features from Java8, such as:
- Collection libraries
- Try-with-resource blocks

No code has been changed

What are your thoughts on this?

This makes code easier to read, and using try-with-resource makes is less likely to forget to close something.

## What changes were proposed in this pull request?

(Please fill in changes proposed in this fix)

## How was this patch tested?

(Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests)
(If this patch involves UI changes, please attach a screenshot; otherwise, remove this)

Please review http://spark.apache.org/contributing.html before opening a pull request.

Closes apache#22399 from Fokko/SPARK-25408.

Authored-by: Fokko Driesprong <[email protected]>
Signed-off-by: Sean Owen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants