Skip to content
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

[SPARK-35958][CORE] Refactor SparkError.scala to SparkThrowable.java #33164

Closed
wants to merge 11 commits into from

Conversation

karenfeng
Copy link
Contributor

What changes were proposed in this pull request?

Refactors the base Throwable trait SparkError.scala (introduced in SPARK-34920) an interface SparkThrowable.java.

Why are the changes needed?

  • Renaming SparkError to SparkThrowable better reflect sthat this is the base interface for both Exception and Error
  • Migrating to Java maximizes its extensibility

Does this PR introduce any user-facing change?

Yes; the base trait has been renamed and the accessor methods have changed (eg. sqlState -> getSqlState()).

How was this patch tested?

Unit tests.

Signed-off-by: Karen Feng <karen.feng@databricks.com>
Signed-off-by: Karen Feng <karen.feng@databricks.com>
Signed-off-by: Karen Feng <karen.feng@databricks.com>
@karenfeng karenfeng changed the title [SPARK-35958] Refactor SparkError.scala to SparkThrowable.java [SPARK-35958][CORE] Refactor SparkError.scala to SparkThrowable.java Jul 1, 2021
* parameters to construct an error message with SparkError.getMessage(). New exception types
* should not accept arbitrary error messages. See [[SparkArithmeticException]].
*/
trait SparkError extends Throwable {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we only to move this to java? Other parts are internal impl and can still be in scala.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, it'll minimize the surface area of these changes


import org.apache.spark.SparkThrowable.SparkThrowableHelper;

public class SparkThrowableSuite implements Serializable {
Copy link
Contributor

@cloud-fan cloud-fan Jul 1, 2021

Choose a reason for hiding this comment

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

I think the test in Scala is good enough, which also covers the most common case: we usually extend SparkThrowable in the scala code (spark codebase is mostly scala).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - I also added a check on the Java side

@SparkQA
Copy link

SparkQA commented Jul 1, 2021

Test build #140478 has finished for PR 33164 at commit ef5db1e.

