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-49773][SQL] Uncaught Java exception from make_timestamp() with bad timezone #48260

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 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 common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3111,6 +3111,12 @@
],
"sqlState" : "42K0F"
},
"INVALID_TIMEZONE" : {
"message" : [
"The timezone: <timeZone> is invalid. The timezone must be either a region-based zone ID or a zone offset. Region IDs must have the form 'area/city', such as 'America/Los_Angeles'. Zone offsets must be in the format '(+|-)HH', '(+|-)HH:mm’ or '(+|-)HH:mm:ss', e.g '-08' , '+01:00' or '-13:33:33', and must be in the range from -18:00 to +18:00. 'Z' and 'UTC' are accepted as synonyms for '+00:00'."
],
"sqlState" : "22009"
},
"INVALID_TIME_TRAVEL_SPEC" : {
"message" : [
"Cannot specify both version and timestamp when time travelling the table."
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 = None
)
}

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.orElse(None)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ trait SparkDateTimeUtils {
// To support the (+|-)hh:m format because it was supported before Spark 3.0.
formattedZoneId = singleMinuteTz.matcher(formattedZoneId).replaceFirst("$1$2:0$3")

ZoneId.of(formattedZoneId, ZoneId.SHORT_IDS)
try {
ZoneId.of(formattedZoneId, ZoneId.SHORT_IDS)
} catch {
case e: java.time.DateTimeException =>
throw ExecutionErrors.zoneOffsetError(timeZoneId, e)
}
}

def getTimeZone(timeZoneId: String): TimeZone = TimeZone.getTimeZone(getZoneId(timeZoneId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ private[sql] trait ExecutionErrors extends DataTypeErrorsBase {
"encoderType" -> encoder.getClass.getName,
"docroot" -> SparkBuildInfo.spark_doc_root))
}

def zoneOffsetError(
timeZone: String,
e: java.time.DateTimeException): SparkDateTimeException = {
new SparkDateTimeException(
errorClass = "INVALID_TIMEZONE",
messageParameters = Map("timeZone" -> timeZone),
context = Array.empty,
summary = "",
cause = Some(e))
}
}

private[sql] object ExecutionErrors extends ExecutionErrors