Skip to content

Commit

Permalink
Rename errorClass to condition in errors in JSON formats
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGekk committed Oct 12, 2024
1 parent 62ade5f commit c21ddf2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@ private[spark] object SparkThrowableHelper {
toJsonString { generator =>
val g = generator.useDefaultPrettyPrinter()
g.writeStartObject()
g.writeStringField("errorClass", "LEGACY")
g.writeStringField("condition", "LEGACY")
g.writeObjectFieldStart("messageParameters")
g.writeStringField("message", e.getMessage)
g.writeEndObject()
g.writeEndObject()
}
case MINIMAL | STANDARD =>
val errorClass = e.getCondition
val condition = e.getCondition
toJsonString { generator =>
val g = generator.useDefaultPrettyPrinter()
g.writeStartObject()
g.writeStringField("errorClass", errorClass)
g.writeStringField("condition", condition)
if (format == STANDARD) {
g.writeStringField("messageTemplate", errorReader.getMessageTemplate(errorClass))
g.writeStringField("messageTemplate", errorReader.getMessageTemplate(condition))
}
val sqlState = e.getSqlState
if (sqlState != null) g.writeStringField("sqlState", sqlState)
Expand Down
12 changes: 6 additions & 6 deletions core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class SparkThrowableSuite extends SparkFunSuite {
// scalastyle:off line.size.limit
assert(SparkThrowableHelper.getMessage(e, MINIMAL) ===
"""{
| "errorClass" : "DIVIDE_BY_ZERO",
| "condition" : "DIVIDE_BY_ZERO",
| "sqlState" : "22012",
| "messageParameters" : {
| "config" : "CONFIG"
Expand All @@ -328,7 +328,7 @@ class SparkThrowableSuite extends SparkFunSuite {
|}""".stripMargin)
assert(SparkThrowableHelper.getMessage(e, STANDARD) ===
"""{
| "errorClass" : "DIVIDE_BY_ZERO",
| "condition" : "DIVIDE_BY_ZERO",
| "messageTemplate" : "Division by zero. Use `try_divide` to tolerate divisor being 0 and return NULL instead. If necessary set <config> to \"false\" to bypass this error.",
| "sqlState" : "22012",
| "messageParameters" : {
Expand All @@ -348,7 +348,7 @@ class SparkThrowableSuite extends SparkFunSuite {
messageParameters = Map("saveMode" -> "UNSUPPORTED_MODE"))
assert(SparkThrowableHelper.getMessage(e2, STANDARD) ===
"""{
| "errorClass" : "UNSUPPORTED_SAVE_MODE.EXISTENT_PATH",
| "condition" : "UNSUPPORTED_SAVE_MODE.EXISTENT_PATH",
| "messageTemplate" : "The save mode <saveMode> is not supported for: an existent path.",
| "sqlState" : "0A000",
| "messageParameters" : {
Expand All @@ -363,7 +363,7 @@ class SparkThrowableSuite extends SparkFunSuite {
val e3 = new LegacyException
assert(SparkThrowableHelper.getMessage(e3, MINIMAL) ===
"""{
| "errorClass" : "LEGACY",
| "condition" : "LEGACY",
| "messageParameters" : {
| "message" : "Test message"
| }
Expand Down Expand Up @@ -392,7 +392,7 @@ class SparkThrowableSuite extends SparkFunSuite {
// scalastyle:off line.size.limit
assert(SparkThrowableHelper.getMessage(e4, MINIMAL) ===
"""{
| "errorClass" : "DIVIDE_BY_ZERO",
| "condition" : "DIVIDE_BY_ZERO",
| "sqlState" : "22012",
| "messageParameters" : {
| "config" : "CONFIG"
Expand All @@ -404,7 +404,7 @@ class SparkThrowableSuite extends SparkFunSuite {
|}""".stripMargin)
assert(SparkThrowableHelper.getMessage(e4, STANDARD) ===
"""{
| "errorClass" : "DIVIDE_BY_ZERO",
| "condition" : "DIVIDE_BY_ZERO",
| "messageTemplate" : "Division by zero. Use `try_divide` to tolerate divisor being 0 and return NULL instead. If necessary set <config> to \"false\" to bypass this error.",
| "sqlState" : "22012",
| "messageParameters" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ class CliSuite extends SparkFunSuite {
format = ErrorMessageFormat.MINIMAL,
errorMessage =
"""{
| "errorClass" : "DIVIDE_BY_ZERO",
| "condition" : "DIVIDE_BY_ZERO",
| "sqlState" : "22012",
| "messageParameters" : {
| "config" : "\"spark.sql.ansi.enabled\""
Expand All @@ -753,7 +753,7 @@ class CliSuite extends SparkFunSuite {
format = ErrorMessageFormat.STANDARD,
errorMessage =
"""{
| "errorClass" : "DIVIDE_BY_ZERO",
| "condition" : "DIVIDE_BY_ZERO",
| "messageTemplate" : "Division by zero. Use `try_divide` to tolerate divisor being 0 and return NULL instead. If necessary set <config> to \"false\" to bypass this error.",
| "sqlState" : "22012",
| "messageParameters" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ trait ThriftServerWithSparkContextSuite extends SharedThriftServer {
val e2 = intercept[HiveSQLException](exec(sql))
assert(e2.getMessage ===
"""{
| "errorClass" : "DIVIDE_BY_ZERO",
| "condition" : "DIVIDE_BY_ZERO",
| "sqlState" : "22012",
| "messageParameters" : {
| "config" : "\"spark.sql.ansi.enabled\""
Expand All @@ -191,7 +191,7 @@ trait ThriftServerWithSparkContextSuite extends SharedThriftServer {
val e3 = intercept[HiveSQLException](exec(sql))
assert(e3.getMessage ===
"""{
| "errorClass" : "DIVIDE_BY_ZERO",
| "condition" : "DIVIDE_BY_ZERO",
| "messageTemplate" : "Division by zero. Use `try_divide` to tolerate divisor being 0 and return NULL instead. If necessary set <config> to \"false\" to bypass this error.",
| "sqlState" : "22012",
| "messageParameters" : {
Expand Down

0 comments on commit c21ddf2

Please sign in to comment.