peter-toth commented on a change in pull request #26028:
[SPARK-29359][SQL][TESTS] Better exception handling in
(SQL|ThriftServer)QueryTestSuite
URL: https://github.com/apache/spark/pull/26028#discussion_r332172052
##########
File path: sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala
##########
@@ -388,49 +390,52 @@ class SQLQueryTestSuite extends QueryTest with
SharedSparkSession {
}
}
- /** Executes a query and returns the result as (schema of the output,
normalized output). */
- private def getNormalizedResult(session: SparkSession, sql: String):
(StructType, Seq[String]) = {
- // Returns true if the plan is supposed to be sorted.
- def isSorted(plan: LogicalPlan): Boolean = plan match {
- case _: Join | _: Aggregate | _: Generate | _: Sample | _: Distinct =>
false
- case _: DescribeCommandBase
- | _: DescribeColumnCommand
- | _: DescribeTableStatement
- | _: DescribeColumnStatement => true
- case PhysicalOperation(_, _, Sort(_, true, _)) => true
- case _ => plan.children.iterator.exists(isSorted)
- }
-
+ protected def handleExceptions(result: => (String, Seq[String])): (String,
Seq[String]) = {
try {
- val df = session.sql(sql)
- val schema = df.schema
- // Get answer, but also get rid of the #1234 expression ids that show up
in explain plans
- val answer = SQLExecution.withNewExecutionId(session, df.queryExecution,
Some(sql)) {
-
hiveResultString(df.queryExecution.executedPlan).map(replaceNotIncludedMsg)
- }
-
- // If the output is not pre-sorted, sort it.
- if (isSorted(df.queryExecution.analyzed)) (schema, answer) else (schema,
answer.sorted)
-
+ result
} catch {
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
- (StructType(Seq.empty), Seq(a.getClass.getName,
msg.replaceAll("#\\d+", "#x")))
+ (emptySchema, Seq(a.getClass.getName, msg.replaceAll("#\\d+", "#x")))
Review comment:
No particular test case. Since I touched this method and
`StructType(Seq.empty)` was used 3 times so I just moved it to a `val`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]