aboutsummaryrefslogtreecommitdiff
path: root/sql/hive
diff options
context:
space:
mode:
authorgatorsmile <gatorsmile@gmail.com>2016-08-26 11:13:38 -0700
committerYin Huai <yhuai@databricks.com>2016-08-26 11:13:38 -0700
commitfd4ba3f626f49d7d616a2a334d45b1c736e1db1c (patch)
treeb1157e6cb57bfe55d1db6776b6f07c2e441fb5e4 /sql/hive
parent18832162357282ec81515b5b2ba93747be3ad18b (diff)
downloadspark-fd4ba3f626f49d7d616a2a334d45b1c736e1db1c.tar.gz
spark-fd4ba3f626f49d7d616a2a334d45b1c736e1db1c.tar.bz2
spark-fd4ba3f626f49d7d616a2a334d45b1c736e1db1c.zip
[SPARK-17192][SQL] Issue Exception when Users Specify the Partitioning Columns without a Given Schema
### What changes were proposed in this pull request? Address the comments by yhuai in the original PR: https://github.com/apache/spark/pull/14207 First, issue an exception instead of logging a warning when users specify the partitioning columns without a given schema. Second, refactor the codes a little. ### How was this patch tested? Fixed the test cases. Author: gatorsmile <gatorsmile@gmail.com> Closes #14572 from gatorsmile/followup16552.
Diffstat (limited to 'sql/hive')
-rw-r--r--sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala16
1 files changed, 9 insertions, 7 deletions
diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala
index 2586d11a6c..7f50e38d30 100644
--- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala
+++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala
@@ -622,24 +622,26 @@ object HiveExternalCatalog {
def getSchemaFromTableProperties(metadata: CatalogTable): StructType = {
val errorMessage = "Could not read schema from the hive metastore because it is corrupted."
val props = metadata.properties
- props.get(DATASOURCE_SCHEMA).map { schema =>
+ val schema = props.get(DATASOURCE_SCHEMA)
+ if (schema.isDefined) {
// Originally, we used `spark.sql.sources.schema` to store the schema of a data source table.
// After SPARK-6024, we removed this flag.
// Although we are not using `spark.sql.sources.schema` any more, we need to still support.
- DataType.fromJson(schema).asInstanceOf[StructType]
- } getOrElse {
- props.get(DATASOURCE_SCHEMA_NUMPARTS).map { numParts =>
- val parts = (0 until numParts.toInt).map { index =>
+ DataType.fromJson(schema.get).asInstanceOf[StructType]
+ } else {
+ val numSchemaParts = props.get(DATASOURCE_SCHEMA_NUMPARTS)
+ if (numSchemaParts.isDefined) {
+ val parts = (0 until numSchemaParts.get.toInt).map { index =>
val part = metadata.properties.get(s"$DATASOURCE_SCHEMA_PART_PREFIX$index").orNull
if (part == null) {
throw new AnalysisException(errorMessage +
- s" (missing part $index of the schema, $numParts parts are expected).")
+ s" (missing part $index of the schema, ${numSchemaParts.get} parts are expected).")
}
part
}
// Stick all parts back to a single schema string.
DataType.fromJson(parts.mkString).asInstanceOf[StructType]
- } getOrElse {
+ } else {
throw new AnalysisException(errorMessage)
}
}