aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/test
diff options
context:
space:
mode:
authorgatorsmile <gatorsmile@gmail.com>2016-08-10 17:05:50 +0800
committerWenchen Fan <wenchen@databricks.com>2016-08-10 17:05:50 +0800
commit2b10ebe6ac1cdc2c723cb47e4b88cfbf39e0de08 (patch)
tree0e285bc9ea7c67c0760fdab0da5e915fdcf42f25 /sql/core/src/test
parent41a7dbdd34d2641d42eb00828f16285089356aa9 (diff)
downloadspark-2b10ebe6ac1cdc2c723cb47e4b88cfbf39e0de08.tar.gz
spark-2b10ebe6ac1cdc2c723cb47e4b88cfbf39e0de08.tar.bz2
spark-2b10ebe6ac1cdc2c723cb47e4b88cfbf39e0de08.zip
[SPARK-16185][SQL] Better Error Messages When Creating Table As Select Without Enabling Hive Support
#### What changes were proposed in this pull request? When we do not turn on the Hive Support, the following query generates a confusing error message by Planner: ```Scala sql("CREATE TABLE t2 SELECT a, b from t1") ``` ``` assertion failed: No plan for CreateTable CatalogTable( Table: `t2` Created: Tue Aug 09 23:45:32 PDT 2016 Last Access: Wed Dec 31 15:59:59 PST 1969 Type: MANAGED Provider: hive Storage(InputFormat: org.apache.hadoop.mapred.TextInputFormat, OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat)), ErrorIfExists +- Relation[a#19L,b#20L] parquet java.lang.AssertionError: assertion failed: No plan for CreateTable CatalogTable( Table: `t2` Created: Tue Aug 09 23:45:32 PDT 2016 Last Access: Wed Dec 31 15:59:59 PST 1969 Type: MANAGED Provider: hive Storage(InputFormat: org.apache.hadoop.mapred.TextInputFormat, OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat)), ErrorIfExists +- Relation[a#19L,b#20L] parquet ``` This PR is to issue a better error message: ``` Hive support is required to use CREATE Hive TABLE AS SELECT ``` #### How was this patch tested? Added test cases in `DDLSuite.scala` Author: gatorsmile <gatorsmile@gmail.com> Closes #13886 from gatorsmile/createCatalogedTableAsSelect.
Diffstat (limited to 'sql/core/src/test')
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala28
1 files changed, 28 insertions, 0 deletions
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
index 53376c56f1..0eb3f2002d 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
@@ -1578,6 +1578,34 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
"WITH SERDEPROPERTIES ('spark.sql.sources.me'='anything')")
}
+ test("Create Hive Table As Select") {
+ import testImplicits._
+ withTable("t", "t1") {
+ var e = intercept[AnalysisException] {
+ sql("CREATE TABLE t SELECT 1 as a, 1 as b")
+ }.getMessage
+ assert(e.contains("Hive support is required to use CREATE Hive TABLE AS SELECT"))
+
+ spark.range(1).select('id as 'a, 'id as 'b).write.saveAsTable("t1")
+ e = intercept[AnalysisException] {
+ sql("CREATE TABLE t SELECT a, b from t1")
+ }.getMessage
+ assert(e.contains("Hive support is required to use CREATE Hive TABLE AS SELECT"))
+ }
+ }
+
+ test("Create Data Source Table As Select") {
+ import testImplicits._
+ withTable("t", "t1", "t2") {
+ sql("CREATE TABLE t USING parquet SELECT 1 as a, 1 as b")
+ checkAnswer(spark.table("t"), Row(1, 1) :: Nil)
+
+ spark.range(1).select('id as 'a, 'id as 'b).write.saveAsTable("t1")
+ sql("CREATE TABLE t2 USING parquet SELECT a, b from t1")
+ checkAnswer(spark.table("t2"), spark.table("t1"))
+ }
+ }
+
test("drop current database") {
sql("CREATE DATABASE temp")
sql("USE temp")