Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adjusted comments
  • Loading branch information
itholic committed Sep 30, 2024
commit c8cb363cc40495c9b75bd70b57b29bdbb7afe133
8 changes: 7 additions & 1 deletion common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@
},
"DATE_TIME_FIELD_OUT_OF_BOUNDS" : {
"message" : [
"<message>. If necessary set <ansiConfig> to false to bypass this error."
"Invalid value for datetime field. If necessary set <ansiConfig> to false to bypass this error."
],
"sqlState" : "22008"
},
Expand Down Expand Up @@ -4788,6 +4788,12 @@
],
"sqlState" : "0A000"
},
"UNSUPPORTED_DATETIME_UNIT_ADDITION" : {
"message" : [
"Cannot add hours, minutes or seconds, milliseconds, microseconds to a date. If necessary set <ansiConfig> to false to bypass this error."
],
"sqlState" : "22008"
},
"UNSUPPORTED_DEFAULT_VALUE" : {
"message" : [
"DEFAULT column values is not supported."
Expand Down
23 changes: 20 additions & 3 deletions common/utils/src/main/scala/org/apache/spark/SparkException.scala
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,9 @@ private[spark] class SparkDateTimeException private(
message: String,
errorClass: Option[String],
messageParameters: Map[String, String],
context: Array[QueryContext])
extends DateTimeException(message) with SparkThrowable {
context: Array[QueryContext],
cause: Option[Throwable])
extends DateTimeException(message, cause.orNull) with SparkThrowable {

def this(
errorClass: String,
Expand All @@ -318,7 +319,23 @@ private[spark] class SparkDateTimeException private(
SparkThrowableHelper.getMessage(errorClass, messageParameters, summary),
Option(errorClass),
messageParameters,
context
context,
cause = null
)
}

def this(
errorClass: String,
messageParameters: Map[String, String],
context: Array[QueryContext],
summary: String,
cause: Option[Throwable]) = {
this(
SparkThrowableHelper.getMessage(errorClass, messageParameters, summary),
Option(errorClass),
messageParameters,
context,
cause
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ object DateTimeUtils extends SparkDateTimeUtils {
start: Int,
interval: CalendarInterval): Int = {
if (interval.microseconds != 0) {
throw QueryExecutionErrors.ansiIllegalArgumentError(
"Cannot add hours, minutes or seconds, milliseconds, microseconds to a date")
throw QueryExecutionErrors.ansiIllegalArgumentError()
}
val ld = daysToLocalDate(start).plusMonths(interval.months).plusDays(interval.days)
localDateToDays(ld)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,16 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE
new SparkDateTimeException(
errorClass = "DATE_TIME_FIELD_OUT_OF_BOUNDS",
messageParameters = Map(
"message" -> e.getMessage,
"ansiConfig" -> toSQLConf(SQLConf.ANSI_ENABLED.key)),
context = Array.empty,
summary = "")
summary = "",
cause = Some(e))
}

def ansiIllegalArgumentError(message: String): SparkIllegalArgumentException = {
def ansiIllegalArgumentError(): SparkIllegalArgumentException = {
new SparkIllegalArgumentException(
errorClass = "DATE_TIME_FIELD_OUT_OF_BOUNDS",
errorClass = "UNSUPPORTED_DATETIME_UNIT_ADDITION",
messageParameters = Map(
"message" -> message,
"ansiConfig" -> toSQLConf(SQLConf.ANSI_ENABLED.key)))
}

Expand Down