-
Notifications
You must be signed in to change notification settings - Fork 28k
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
Conversation
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>
* parameters to construct an error message with SparkError.getMessage(). New exception types | ||
* should not accept arbitrary error messages. See [[SparkArithmeticException]]. | ||
*/ | ||
trait SparkError extends Throwable { |
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 think we only to move this to java? Other parts are internal impl and can still be in scala.
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.
Good call, it'll minimize the surface area of these changes
|
||
import org.apache.spark.SparkThrowable.SparkThrowableHelper; | ||
|
||
public class SparkThrowableSuite implements Serializable { |
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 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).
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.
Done - I also added a check on the Java side
Test build #140478 has finished for PR 33164 at commit
|
String getSqlState(); | ||
String[] getMessageParameters(); | ||
|
||
class SparkThrowableHelper { |
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.
Does it have to be an inner class?
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.
Moved back to Scala!
* types should not accept arbitrary error messages. See [[SparkArithmeticException]]. | ||
*/ | ||
public interface SparkThrowable { | ||
String getErrorClass(); |
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.
Add comments for interface methods?
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.
Done - these generally reflect the README
return null; | ||
} | ||
|
||
static SortedMap<String, ErrorInfo> getErrorClassToInfoMap() { |
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.
private?
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.
Moved back to Scala
@@ -0,0 +1,150 @@ | |||
package org.apache.spark; |
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.
copy right header?
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.
Moved back to Scala
Kubernetes integration test unable to build dist. exiting with code: 1 |
Signed-off-by: Karen Feng <karen.feng@databricks.com>
Kubernetes integration test starting |
Kubernetes integration test status success |
Test build #140482 has finished for PR 33164 at commit
|
Signed-off-by: Karen Feng <karen.feng@databricks.com>
Kubernetes integration test unable to build dist. exiting with code: 1 |
Test build #140533 has finished for PR 33164 at commit
|
Signed-off-by: Karen Feng <karen.feng@databricks.com>
Kubernetes integration test starting |
Kubernetes integration test status success |
Test build #140539 has finished for PR 33164 at commit
|
* types should not accept arbitrary error messages. See [[SparkArithmeticException]]. | ||
*/ | ||
public interface SparkThrowable { | ||
// Succinct, human-readable, unique, and consistent representation of the error category |
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.
Shall we use java Option? or document the null semantic and say that null means no error class?
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 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.
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.
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?
core/src/main/java/org/apache/spark/memory/SparkOutOfMemoryError.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Karen Feng <karen.feng@databricks.com>
Kubernetes integration test starting |
Kubernetes integration test status success |
Test build #140715 has finished for PR 33164 at commit
|
Signed-off-by: Karen Feng <karen.feng@databricks.com>
* 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]]. |
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.
Shall we add @since
?
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.
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 |
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.
Let's keep them 2-spaced
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 know many of other java files are not but strictly it should be 2-spaced
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.
Done (I think) - can you confirm?
Kubernetes integration test starting |
Kubernetes integration test status success |
Test build #140729 has finished for PR 33164 at commit
|
def this(errorClass: String, messageParameters: Seq[String]) = | ||
this(errorClass = Some(errorClass), messageParameters = messageParameters) | ||
override def getErrorClass: String = errorClass | ||
override def getMessageParameters: Array[String] = messageParameters |
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 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.
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.
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
.
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 except for some minor comments
Signed-off-by: Karen Feng <karen.feng@databricks.com>
Kubernetes integration test starting |
Kubernetes integration test starting |
Kubernetes integration test status success |
Kubernetes integration test status success |
Kubernetes integration test starting |
Test build #140761 has finished for PR 33164 at commit
|
Kubernetes integration test status success |
Test build #140762 has finished for PR 33164 at commit
|
Looks good to me 2. the test failures in yarn cluster look unrelated. |
### 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>
thanks, merging to master/3.2! |
What changes were proposed in this pull request?
Refactors the base Throwable trait
SparkError.scala
(introduced in SPARK-34920) an interfaceSparkThrowable.java
.Why are the changes needed?
SparkError
toSparkThrowable
better reflect sthat this is the base interface for bothException
andError
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.