-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-32356][SQL] Forbid create view with null type #29152
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 6 commits
d5a5575
95dd3d2
3780ccd
2e8d9f3
9d77cb5
e1d92ae
32ec11a
94fb546
4d8d088
3cb224f
d02986c
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 |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ import org.apache.spark.sql.execution.datasources.CreateTable | |
| import org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.sources.SimpleScanSource | ||
| import org.apache.spark.sql.types.{CharType, DoubleType, HIVE_TYPE_STRING, IntegerType, LongType, MetadataBuilder, StringType, StructField, StructType} | ||
| import org.apache.spark.sql.types.{CharType, DoubleType, HIVE_TYPE_STRING, IntegerType, LongType, MetadataBuilder, NullType, StringType, StructField, StructType} | ||
|
|
||
| class PlanResolutionSuite extends AnalysisTest { | ||
| import CatalystSqlParser._ | ||
|
|
@@ -1557,6 +1557,19 @@ class PlanResolutionSuite extends AnalysisTest { | |
| checkFailure("testcat.tab", "foo") | ||
| } | ||
|
|
||
| test("SPARK-32356: forbid null type in create view") { | ||
| val sql1 = "create view v as select null as c" | ||
| val sql2 = "alter view v as select null as c" | ||
|
Contributor
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. can we test temp view as well? also the df api
Contributor
Author
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. added. |
||
| val sql3 = "create temporary view v as select null as c" | ||
| val sql4 = "create global temporary view v as select null as c" | ||
| Seq(sql1, sql2, sql3, sql4).foreach { sql => | ||
| val msg = intercept[AnalysisException] { | ||
| parseAndResolve(sql) | ||
| }.getMessage | ||
| assert(msg.contains(s"Cannot create tables/views with ${NullType.simpleString} type.")) | ||
| } | ||
| } | ||
|
|
||
| // TODO: add tests for more commands. | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2314,6 +2314,7 @@ class HiveDDLSuite | |
| } | ||
|
|
||
| test("SPARK-20680: do not support for null column datatype") { | ||
| val errMsg = s"Cannot create tables/views with ${NullType.simpleString} type." | ||
|
Contributor
Author
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. changed old error msg |
||
| withTable("t") { | ||
| withView("tabNullType") { | ||
| hiveClient.runSqlHive("CREATE TABLE t (t1 int)") | ||
|
|
@@ -2331,17 +2332,17 @@ class HiveDDLSuite | |
| val e1 = intercept[AnalysisException] { | ||
| spark.sql("CREATE TABLE t1 USING PARQUET AS SELECT null as null_col") | ||
| }.getMessage | ||
| assert(e1.contains("Cannot create tables with null type")) | ||
| assert(e1.contains(errMsg)) | ||
|
|
||
| val e2 = intercept[AnalysisException] { | ||
| spark.sql("CREATE TABLE t2 AS SELECT null as null_col") | ||
| }.getMessage | ||
| assert(e2.contains("Cannot create tables with null type")) | ||
| assert(e2.contains(errMsg)) | ||
|
|
||
| val e3 = intercept[AnalysisException] { | ||
| spark.sql("CREATE TABLE t3 STORED AS PARQUET AS SELECT null as null_col") | ||
| }.getMessage | ||
| assert(e3.contains("Cannot create tables with null type")) | ||
| assert(e3.contains(errMsg)) | ||
| } | ||
|
|
||
| // Forbid Replace table AS SELECT with null type | ||
|
|
@@ -2350,27 +2351,27 @@ class HiveDDLSuite | |
| val e = intercept[AnalysisException] { | ||
| spark.sql(s"CREATE OR REPLACE TABLE t USING $v2Source AS SELECT null as null_col") | ||
| }.getMessage | ||
| assert(e.contains("Cannot create tables with null type")) | ||
| assert(e.contains(errMsg)) | ||
| } | ||
|
|
||
| // Forbid creating table with VOID type in Spark | ||
| withTable("t1", "t2", "t3", "t4") { | ||
| val e1 = intercept[AnalysisException] { | ||
| spark.sql(s"CREATE TABLE t1 (v VOID) USING PARQUET") | ||
| }.getMessage | ||
| assert(e1.contains("Cannot create tables with null type")) | ||
| assert(e1.contains(errMsg)) | ||
| val e2 = intercept[AnalysisException] { | ||
| spark.sql(s"CREATE TABLE t2 (v VOID) USING hive") | ||
| }.getMessage | ||
| assert(e2.contains("Cannot create tables with null type")) | ||
| assert(e2.contains(errMsg)) | ||
| val e3 = intercept[AnalysisException] { | ||
| spark.sql(s"CREATE TABLE t3 (v VOID)") | ||
| }.getMessage | ||
| assert(e3.contains("Cannot create tables with null type")) | ||
| assert(e3.contains(errMsg)) | ||
| val e4 = intercept[AnalysisException] { | ||
| spark.sql(s"CREATE TABLE t4 (v VOID) STORED AS PARQUET") | ||
| }.getMessage | ||
| assert(e4.contains("Cannot create tables with null type")) | ||
| assert(e4.contains(errMsg)) | ||
| } | ||
|
|
||
| // Forbid Replace table with VOID type | ||
|
|
@@ -2379,7 +2380,7 @@ class HiveDDLSuite | |
| val e = intercept[AnalysisException] { | ||
| spark.sql(s"CREATE OR REPLACE TABLE t (v VOID) USING $v2Source") | ||
| }.getMessage | ||
| assert(e.contains("Cannot create tables with null type")) | ||
| assert(e.contains(errMsg)) | ||
| } | ||
|
|
||
| // Make sure spark.catalog.createTable with null type will fail | ||
|
|
@@ -2416,7 +2417,7 @@ class HiveDDLSuite | |
| schema = schema, | ||
| options = Map("fileFormat" -> "parquet")) | ||
| }.getMessage | ||
| assert(e.contains("Cannot create tables with null type")) | ||
| assert(e.contains(s"Cannot create tables/views with ${NullType.simpleString} type.")) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -2429,7 +2430,7 @@ class HiveDDLSuite | |
| schema = schema, | ||
| options = Map.empty[String, String]) | ||
| }.getMessage | ||
| assert(e.contains("Cannot create tables with null type")) | ||
| assert(e.contains(s"Cannot create tables/views with ${NullType.simpleString} type.")) | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
can we move this to
SQLViewSuiteas well?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.
Moved.