-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-29628][SQL] Forcibly create a temporary view in CREATE VIEW if referencing a temporary view #26317
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
Conversation
|
Can one of the admins verify this patch? |
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
Outdated
Show resolved
Hide resolved
| throw new AnalysisException( | ||
| s"It is not allowed to add database prefix `$database` for the TEMPORARY view name.") | ||
| // Temporary view names should NOT contain database prefix like "database.table" | ||
| if (name.database.isDefined) { |
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.
nit:
name.database.foreach { database =>
throw new AnalysisException(
s"It is not allowed to add database prefix `$database` for the TEMPORARY view name.")
}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.
name.database returns String.
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.
It's not, it's an Option[String], I imagine, in which case this is indeed a little more idiomatic.
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.
My bad. name.database is an Option[String].
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.
Now, I see how foreach is working here.
Thanks @MaxGekk
|
cc @maropu |
|
Hi, @amanomer . Thank you for making a PR. FYI, for SQL PR, you need to add |
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
Outdated
Show resolved
Hide resolved
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
Outdated
Show resolved
Hide resolved
sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala
Outdated
Show resolved
Hide resolved
|
cc @gatorsmile since this is a behavior change. |
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
Outdated
Show resolved
Hide resolved
dongjoon-hyun
left a comment
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.
@amanomer . I finished my first round review. After your updating, I'll review again.
|
btw, is this behaviour is common in the other DMBS-like? If no, better to add this feature in the PgSQL dialect. |
|
This is a weird feature. Does pgsql give warning when this happens? |
|
Yea, pgSQL does so: |
|
If it's a feature that pgsql would warn you, I'm not sure we need to have it in Spark. This at lease should be protected by the pgsql dialect. |
|
I generally agree, unless it's important to match semantics, I don't think we should just let this work? |
|
I'm not sure though, if this feature is not common in the other DMBS implementations (e.g., Oracle?), I personally think it might be worth doing in the pgSQL dialect. |
|
I will move this code to pgSQL dialect. |
| throw new AnalysisException(s"Not allowed to create a permanent view $name by " + | ||
| s"referencing a temporary view $ident") | ||
| // Temporary views are only stored in the session catalog | ||
| if (sparkSession.sqlContext.conf.usePostgreSQLDialect) { |
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.
I have handled pgSQLDialect case here. Since class CreateViewCommand of sql/core is not accessible from PostgreSQLDialect sql/catalyst because sql/core is dependent on sql/catalyst.
|
I have handled the review comments.Kindly check this. |
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
Outdated
Show resolved
Hide resolved
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
Outdated
Show resolved
Hide resolved
| } | ||
| } | ||
|
|
||
| private var isTempReferred = false |
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.
I'm not sure about the semantics of this. It's used in a different place from where it's checked. Is this always set to true by a code path before it needs to be used?
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.
isTempReferred A flag which will be true when permanent view is based on temporary view while using pgSQL dialect.
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.
Yes that's not quite my question. How do we know the code path that sets this to true below will execute first?
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.
In run(), before using isTempReferred, a call to verifyTemporaryObjectsNotExists() is made which will update it's value.
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
Show resolved
Hide resolved
|
cc @brkyvz |
|
cc @cloud-fan |
|
@maropu @gengliangwang kindly review this |
| throw new AnalysisException(s"Not allowed to create a permanent view $name by " + | ||
| s"referencing a temporary view $ident") | ||
| // Temporary views are only stored in the session catalog | ||
| if (sparkSession.sqlContext.conf.usePostgreSQLDialect) { |
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.
We are removing this dialect as we discussed in the mailing list.
| if sparkSession.sessionState.catalog.isTemporaryTable(ident) => | ||
| // temporary views are only stored in the session catalog | ||
| throw new AnalysisException(s"Not allowed to create a permanent view $name by " + | ||
| s"referencing a temporary view $ident") |
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.
We can improve the error message and suggest end users to add the keyword TEMPORARY to create a temporary view instead.
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.
PR for above suggestion #26731
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.
@gatorsmile also review #26712
### What changes were proposed in this pull request? Improved error message while creating views. ### Why are the changes needed? Error message should suggest user to use TEMPORARY keyword while creating permanent view referred by temporary view. #26317 (comment) ### Does this PR introduce any user-facing change? No ### How was this patch tested? Updated test case. Closes #26731 from amanomer/imp_err_msg. Authored-by: Aman Omer <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
### What changes were proposed in this pull request? Improved error message while creating views. ### Why are the changes needed? Error message should suggest user to use TEMPORARY keyword while creating permanent view referred by temporary view. apache#26317 (comment) ### Does this PR introduce any user-facing change? No ### How was this patch tested? Updated test case. Closes apache#26731 from amanomer/imp_err_msg. Authored-by: Aman Omer <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
|
I think, this PR is not required. |
What changes were proposed in this pull request?
When creating permanent view based on temporary view, it will be created as a temporary view. Previously, Spark this was not allowed.
Why are the changes needed?
To match the behavior of postgreSQL.
Does this PR introduce any user-facing change?
No
How was this patch tested?
UT added.