Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/src/main/resources/error/error-classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
"INCOMPATIBLE_DATASOURCE_REGISTER" : {
"message" : [ "Detected an incompatible DataSourceRegister. Please remove the incompatible library from classpath or upgrade it. Error: %s" ]
},
"INCONSISTENT_BEHAVIOR_CROSS_VERSION" : {
"message" : [ "You may get a different result due to the upgrading to Spark >= %s: %s" ]
},
"INDEX_OUT_OF_BOUNDS" : {
"message" : [ "Index %s must be between 0 and the length of the ArrayData." ],
"sqlState" : "22023"
Expand Down Expand Up @@ -158,6 +161,9 @@
"UNSUPPORTED_GROUPING_EXPRESSION" : {
"message" : [ "grouping()/grouping_id() can only be used with GroupingSets/Cube/Rollup" ]
},
"UNSUPPORTED_OPERATION" : {
"message" : [ "The operation is not supported: %s" ]
},
"WRITING_JOB_ABORTED" : {
"message" : [ "Writing job aborted" ],
"sqlState" : "40000"
Expand Down
19 changes: 16 additions & 3 deletions core/src/main/scala/org/apache/spark/SparkException.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,22 @@ private[spark] case class ExecutorDeadException(message: String)
/**
* Exception thrown when Spark returns different result after upgrading to a new version.
*/
private[spark] class SparkUpgradeException(version: String, message: String, cause: Throwable)
extends RuntimeException("You may get a different result due to the upgrading of Spark" +
s" $version: $message", cause)
private[spark] class SparkUpgradeException(
errorClass: String,
messageParameters: Array[String],
cause: Throwable)
extends RuntimeException(SparkThrowableHelper.getMessage(errorClass, messageParameters), cause)
with SparkThrowable {

def this(version: String, message: String, cause: Throwable) =
this (
errorClass = "INCONSISTENT_BEHAVIOR_CROSS_VERSION",
messageParameters = Array(version, message),
cause = cause
)

override def getErrorClass: String = errorClass
}

/**
* Arithmetic exception thrown from Spark with an error class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,30 +533,43 @@ object QueryExecutionErrors {

def sparkUpgradeInReadingDatesError(
format: String, config: String, option: String): SparkUpgradeException = {
new SparkUpgradeException("3.0",
s"""
|reading dates before 1582-10-15 or timestamps before 1900-01-01T00:00:00Z from $format
|files can be ambiguous, as the files may be written by Spark 2.x or legacy versions of
|Hive, which uses a legacy hybrid calendar that is different from Spark 3.0+'s Proleptic
|Gregorian calendar. See more details in SPARK-31404. You can set the SQL config
|'$config' or the datasource option '$option' to 'LEGACY' to rebase the datetime values
|w.r.t. the calendar difference during reading. To read the datetime values as it is,
|set the SQL config '$config' or the datasource option '$option' to 'CORRECTED'.
""".stripMargin, null)
new SparkUpgradeException(
errorClass = "INCONSISTENT_BEHAVIOR_CROSS_VERSION",
messageParameters = Array(
"3.0",
s"""
|reading dates before 1582-10-15 or timestamps before 1900-01-01T00:00:00Z
|from $format files can be ambiguous, as the files may be written by
|Spark 2.x or legacy versions of Hive, which uses a legacy hybrid calendar
|that is different from Spark 3.0+'s Proleptic Gregorian calendar.
|See more details in SPARK-31404. You can set the SQL config '$config' or
|the datasource option '$option' to 'LEGACY' to rebase the datetime values
|w.r.t. the calendar difference during reading. To read the datetime values
|as it is, set the SQL config '$config' or the datasource option '$option'
|to 'CORRECTED'.
|""".stripMargin),
cause = null
)
}

def sparkUpgradeInWritingDatesError(format: String, config: String): SparkUpgradeException = {
new SparkUpgradeException("3.0",
s"""
|writing dates before 1582-10-15 or timestamps before 1900-01-01T00:00:00Z into $format
|files can be dangerous, as the files may be read by Spark 2.x or legacy versions of Hive
|later, which uses a legacy hybrid calendar that is different from Spark 3.0+'s Proleptic
|Gregorian calendar. See more details in SPARK-31404. You can set $config to 'LEGACY' to
|rebase the datetime values w.r.t. the calendar difference during writing, to get maximum
|interoperability. Or set $config to 'CORRECTED' to write the datetime values as it is,
|if you are 100% sure that the written files will only be read by Spark 3.0+ or other
|systems that use Proleptic Gregorian calendar.
""".stripMargin, null)
new SparkUpgradeException(
errorClass = "INCONSISTENT_BEHAVIOR_CROSS_VERSION",
messageParameters = Array(
"3.0",
s"""
|writing dates before 1582-10-15 or timestamps before 1900-01-01T00:00:00Z
|into $format files can be dangerous, as the files may be read by Spark 2.x
|or legacy versions of Hive later, which uses a legacy hybrid calendar that
|is different from Spark 3.0+'s Proleptic Gregorian calendar. See more
|details in SPARK-31404. You can set $config to 'LEGACY' to rebase the
|datetime values w.r.t. the calendar difference during writing, to get maximum
|interoperability. Or set $config to 'CORRECTED' to write the datetime values
|as it is, if you are 100% sure that the written files will only be read by
|Spark 3.0+ or other systems that use Proleptic Gregorian calendar.
|""".stripMargin),
cause = null
)
}

def buildReaderUnsupportedForFileFormatError(format: String): Throwable = {
Expand Down Expand Up @@ -1617,8 +1630,12 @@ object QueryExecutionErrors {
}

def timeZoneIdNotSpecifiedForTimestampTypeError(): Throwable = {
new UnsupportedOperationException(
s"${TimestampType.catalogString} must supply timeZoneId parameter")
new SparkUnsupportedOperationException(
errorClass = "UNSUPPORTED_OPERATION",
messageParameters = Array(
s"${TimestampType.catalogString} must supply timeZoneId parameter " +
s"while converting to ArrowType")
)
}

def notPublicClassError(name: String): Throwable = {
Expand Down Expand Up @@ -1932,7 +1949,9 @@ object QueryExecutionErrors {
}

def cannotConvertOrcTimestampToTimestampNTZError(): Throwable = {
new RuntimeException("Unable to convert timestamp of Orc to data type 'timestamp_ntz'")
new SparkUnsupportedOperationException(
errorClass = "UNSUPPORTED_OPERATION",
messageParameters = Array("Unable to convert timestamp of Orc to data type 'timestamp_ntz'"))
}

def writePartitionExceedConfigSizeWhenDynamicPartitionError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
exprSeq2.foreach(pair =>
checkExceptionInExpression[SparkUpgradeException](
pair._1,
"You may get a different result due to the upgrading of Spark 3.0"))
"You may get a different result due to the upgrading to Spark >= 3.0"))
} else {
if (ansiEnabled) {
exprSeq2.foreach(pair =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ select to_date('26/October/2015', 'dd/MMMMM/yyyy')
struct<>
-- !query output
org.apache.spark.SparkUpgradeException
You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'dd/MMMMM/yyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html
You may get a different result due to the upgrading to Spark >= 3.0: Fail to recognize 'dd/MMMMM/yyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html


-- !query
Expand All @@ -650,7 +650,7 @@ select from_json('{"d":"26/October/2015"}', 'd Date', map('dateFormat', 'dd/MMMM
struct<>
-- !query output
org.apache.spark.SparkUpgradeException
You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'dd/MMMMM/yyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html
You may get a different result due to the upgrading to Spark >= 3.0: Fail to recognize 'dd/MMMMM/yyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html


-- !query
Expand All @@ -659,7 +659,7 @@ select from_csv('26/October/2015', 'd Date', map('dateFormat', 'dd/MMMMM/yyyy'))
struct<>
-- !query output
org.apache.spark.SparkUpgradeException
You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'dd/MMMMM/yyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html
You may get a different result due to the upgrading to Spark >= 3.0: Fail to recognize 'dd/MMMMM/yyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html


-- !query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ select to_timestamp('1', 'yy')
struct<>
-- !query output
org.apache.spark.SparkUpgradeException
You may get a different result due to the upgrading of Spark 3.0: Fail to parse '1' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.
You may get a different result due to the upgrading to Spark >= 3.0: Fail to parse '1' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.


-- !query
Expand All @@ -35,7 +35,7 @@ select to_timestamp('123', 'yy')
struct<>
-- !query output
org.apache.spark.SparkUpgradeException
You may get a different result due to the upgrading of Spark 3.0: Fail to parse '123' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.
You may get a different result due to the upgrading to Spark >= 3.0: Fail to parse '123' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.


-- !query
Expand All @@ -44,7 +44,7 @@ select to_timestamp('1', 'yyy')
struct<>
-- !query output
org.apache.spark.SparkUpgradeException
You may get a different result due to the upgrading of Spark 3.0: Fail to parse '1' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.
You may get a different result due to the upgrading to Spark >= 3.0: Fail to parse '1' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.


-- !query
Expand All @@ -53,7 +53,7 @@ select to_timestamp('1234567', 'yyyyyyy')
struct<>
-- !query output
org.apache.spark.SparkUpgradeException
You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'yyyyyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html
You may get a different result due to the upgrading to Spark >= 3.0: Fail to recognize 'yyyyyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html


-- !query
Expand All @@ -71,7 +71,7 @@ select to_timestamp('9', 'DD')
struct<>
-- !query output
org.apache.spark.SparkUpgradeException
You may get a different result due to the upgrading of Spark 3.0: Fail to parse '9' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.
You may get a different result due to the upgrading to Spark >= 3.0: Fail to parse '9' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.


-- !query
Expand All @@ -89,7 +89,7 @@ select to_timestamp('9', 'DDD')
struct<>
-- !query output
org.apache.spark.SparkUpgradeException
You may get a different result due to the upgrading of Spark 3.0: Fail to parse '9' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.
You may get a different result due to the upgrading to Spark >= 3.0: Fail to parse '9' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.


-- !query
Expand All @@ -98,7 +98,7 @@ select to_timestamp('99', 'DDD')
struct<>
-- !query output
org.apache.spark.SparkUpgradeException
You may get a different result due to the upgrading of Spark 3.0: Fail to parse '99' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.
You may get a different result due to the upgrading to Spark >= 3.0: Fail to parse '99' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.


-- !query
Expand Down Expand Up @@ -170,7 +170,7 @@ select from_csv('2018-366', 'date Date', map('dateFormat', 'yyyy-DDD'))
struct<>
-- !query output
org.apache.spark.SparkUpgradeException
You may get a different result due to the upgrading of Spark 3.0: Fail to parse '2018-366' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.
You may get a different result due to the upgrading to Spark >= 3.0: Fail to parse '2018-366' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.


-- !query
Expand Down
Loading