aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/test/scala
diff options
context:
space:
mode:
authorWenchen Fan <wenchen@databricks.com>2016-09-06 14:17:47 +0800
committerWenchen Fan <wenchen@databricks.com>2016-09-06 14:17:47 +0800
commitc0ae6bc6ea38909730fad36e653d3c7ab0a84b44 (patch)
tree25c1e98400ccadb9db221cf02cda423fd0bd7eb4 /sql/core/src/test/scala
parent64e826f91eabb1a22d3d163d71fbb7b6d2185f25 (diff)
downloadspark-c0ae6bc6ea38909730fad36e653d3c7ab0a84b44.tar.gz
spark-c0ae6bc6ea38909730fad36e653d3c7ab0a84b44.tar.bz2
spark-c0ae6bc6ea38909730fad36e653d3c7ab0a84b44.zip
[SPARK-17361][SQL] file-based external table without path should not be created
## What changes were proposed in this pull request? Using the public `Catalog` API, users can create a file-based data source table, without giving the path options. For this case, currently we can create the table successfully, but fail when we read it. Ideally we should fail during creation. This is because when we create data source table, we resolve the data source relation without validating path: `resolveRelation(checkPathExist = false)`. Looking back to why we add this trick(`checkPathExist`), it's because when we call `resolveRelation` for managed table, we add the path to data source options but the path is not created yet. So why we add this not-yet-created path to data source options? This PR fix the problem by adding path to options after we call `resolveRelation`. Then we can remove the `checkPathExist` parameter in `DataSource.resolveRelation` and do some related cleanups. ## How was this patch tested? existing tests and new test in `CatalogSuite` Author: Wenchen Fan <wenchen@databricks.com> Closes #14921 from cloud-fan/check-path.
Diffstat (limited to 'sql/core/src/test/scala')
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala17
1 files changed, 17 insertions, 0 deletions
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala
index 8aa81854b2..b221eed7b2 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala
@@ -27,6 +27,7 @@ import org.apache.spark.sql.catalyst.catalog._
import org.apache.spark.sql.catalyst.expressions.{Expression, ExpressionInfo}
import org.apache.spark.sql.catalyst.plans.logical.Range
import org.apache.spark.sql.test.SharedSQLContext
+import org.apache.spark.sql.types.{IntegerType, StructType}
/**
@@ -305,6 +306,22 @@ class CatalogSuite
columnFields.foreach { f => assert(columnString.contains(f.toString)) }
}
+ test("createExternalTable should fail if path is not given for file-based data source") {
+ val e = intercept[AnalysisException] {
+ spark.catalog.createExternalTable("tbl", "json", Map.empty[String, String])
+ }
+ assert(e.message.contains("Unable to infer schema"))
+
+ val e2 = intercept[AnalysisException] {
+ spark.catalog.createExternalTable(
+ "tbl",
+ "json",
+ new StructType().add("i", IntegerType),
+ Map.empty[String, String])
+ }
+ assert(e2.message == "Cannot create a file-based external data source table without path")
+ }
+
// TODO: add tests for the rest of them
}