You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by we...@apache.org on 2024/01/09 01:07:46 UTC
(spark) branch master updated: [SPARK-46610][SQL] Create table should throw exception when no value for a key in options
This is an automated email from the ASF dual-hosted git repository.
wenchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new e7536f2484af [SPARK-46610][SQL] Create table should throw exception when no value for a key in options
e7536f2484af is described below
commit e7536f2484afce412256bf711452acde8df5a287
Author: Rui Wang <ru...@databricks.com>
AuthorDate: Tue Jan 9 09:07:34 2024 +0800
[SPARK-46610][SQL] Create table should throw exception when no value for a key in options
### What changes were proposed in this pull request?
Before SPARK-43529, there was a check from `visitPropertyKeyValues` that throws for null values for option keys. After SPARK-43529, a new function is used to support expressions in options but the new function lose the check.
This PR adds the check back.
### Why are the changes needed?
Throw exception when a option value is null.
### Does this PR introduce _any_ user-facing change?
NO
### How was this patch tested?
UT
### Was this patch authored or co-authored using generative AI tooling?
NO
Closes #44615 from amaliujia/fix_create_table_options.
Lead-authored-by: Rui Wang <ru...@databricks.com>
Co-authored-by: Wenchen Fan <cl...@gmail.com>
Signed-off-by: Wenchen Fan <we...@databricks.com>
---
.../org/apache/spark/sql/catalyst/parser/AstBuilder.scala | 4 +++-
.../apache/spark/sql/catalyst/parser/DDLParserSuite.scala | 12 ++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
index 7609e96eba6f..54c4343e7ff9 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
@@ -3379,7 +3379,9 @@ class AstBuilder extends DataTypeAstBuilder with SQLConfHelper with Logging {
ctx: ExpressionPropertyListContext): OptionList = {
val options = ctx.expressionProperty.asScala.map { property =>
val key: String = visitPropertyKey(property.key)
- val value: Expression = Option(property.value).map(expression).orNull
+ val value: Expression = Option(property.value).map(expression).getOrElse {
+ operationNotAllowed(s"A value must be specified for the key: $key.", ctx)
+ }
key -> value
}.toSeq
OptionList(options)
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala
index ee85d509b6fc..03b31f1f03e4 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala
@@ -2421,6 +2421,18 @@ class DDLParserSuite extends AnalysisTest {
stop = 42))
}
+ test("SPARK-46610: throw exception when no value for a key in create table options") {
+ val createTableSql = "create table test_table using my_data_source options (password)"
+ checkError(
+ exception = parseException(createTableSql),
+ errorClass = "_LEGACY_ERROR_TEMP_0035",
+ parameters = Map("message" -> "A value must be specified for the key: password."),
+ context = ExpectedContext(
+ fragment = createTableSql,
+ start = 0,
+ stop = 62))
+ }
+
test("UNCACHE TABLE") {
comparePlans(
parsePlan("UNCACHE TABLE a.b.c"),
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org