Skip to content

Commit 0b75d5b

Browse files
committed
fix test error
1 parent 2a422ea commit 0b75d5b

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkExecuteStatementOperation.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,11 @@ private[hive] class SparkExecuteStatementOperation(
276276
setState(OperationState.ERROR)
277277
HiveThriftServer2.listener.onStatementError(
278278
statementId, e.getMessage, SparkUtils.exceptionString(e))
279-
e
279+
if (e.isInstanceOf[HiveSQLException]) {
280+
throw e.asInstanceOf[HiveSQLException]
281+
} else {
282+
throw new HiveSQLException("Error running query: " + e.toString, e)
283+
}
280284
}
281285
} finally {
282286
synchronized {

sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@
1818
package org.apache.spark.sql.hive.thriftserver
1919

2020
import java.io.File
21-
import java.sql.{DriverManager, SQLException, Statement, Timestamp}
22-
import java.util.Locale
21+
import java.sql.{DriverManager, Statement, Timestamp}
22+
import java.util.{Locale, MissingFormatArgumentException}
2323

2424
import scala.util.{Random, Try}
2525
import scala.util.control.NonFatal
2626

27+
import org.apache.commons.lang3.exception.ExceptionUtils
2728
import org.apache.hadoop.hive.conf.HiveConf.ConfVars
2829
import org.apache.hive.service.cli.HiveSQLException
2930

30-
import org.apache.spark.sql.{AnalysisException, SQLQueryTestSuite}
31+
import org.apache.spark.SparkException
32+
import org.apache.spark.sql.SQLQueryTestSuite
33+
import org.apache.spark.sql.catalyst.analysis.NoSuchTableException
3134
import org.apache.spark.sql.catalyst.util.fileToString
3235
import org.apache.spark.sql.execution.HiveResult
3336
import org.apache.spark.sql.internal.SQLConf
@@ -169,19 +172,47 @@ class ThriftServerQueryTestSuite extends SQLQueryTestSuite {
169172
|| d.sql.toUpperCase(Locale.ROOT).startsWith("DESC\n")
170173
|| d.sql.toUpperCase(Locale.ROOT).startsWith("DESCRIBE ")
171174
|| d.sql.toUpperCase(Locale.ROOT).startsWith("DESCRIBE\n") =>
175+
172176
// Skip show command, see HiveResult.hiveResultString
173177
case s if s.sql.toUpperCase(Locale.ROOT).startsWith("SHOW ")
174178
|| s.sql.toUpperCase(Locale.ROOT).startsWith("SHOW\n") =>
175-
// AnalysisException should exactly match.
176-
// SQLException should not exactly match. We only assert the result contains Exception.
177-
case _ if output.output.startsWith(classOf[SQLException].getName) =>
179+
180+
case _ if output.output.startsWith(classOf[RuntimeException].getName) =>
178181
assert(expected.output.contains("Exception"),
179182
s"Exception did not match for query #$i\n${expected.sql}, " +
180183
s"expected: ${expected.output}, but got: ${output.output}")
184+
185+
case _ if output.output.startsWith(classOf[NoSuchTableException].getPackage.getName) =>
186+
assert(expected.output.startsWith(classOf[NoSuchTableException].getPackage.getName),
187+
s"Exception did not match for query #$i\n${expected.sql}, " +
188+
s"expected: ${expected.output}, but got: ${output.output}")
189+
190+
case _ if output.output.startsWith(classOf[SparkException].getName)
191+
&& output.output.contains("overflow") =>
192+
assert(expected.output.contains(classOf[ArithmeticException].getName)
193+
&& expected.output.contains("overflow"),
194+
s"Exception did not match for query #$i\n${expected.sql}, " +
195+
s"expected: ${expected.output}, but got: ${output.output}")
196+
197+
case _ if output.output.startsWith(classOf[ArithmeticException].getName)
198+
&& output.output.contains("causes overflow") =>
199+
assert(expected.output.contains(classOf[ArithmeticException].getName)
200+
&& expected.output.contains("causes overflow"),
201+
s"Exception did not match for query #$i\n${expected.sql}, " +
202+
s"expected: ${expected.output}, but got: ${output.output}")
203+
204+
case _ if output.output.startsWith(classOf[MissingFormatArgumentException].getName)
205+
&& output.output.contains("Format specifier") =>
206+
assert(expected.output.contains(classOf[MissingFormatArgumentException].getName)
207+
&& expected.output.contains("Format specifier"),
208+
s"Exception did not match for query #$i\n${expected.sql}, " +
209+
s"expected: ${expected.output}, but got: ${output.output}")
210+
181211
// HiveSQLException is usually a feature that our ThriftServer cannot support.
182212
// Please add SQL to blackList.
183213
case _ if output.output.startsWith(classOf[HiveSQLException].getName) =>
184214
assert(false, s"${output.output} for query #$i\n${expected.sql}")
215+
185216
case _ =>
186217
assertResult(expected.output, s"Result did not match for query #$i\n${expected.sql}") {
187218
output.output
@@ -244,15 +275,10 @@ class ThriftServerQueryTestSuite extends SQLQueryTestSuite {
244275
answer
245276
}
246277
} catch {
247-
case a: AnalysisException =>
248-
// Do not output the logical plan tree which contains expression IDs.
249-
// Also implement a crude way of masking expression IDs in the error message
250-
// with a generic pattern "###".
251-
val msg = if (a.plan.nonEmpty) a.getSimpleMessage else a.getMessage
252-
Seq(a.getClass.getName, msg.replaceAll("#\\d+", "#x")).sorted
253278
case NonFatal(e) =>
279+
val rootCause = ExceptionUtils.getRootCause(e)
254280
// If there is an exception, put the exception class followed by the message.
255-
Seq(e.getClass.getName, e.getMessage)
281+
Seq(rootCause.getClass.getName, rootCause.getMessage)
256282
}
257283
}
258284

0 commit comments

Comments
 (0)