  • This patch fails RAT tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

String getSqlState();
String[] getMessageParameters();

class SparkThrowableHelper {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it have to be an inner class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved back to Scala!

* types should not accept arbitrary error messages. See [[SparkArithmeticException]].
*/
public interface SparkThrowable {
String getErrorClass();
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comments for interface methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - these generally reflect the README

return null;
}

static SortedMap<String, ErrorInfo> getErrorClassToInfoMap() {
Copy link
Contributor

Choose a reason for hiding this comment

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

private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved back to Scala

@@ -0,0 +1,150 @@
package org.apache.spark;
Copy link
Contributor

Choose a reason for hiding this comment

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

copy right header?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved back to Scala

@SparkQA
Copy link

SparkQA commented Jul 1, 2021

Kubernetes integration test unable to build dist.

exiting with code: 1
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/44990/

Signed-off-by: Karen Feng <karen.feng@databricks.com>
@SparkQA
Copy link

SparkQA commented Jul 1, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/44994/

@SparkQA
Copy link

SparkQA commented Jul 1, 2021

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/44994/

@SparkQA
Copy link

SparkQA commented Jul 1, 2021

Test build #140482 has finished for PR 33164 at commit ec89069.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • throw new IllegalArgumentException(s\"Cannot find error class '$errorClass'\"))

Signed-off-by: Karen Feng <karen.feng@databricks.com>
@SparkQA
Copy link

SparkQA commented Jul 1, 2021

Kubernetes integration test unable to build dist.

exiting with code: 1
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45046/

@SparkQA
Copy link

SparkQA commented Jul 1, 2021

Test build #140533 has finished for PR 33164 at commit ec111f4.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Signed-off-by: Karen Feng <karen.feng@databricks.com>
@SparkQA
Copy link

SparkQA commented Jul 1, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45052/

@SparkQA
Copy link

SparkQA commented Jul 1, 2021

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45052/

@SparkQA
Copy link

SparkQA commented Jul 1, 2021

Test build #140539 has finished for PR 33164 at commit 5db91e5.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

* types should not accept arbitrary error messages. See [[SparkArithmeticException]].
*/
public interface SparkThrowable {
// Succinct, human-readable, unique, and consistent representation of the error category
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we use java Option? or document the null semantic and say that null means no error class?

Copy link
Contributor Author

@karenfeng karenfeng Jul 6, 2021

Choose a reason for hiding this comment

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

I tried using Java's Optional, but it turns out that Scala's Option is quite different and we'd have to do wrappers with null conversions. I think using null is cleaner overall; I'll document this.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think you should wrap or manually convert that to Option .. but I guess that's fine though? are there many changes required for that?

Signed-off-by: Karen Feng <karen.feng@databricks.com>
@SparkQA
Copy link

SparkQA commented Jul 6, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45226/

@SparkQA
Copy link

SparkQA commented Jul 6, 2021

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45226/

@SparkQA
Copy link

SparkQA commented Jul 6, 2021

Test build #140715 has finished for PR 33164 at commit f359e48.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Signed-off-by: Karen Feng <karen.feng@databricks.com>
@github-actions github-actions bot added the INFRA label Jul 7, 2021
* message with a null error class. See [[SparkException]].
* - To promote standardization, Throwables should be thrown with an error class and message
* parameters to construct an error message with SparkThrowableHelper.getMessage(). New Throwable
* types should not accept arbitrary error messages. See [[SparkArithmeticException]].
Copy link
Member

Choose a reason for hiding this comment

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

Shall we add @since?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! I also added @Evolving because it's so new.

*/
@Experimental
public interface SparkThrowable {
// Succinct, human-readable, unique, and consistent representation of the error category
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep them 2-spaced

Copy link
Member

Choose a reason for hiding this comment

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

I know many of other java files are not but strictly it should be 2-spaced

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done (I think) - can you confirm?

@SparkQA
Copy link

SparkQA commented Jul 7, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45239/

@SparkQA
Copy link

SparkQA commented Jul 7, 2021

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45239/

@SparkQA
Copy link

SparkQA commented Jul 7, 2021

Test build #140729 has finished for PR 33164 at commit d6f93b7.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Signed-off-by: Karen Feng <karen.feng@databricks.com>
Signed-off-by: Karen Feng <karen.feng@databricks.com>
def this(errorClass: String, messageParameters: Seq[String]) =
this(errorClass = Some(errorClass), messageParameters = messageParameters)
override def getErrorClass: String = errorClass
override def getMessageParameters: Array[String] = messageParameters
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like we are totally fine if SparkThrowable does not have getMessageParameters. I think the message parameter is an internal thing and we shouldn't expose it to the end-users via a public API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call - this was in order to construct a ParseException from an AnalysisException, but I was able to work around this by making messageParameters accessible as a val.

Copy link
Contributor

@cloud-fan cloud-fan left a comment

Choose a reason for hiding this comment

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

LGTM except for some minor comments

Signed-off-by: Karen Feng <karen.feng@databricks.com>
@SparkQA
Copy link

SparkQA commented Jul 7, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45272/

@SparkQA
Copy link

SparkQA commented Jul 7, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45273/

@SparkQA
Copy link

SparkQA commented Jul 7, 2021

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45272/

@SparkQA
Copy link

SparkQA commented Jul 7, 2021

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45273/

@SparkQA
Copy link

SparkQA commented Jul 7, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45274/

@SparkQA
Copy link

SparkQA commented Jul 7, 2021

Test build #140761 has finished for PR 33164 at commit c2f0b86.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jul 7, 2021

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/45274/

@SparkQA
Copy link

SparkQA commented Jul 7, 2021

Test build #140762 has finished for PR 33164 at commit 048adf6.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@HyukjinKwon
Copy link
Member

Looks good to me 2. the test failures in yarn cluster look unrelated.

@cloud-fan cloud-fan closed this in 71c086e Jul 8, 2021
cloud-fan pushed a commit that referenced this pull request Jul 8, 2021
### What changes were proposed in this pull request?

Refactors the base Throwable trait `SparkError.scala` (introduced in SPARK-34920) an interface `SparkThrowable.java`.

### Why are the changes needed?

- Renaming `SparkError` to `SparkThrowable` better reflect sthat this is the base interface for both `Exception` and `Error`
- Migrating to Java maximizes its extensibility

### Does this PR introduce _any_ user-facing change?

Yes; the base trait has been renamed and the accessor methods have changed (eg. `sqlState` -> `getSqlState()`).

### How was this patch tested?

Unit tests.

Closes #33164 from karenfeng/SPARK-35958.

Authored-by: Karen Feng <karen.feng@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit 71c086e)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
@cloud-fan
Copy link
Contributor

thanks, merging to master/3.2!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants