Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,28 @@ trait SQLQueryTestHelper {
*/
protected def handleExceptions(result: => (String, Seq[String])): (String, Seq[String]) = {
val format = MINIMAL
// Do not output the logical plan tree which contains expression IDs.
// Also implement a crude way of masking expression IDs in the error message
// with a generic pattern "###".
def maskIds(msg: String) = msg.replaceAll("#\\d+", "#x")
try {
result
} catch {
case e: SparkThrowable with Throwable if e.getErrorClass != null =>
(emptySchema, Seq(e.getClass.getName, getMessage(e, format)))
case a: AnalysisException =>
// Do not output the logical plan tree which contains expression IDs.
// Also implement a crude way of masking expression IDs in the error message
// with a generic pattern "###".
val msg = if (a.plan.nonEmpty) a.getSimpleMessage else a.getMessage
(emptySchema, Seq(a.getClass.getName, msg.replaceAll("#\\d+", "#x")))
case s: SparkException if s.getCause != null =>
// For a runtime exception, it is hard to match because its message contains
// information of stage, task ID, etc.
// To make result matching simpler, here we match the cause of the exception if it exists.
s.getCause match {
case e: SparkThrowable with Throwable if e.getErrorClass != null =>
(emptySchema, Seq(e.getClass.getName, getMessage(e, format)))
case e: SparkThrowable with Throwable =>
(emptySchema, Seq(e.getClass.getName, maskIds(getMessage(e, format))))
case cause =>
(emptySchema, Seq(cause.getClass.getName, cause.getMessage))
(emptySchema, Seq(cause.getClass.getName, maskIds(cause.getMessage)))
}
case e: SparkThrowable with Throwable =>
(emptySchema, Seq(e.getClass.getName, maskIds(getMessage(e, format))))
case NonFatal(e) =>
// If there is an exception, put the exception class followed by the message.
(emptySchema, Seq(e.getClass.getName, e.getMessage))
(emptySchema, Seq(e.getClass.getName, maskIds(e.getMessage)))
}
}
}