-
Notifications
You must be signed in to change notification settings - Fork 28k
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
[SPARK-32356][SQL] Forbid create view with null type #29152
Conversation
Test build #126106 has finished for PR 29152 at commit
|
Thank you, @ulysses-you . |
@@ -1557,6 +1557,17 @@ 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" |
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 test temp view as well? also the df api df.createTempView
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.
added.
val msg = intercept[AnalysisException] { | ||
parseAndResolve(sql) | ||
}.getMessage | ||
assert(msg.contains(s"Cannot create tables 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.
shall we update the error message to be tables/views
?
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.
updated
Test build #126175 has finished for PR 29152 at commit
|
@@ -2540,6 +2540,17 @@ class DataFrameSuite extends QueryTest | |||
assert(df.schema === new StructType().add(StructField("d", DecimalType(38, 0)))) | |||
} | |||
} | |||
|
|||
test("SPARK-32356: forbid null type in create view") { |
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 put test in one place SQLViewSuite
?
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 this
@@ -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." |
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.
changed old error msg tables
-> tables/views
.
Test build #126181 has finished for PR 29152 at commit
|
@@ -1557,6 +1557,19 @@ class PlanResolutionSuite extends AnalysisTest { | |||
checkFailure("testcat.tab", "foo") | |||
} | |||
|
|||
test("SPARK-32356: forbid null type in create view") { |
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 SQLViewSuite
as 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.
@@ -96,6 +97,7 @@ case class CreateViewCommand( | |||
qe.assertAnalyzed() | |||
val analyzedPlan = qe.analyzed | |||
|
|||
assertNoNullTypeInSchema(analyzedPlan.schema) |
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.
This check is for df.createTempView
. Note that, we support select null as c
but fail in create view with null type plan.
Test build #126208 has finished for PR 29152 at commit
|
Test build #126211 has finished for PR 29152 at commit
|
LGTM if tests pass. One last question: Hive also fails to create view if the column is null type? |
@cloud-fan Hive support this
That said, we will get |
how does this happen if Hive supports it? |
@cloud-fan |
And it works if we change To clarify, this case never works in Spark? |
Yes, never works. |
hm, at least, most databases can accpet it
MySQL: http://sqlfiddle.com/#!9/42febe/1/0 So, IMO accepting it looks somewhat meaningful to follow other databases, but we don't need to handle it as a null type. Either way, I think its better to update the migration guide if we change thsi behaivour. |
But create view v as select null with in-memory works before, right, according to the description? This changes the behavior. |
I'd treat it as not-working if it ONLY works with in-memory catalog. In production no one use it. The official release of Spark always include the hive dependencies. |
How about give user a config that In my practice, most time |
Oh ok, it makes sense. For a better error message, this PR is fine. |
Looks okay to me, but (this is trivial though) we might need to choose either action?;
cc: @dongjoon-hyun |
If it just improves error message, I think we don't need to backport. My question is if we want to support it. It seems it's easy to support it, and hive supports it as well. |
Forbitting it in in-memory catalog, too, looks ok to me. If we get a user's request about the behaivour, we can easily fix it. |
It seems During resolve failed test, I find many place use e.g.,
I'm not confident to remove all that test. |
Test build #126459 has finished for PR 29152 at commit
|
That's a good point. Then I think we should support NullType in permanent views as well. @ulysses-you can you open a PR to do it? |
@cloud-fan ok may be tomorrow. |
Test build #126471 has finished for PR 29152 at commit
|
@cloud-fan . Just for my understanding, do you mean to reverting
cc @LantaoJin |
I mean to override |
What changes were proposed in this pull request?
After #28833, we forbid create table with null type, but not include the view. This pr aims to forbid creat view with null type.
Why are the changes needed?
Currently, we support
create view v as select null
within-memory
but failed inhive
. It's better to have same behavior of them.inclued 4 command:
Does this PR introduce any user-facing change?
Yes, user will get exception when create view with null type .
How was this patch tested?
Add ut.