Skip to content

Commit ad2b07d

Browse files
committed
Update tests and error messages.
1 parent 8af5b2a commit ad2b07d

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveContext.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
7474
* and no SerDe is specified (no ROW FORMAT SERDE clause).
7575
*/
7676
protected[sql] def convertCTAS: Boolean =
77-
getConf("spark.sql.hive.convertCTAS", "false") == "true"
77+
getConf("spark.sql.hive.convertCTAS", "false").toBoolean
7878

7979
override protected[sql] def executePlan(plan: LogicalPlan): this.QueryExecution =
8080
new this.QueryExecution(plan)

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ private[hive] class HiveMetastoreCatalog(hive: HiveContext) extends Catalog with
507507
}
508508

509509
if (hive.convertCTAS && !hasStorageSpec) {
510-
// Do the conversion when convertHiveCTASWithoutStorageSpec is true and the query
510+
// Do the conversion when spark.sql.hive.convertCTAS is true and the query
511511
// does not specify any storage format (file format and storage handler).
512512
if (dbName.isDefined) {
513513
throw new AnalysisException(

sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/commands.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.spark.sql.hive.execution
1919

2020
import org.apache.spark.annotation.DeveloperApi
21+
import org.apache.spark.sql.AnalysisException
2122
import org.apache.spark.sql.catalyst.analysis.EliminateSubQueries
2223
import org.apache.spark.sql.catalyst.util._
2324
import org.apache.spark.sql.sources._
@@ -117,7 +118,7 @@ case class CreateMetastoreDataSource(
117118
if (allowExisting) {
118119
return Seq.empty[Row]
119120
} else {
120-
sys.error(s"Table $tableName already exists.")
121+
throw new AnalysisException(s"Table $tableName already exists.")
121122
}
122123
}
123124

@@ -164,8 +165,8 @@ case class CreateMetastoreDataSourceAsSelect(
164165
// Check if we need to throw an exception or just return.
165166
mode match {
166167
case SaveMode.ErrorIfExists =>
167-
sys.error(s"Table $tableName already exists. " +
168-
s"If you are using saveAsTable, you can set SaveMode to SaveMode.Append to" +
168+
throw new AnalysisException(s"Table $tableName already exists. " +
169+
s"If you are using saveAsTable, you can set SaveMode to SaveMode.Append to " +
169170
s"insert data into the table or set SaveMode to SaveMode.Overwrite to overwrite" +
170171
s"the existing data. " +
171172
s"Or, if you are using SQL CREATE TABLE, you need to drop $tableName first.")
@@ -193,7 +194,7 @@ case class CreateMetastoreDataSourceAsSelect(
193194
s"== Actual Schema ==" +:
194195
createdRelation.schema.treeString.split("\\\n")).mkString("\n")}
195196
""".stripMargin
196-
sys.error(errorMessage)
197+
throw new AnalysisException(errorMessage)
197198
} else if (i != createdRelation.relation) {
198199
val errorDescription =
199200
s"Cannot append to table $tableName because the resolved relation does not " +
@@ -210,10 +211,10 @@ case class CreateMetastoreDataSourceAsSelect(
210211
s"== Actual Relation ==" ::
211212
createdRelation.toString :: Nil).mkString("\n")}
212213
""".stripMargin
213-
sys.error(errorMessage)
214+
throw new AnalysisException(errorMessage)
214215
}
215216
case o =>
216-
sys.error(s"Saving data in ${o.toString} is not supported.")
217+
throw new AnalysisException(s"Saving data in ${o.toString} is not supported.")
217218
}
218219
case SaveMode.Overwrite =>
219220
hiveContext.sql(s"DROP TABLE IF EXISTS $tableName")

sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ class MetastoreDataSourcesSuite extends QueryTest with BeforeAndAfterEach {
303303
|SELECT * FROM jsonTable
304304
""".stripMargin)
305305

306-
// Create the table again should trigger a AlreadyExistsException.
307-
val message = intercept[RuntimeException] {
306+
// Create the table again should trigger a AnalysisException.
307+
val message = intercept[AnalysisException] {
308308
sql(
309309
s"""
310310
|CREATE TABLE ctasJsonTable
@@ -513,7 +513,7 @@ class MetastoreDataSourcesSuite extends QueryTest with BeforeAndAfterEach {
513513
sql("SELECT * FROM createdJsonTable"),
514514
df.collect())
515515

516-
var message = intercept[RuntimeException] {
516+
var message = intercept[AnalysisException] {
517517
createExternalTable("createdJsonTable", filePath.toString)
518518
}.getMessage
519519
assert(message.contains("Table createdJsonTable already exists."),

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class SQLQuerySuite extends QueryTest {
7171

7272
sql("CREATE TABLE ctas1 AS SELECT key k, value FROM src ORDER BY k, value")
7373
sql("CREATE TABLE IF NOT EXISTS ctas1 AS SELECT key k, value FROM src ORDER BY k, value")
74-
var message = intercept[RuntimeException] {
74+
var message = intercept[AnalysisException] {
7575
sql("CREATE TABLE ctas1 AS SELECT key k, value FROM src ORDER BY k, value")
7676
}.getMessage
7777
assert(message.contains("Table ctas1 already exists"))
@@ -105,10 +105,9 @@ class SQLQuerySuite extends QueryTest {
105105
checkRelation("ctas1", false)
106106
sql("DROP TABLE ctas1")
107107

108-
// Enable the following one after SPARK-5852 is fixed
109-
// sql("CREATE TABLE ctas1 stored as parquet AS SELECT key k, value FROM src ORDER BY k, value")
110-
// checkRelation("ctas1", false)
111-
// sql("DROP TABLE ctas1")
108+
sql("CREATE TABLE ctas1 stored as parquet AS SELECT key k, value FROM src ORDER BY k, value")
109+
checkRelation("ctas1", false)
110+
sql("DROP TABLE ctas1")
112111

113112
setConf("spark.sql.hive.convertCTAS", originalConf)
114113
}

0 commit comments

Comments
 (0)