You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by we...@apache.org on 2020/02/24 10:50:41 UTC
[spark] branch branch-3.0 updated: [SPARK-30868][SQL] Throw
Exception if runHive(sql) failed
This is an automated email from the ASF dual-hosted git repository.
wenchen pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new 1fedafdd [SPARK-30868][SQL] Throw Exception if runHive(sql) failed
1fedafdd is described below
commit 1fedafdd1de9234a91b532f1e3cbeef4e8878f24
Author: lijunqing <li...@baidu.com>
AuthorDate: Mon Feb 24 15:42:45 2020 +0800
[SPARK-30868][SQL] Throw Exception if runHive(sql) failed
### Why are the changes needed?
At present, HiveClientImpl.runHive will not throw an exception when it runs incorrectly, which will cause it to fail to feedback error information normally.
Example
```scala
spark.sql("add jar file:///tmp/not_exists.jar")
spark.sql("show databases").show()
```
/tmp/not_exists.jar doesn't exist, thus add jar is failed. However this code will run completely without causing application failure.
### Does this PR introduce any user-facing change?
No.
### How was this patch tested?
add new suite tests
Closes #27644 from stczwd/SPARK-30868.
Authored-by: lijunqing <li...@baidu.com>
Signed-off-by: Wenchen Fan <we...@databricks.com>
---
.../spark/sql/hive/client/HiveClientImpl.scala | 7 ++++++-
.../spark/sql/hive/HiveExternalCatalogSuite.scala | 24 ++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
index ab4db0c..f2c516e 100644
--- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
+++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
@@ -839,7 +839,12 @@ private[hive] class HiveClientImpl(
state.out.println(tokens(0) + " " + cmd_1)
// scalastyle:on println
}
- Seq(proc.run(cmd_1).getResponseCode.toString)
+ val response: CommandProcessorResponse = proc.run(cmd_1)
+ // Throw an exception if there is an error in query processing.
+ if (response.getResponseCode != 0) {
+ throw new QueryExecutionException(response.getErrorMessage)
+ }
+ Seq(response.getResponseCode.toString)
}
} catch {
case e: Exception =>
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveExternalCatalogSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveExternalCatalogSuite.scala
index 79e569b..0a88898 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveExternalCatalogSuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveExternalCatalogSuite.scala
@@ -22,6 +22,7 @@ import org.apache.hadoop.conf.Configuration
import org.apache.spark.SparkConf
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.catalog._
+import org.apache.spark.sql.execution.QueryExecutionException
import org.apache.spark.sql.execution.command.DDLUtils
import org.apache.spark.sql.types.StructType
@@ -154,4 +155,27 @@ class HiveExternalCatalogSuite extends ExternalCatalogSuite {
catalog.createTable(hiveTable, ignoreIfExists = false)
assert(catalog.getTable("db1", "spark_29498").owner === owner)
}
+
+ test("SPARK-30868 throw an exception if HiveClient#runSqlHive fails") {
+ val client = externalCatalog.client
+ // test add jars which doesn't exists
+ val jarPath = "file:///tmp/not_exists.jar"
+ assertThrows[QueryExecutionException](client.runSqlHive(s"ADD JAR $jarPath"))
+
+ // test change to the database which doesn't exists
+ assertThrows[QueryExecutionException](client.runSqlHive(
+ s"use db_not_exists"))
+
+ // test create hive table failed with unsupported into type
+ assertThrows[QueryExecutionException](client.runSqlHive(
+ s"CREATE TABLE t(n into)"))
+
+ // test desc table failed with wrong `FORMATED` keyword
+ assertThrows[QueryExecutionException](client.runSqlHive(
+ s"DESC FORMATED t"))
+
+ // test wrong insert query
+ assertThrows[QueryExecutionException](client.runSqlHive(
+ "INSERT overwrite directory \"fs://localhost/tmp\" select 1 as a"))
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org