diff options
author | Michael Armbrust <michael@databricks.com> | 2015-03-24 14:10:56 -0700 |
---|---|---|
committer | Michael Armbrust <michael@databricks.com> | 2015-03-24 14:10:56 -0700 |
commit | a8f51b82968147abebbe61b8b68b066d21a0c6e6 (patch) | |
tree | d90df468f3b8e32f5e97e4d18c6f6de8cac15e23 | |
parent | cbeaf9ebab31a0bcbca884d4db7a791fd9edbff3 (diff) | |
download | spark-a8f51b82968147abebbe61b8b68b066d21a0c6e6.tar.gz spark-a8f51b82968147abebbe61b8b68b066d21a0c6e6.tar.bz2 spark-a8f51b82968147abebbe61b8b68b066d21a0c6e6.zip |
[SPARK-6458][SQL] Better error messages for invalid data sources
Avoid unclear match errors and use `AnalysisException`.
Author: Michael Armbrust <michael@databricks.com>
Closes #5158 from marmbrus/dataSourceError and squashes the following commits:
af9f82a [Michael Armbrust] Yins comment
90c6ba4 [Michael Armbrust] Better error messages for invalid data sources
-rw-r--r-- | sql/core/src/main/scala/org/apache/spark/sql/sources/ddl.scala | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/sources/ddl.scala b/sql/core/src/main/scala/org/apache/spark/sql/sources/ddl.scala index d2e807d3a6..eb46b46ca5 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/sources/ddl.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/sources/ddl.scala @@ -21,7 +21,7 @@ import scala.language.existentials import scala.language.implicitConversions import org.apache.spark.Logging -import org.apache.spark.sql.{SaveMode, DataFrame, SQLContext} +import org.apache.spark.sql.{AnalysisException, SaveMode, DataFrame, SQLContext} import org.apache.spark.sql.catalyst.plans.logical._ import org.apache.spark.sql.catalyst.AbstractSparkSQLParser import org.apache.spark.sql.catalyst.analysis.UnresolvedRelation @@ -204,19 +204,25 @@ private[sql] object ResolvedDataSource { provider: String, options: Map[String, String]): ResolvedDataSource = { val clazz: Class[_] = lookupDataSource(provider) + def className = clazz.getCanonicalName val relation = userSpecifiedSchema match { case Some(schema: StructType) => clazz.newInstance() match { case dataSource: SchemaRelationProvider => dataSource.createRelation(sqlContext, new CaseInsensitiveMap(options), schema) case dataSource: org.apache.spark.sql.sources.RelationProvider => - sys.error(s"${clazz.getCanonicalName} does not allow user-specified schemas.") + throw new AnalysisException(s"$className does not allow user-specified schemas.") + case _ => + throw new AnalysisException(s"$className is not a RelationProvider.") } case None => clazz.newInstance() match { case dataSource: RelationProvider => dataSource.createRelation(sqlContext, new CaseInsensitiveMap(options)) case dataSource: org.apache.spark.sql.sources.SchemaRelationProvider => - sys.error(s"A schema needs to be specified when using ${clazz.getCanonicalName}.") + throw new AnalysisException( + s"A schema needs to be specified when using $className.") + case _ => + throw new AnalysisException(s"$className is not a RelationProvider.") } } new ResolvedDataSource(clazz, relation) |