Skip to content

Commit fc132e6

Browse files
committed
Simplify the logic and throw meaningful exception message.
1 parent 2ed1069 commit fc132e6

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,10 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
283283
} else {
284284
val partitionSpec = if (ctx.partitionSpec != null) {
285285
// According to the syntax, visitPartitionSpec returns `Map[String, Option[String]]`.
286-
val (valid, nonValid) = visitPartitionSpec(ctx.partitionSpec).partition(_._2.isDefined)
287-
if (nonValid.nonEmpty) {
288-
// For non-valid specification for `DESC` command, this raises a ParseException.
289-
return null
290-
} else {
291-
valid.map(x => (x._1, x._2.get))
286+
visitPartitionSpec(ctx.partitionSpec).map {
287+
case (key, Some(value)) => key -> value
288+
case (key, _) =>
289+
throw new ParseException(s"PARTITION specification is incomplete: `$key`", ctx)
292290
}
293291
} else {
294292
Map.empty[String, String]

sql/core/src/test/resources/sql-tests/inputs/describe.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ DESC t PARTITION (c='Us', d=2);
2020
-- AnalysisException: Partition spec is invalid
2121
DESC t PARTITION (c='Us');
2222

23-
-- ParseException: Unsupported SQL statement
23+
-- ParseException: PARTITION specification is incomplete
2424
DESC t PARTITION (c='Us', d);

sql/core/src/test/resources/sql-tests/results/describe.sql.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ struct<>
7575
-- !query 6 output
7676
org.apache.spark.sql.catalyst.parser.ParseException
7777

78-
Unsupported SQL statement
78+
PARTITION specification is incomplete: `d`(line 1, pos 0)
79+
7980
== SQL ==
8081
DESC t PARTITION (c='Us', d)
82+
^^^

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
389389
val m3 = intercept[ParseException] {
390390
sql("DESC partitioned_table PARTITION (c='Us', d)")
391391
}.getMessage()
392-
assert(m3.contains("Unsupported SQL statement"))
392+
assert(m3.contains("PARTITION specification is incomplete: `d`"))
393393

394394
spark
395395
.range(1).select('id as 'a, 'id as 'b, 'id as 'c, 'id as 'd).write

0 commit comments

Comments
 (0)