Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[SPARK-49773][SQL] uncaught Java exception from make_timestamp() with bad timezone #48260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3267,6 +3267,12 @@
},
"sqlState" : "42000"
},
"INVALID_ZONE_OFFSET": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we clearly say it's time zone?

"message": [
"<message>. ZoneOffset represents the time difference from UTC and must be in the range from -18:00 to +18:00."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a bad practice to pass in the entire message. We can just say the zone offset is invalid, and we keep the original error as the causedBy of this error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we need to preserve the caused by. Or is that merely for the stack trace?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, and also to retain the original error message from the JDK library.

],
"sqlState" : "22009"
},
"JOIN_CONDITION_IS_NOT_BOOLEAN_TYPE" : {
"message" : [
"The join condition <joinCondition> has the invalid type <conditionType>, expected \"BOOLEAN\"."
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(e.getMessage)
}
}

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,14 @@ private[sql] trait ExecutionErrors extends DataTypeErrorsBase {
"encoderType" -> encoder.getClass.getName,
"docroot" -> SparkBuildInfo.spark_doc_root))
}

def zoneOffsetError(message: String): SparkDateTimeException = {
new SparkDateTimeException(
errorClass = "INVALID_ZONE_OFFSET",
messageParameters = Map("message" -> message),
context = Array.empty,
summary = "")
}
}

private[sql] object ExecutionErrors extends ExecutionErrors