-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-52236][SQL] Standardize analyze exceptions for default value #50960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3552,6 +3552,42 @@ class DataSourceV2SQLSuiteV1Filter | |
} | ||
} | ||
|
||
test("CREATE TABLE with invalid default value") { | ||
withSQLConf(SQLConf.DEFAULT_COLUMN_ALLOWED_PROVIDERS.key -> s"$v2Format, ") { | ||
withTable("t") { | ||
// The default value fails to analyze. | ||
checkError( | ||
exception = intercept[AnalysisException] { | ||
sql(s"create table t(s int default badvalue) using $v2Format") | ||
}, | ||
condition = "INVALID_DEFAULT_VALUE.UNRESOLVED_EXPRESSION", | ||
parameters = Map( | ||
"statement" -> "CREATE TABLE", | ||
"colName" -> "`s`", | ||
"defaultValue" -> "badvalue")) | ||
} | ||
} | ||
} | ||
|
||
test("REPLACE TABLE with invalid default value") { | ||
withSQLConf(SQLConf.DEFAULT_COLUMN_ALLOWED_PROVIDERS.key -> s"$v2Format, ") { | ||
withTable("t") { | ||
sql(s"create table t(i boolean) using $v2Format") | ||
|
||
// The default value fails to analyze. | ||
checkError( | ||
exception = intercept[AnalysisException] { | ||
sql(s"replace table t(s int default badvalue) using $v2Format") | ||
}, | ||
condition = "INVALID_DEFAULT_VALUE.UNRESOLVED_EXPRESSION", | ||
parameters = Map( | ||
"statement" -> "REPLACE TABLE", | ||
"colName" -> "`s`", | ||
"defaultValue" -> "badvalue")) | ||
} | ||
} | ||
} | ||
|
||
test("SPARK-52116: Create table with default value which is not deterministic") { | ||
withSQLConf(SQLConf.DEFAULT_COLUMN_ALLOWED_PROVIDERS.key -> v2Source) { | ||
withTable("tab") { | ||
|
@@ -3576,7 +3612,7 @@ class DataSourceV2SQLSuiteV1Filter | |
s"REPLACE TABLE tab (col1 DOUBLE DEFAULT rand()) USING $v2Source") | ||
assert(exception.getSqlState == "42623") | ||
assert(exception.errorClass.get == "INVALID_DEFAULT_VALUE.NON_DETERMINISTIC") | ||
assert(exception.messageParameters("statement") == "CREATE TABLE") | ||
assert(exception.messageParameters("statement") == "REPLACE TABLE") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an error message bug fix, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea , my mistake before :) |
||
assert(exception.messageParameters("colName") == "`col1`") | ||
assert(exception.messageParameters("defaultValue") == "rand()") | ||
} | ||
|
@@ -3593,7 +3629,7 @@ class DataSourceV2SQLSuiteV1Filter | |
s"ALTER TABLE tab ADD COLUMN col2 DOUBLE DEFAULT rand()") | ||
assert(exception.getSqlState == "42623") | ||
assert(exception.errorClass.get == "INVALID_DEFAULT_VALUE.NON_DETERMINISTIC") | ||
assert(exception.messageParameters("statement") == "ALTER TABLE") | ||
assert(exception.messageParameters("statement") == "ALTER TABLE ADD COLUMNS") | ||
assert(exception.messageParameters("colName") == "`col2`") | ||
assert(exception.messageParameters("defaultValue") == "rand()") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1170,7 +1170,7 @@ class InsertSuite extends DataSourceTest with SharedSparkSession { | |
exception = intercept[AnalysisException] { | ||
sql("create table t(i boolean, s bigint default badvalue) using parquet") | ||
}, | ||
condition = "INVALID_DEFAULT_VALUE.NOT_CONSTANT", | ||
condition = "INVALID_DEFAULT_VALUE.UNRESOLVED_EXPRESSION", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A good improvement. |
||
parameters = Map( | ||
"statement" -> "CREATE TABLE", | ||
"colName" -> "`s`", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too minor, you can address it in your next PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, thanks!